$serviceBuilder
$serviceBuilder :
Base testcase class for all Guzzle testcases.
$body : \Guzzle\Http\ReadLimitEntityBody
$decorated : \Guzzle\Http\EntityBody
getServer() : \Guzzle\Tests\Http\Server
Get the global server object used throughout the unit tests of Guzzle
setServiceBuilder(\Guzzle\Service\Builder\ServiceBuilderInterface $builder)
Set the service builder to use for tests
\Guzzle\Service\Builder\ServiceBuilderInterface | $builder | Service builder |
getServiceBuilder() : \Guzzle\Service\Builder\ServiceBuilder
Get a service builder object that can be used throughout the service tests
getWildcardObserver(\Guzzle\Common\HasDispatcherInterface $hasDispatcher) : \Guzzle\Tests\Mock\MockObserver
Get a wildcard observer for an event dispatcher
\Guzzle\Common\HasDispatcherInterface | $hasDispatcher |
setMockBasePath(string $path) : \Guzzle\Tests\GuzzleTestCase
Set the mock response base path
string | $path | Path to mock response folder |
addMockedRequest(\Guzzle\Http\Message\RequestInterface $request) : self
Mark a request as being mocked
\Guzzle\Http\Message\RequestInterface | $request |
getMockResponse(string $path) : \Guzzle\Http\Message\Response
Get a mock response for a client by mock file name
string | $path | Relative path to the mock response file |
setMockResponse(\Guzzle\Http\Client $client, string $paths) : \Guzzle\Plugin\Mock\MockPlugin
Set a mock response from a mock file on the next client request.
This method assumes that mock response files are located under the Command/Mock/ directory of the Service being tested (e.g. Unfuddle/Command/Mock/). A mock response is added to the next request sent by the client.
\Guzzle\Http\Client | $client | Client object to modify |
string | $paths | Path to files within the Mock folder of the service |
returns the created mock plugin
compareHeaders(array $filteredHeaders, array $actualHeaders) : array|boolean
Compare HTTP headers and use special markup to filter values A header prefixed with '!' means it must not exist A header prefixed with '_' means it must be ignored A header value of '*' means anything after the * will be ignored
array | $filteredHeaders | Array of special headers |
array | $actualHeaders | Array of headers to check against |
Returns an array of the differences or FALSE if none
hasSubscriber(\Guzzle\Common\HasDispatcherInterface $dispatcher, \Symfony\Component\EventDispatcher\EventSubscriberInterface $subscriber) : boolean
Check if an event dispatcher has a subscriber
\Guzzle\Common\HasDispatcherInterface | $dispatcher | |
\Symfony\Component\EventDispatcher\EventSubscriberInterface | $subscriber |
<?php
namespace Guzzle\Tests\Http;
use Guzzle\Http\EntityBody;
use Guzzle\Http\ReadLimitEntityBody;
/**
* @covers Guzzle\Http\ReadLimitEntityBody
*/
class ReadLimitEntityBodyTest extends \Guzzle\Tests\GuzzleTestCase
{
/** @var ReadLimitEntityBody */
protected $body;
/** @var EntityBody */
protected $decorated;
public function setUp()
{
$this->decorated = EntityBody::factory(fopen(__FILE__, 'r'));
$this->body = new ReadLimitEntityBody($this->decorated, 10, 3);
}
public function testReturnsSubsetWhenCastToString()
{
$body = EntityBody::factory('foo_baz_bar');
$limited = new ReadLimitEntityBody($body, 3, 4);
$this->assertEquals('baz', (string) $limited);
}
public function testReturnsSubsetOfEmptyBodyWhenCastToString()
{
$body = EntityBody::factory('');
$limited = new ReadLimitEntityBody($body, 0, 10);
$this->assertEquals('', (string) $limited);
}
public function testSeeksWhenConstructed()
{
$this->assertEquals(3, $this->body->ftell());
}
public function testAllowsBoundedSeek()
{
$this->body->seek(100);
$this->assertEquals(13, $this->body->ftell());
$this->body->seek(0);
$this->assertEquals(3, $this->body->ftell());
$this->assertEquals(false, $this->body->seek(1000, SEEK_END));
}
public function testReadsOnlySubsetOfData()
{
$data = $this->body->read(100);
$this->assertEquals(10, strlen($data));
$this->assertFalse($this->body->read(1000));
$this->body->setOffset(10);
$newData = $this->body->read(100);
$this->assertEquals(10, strlen($newData));
$this->assertNotSame($data, $newData);
}
public function testClaimsConsumedWhenReadLimitIsReached()
{
$this->assertFalse($this->body->isConsumed());
$this->body->read(1000);
$this->assertTrue($this->body->isConsumed());
}
public function testContentLengthIsBounded()
{
$this->assertEquals(10, $this->body->getContentLength());
}
public function testContentMd5IsBasedOnSubsection()
{
$this->assertNotSame($this->body->getContentMd5(), $this->decorated->getContentMd5());
}
}