$serviceBuilder
$serviceBuilder :
Base testcase class for all Guzzle testcases.
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\Plugin\Backoff;
use Guzzle\Http\Message\Request;
use Guzzle\Plugin\Backoff\TruncatedBackoffStrategy;
use Guzzle\Plugin\Backoff\CallbackBackoffStrategy;
/**
* @covers Guzzle\Plugin\Backoff\AbstractBackoffStrategy
*/
class AbstractBackoffStrategyTest extends \Guzzle\Tests\GuzzleTestCase
{
protected function getMockStrategy()
{
return $this->getMockBuilder('Guzzle\Plugin\Backoff\AbstractBackoffStrategy')
->setMethods(array('getDelay', 'makesDecision'))
->getMockForAbstractClass();
}
public function testReturnsZeroWhenNoNextAndGotNull()
{
$request = new Request('GET', 'http://www.foo.com');
$mock = $this->getMockStrategy();
$mock->expects($this->atLeastOnce())->method('getDelay')->will($this->returnValue(null));
$this->assertEquals(0, $mock->getBackoffPeriod(0, $request));
}
public function testReturnsFalse()
{
$request = new Request('GET', 'http://www.foo.com');
$mock = $this->getMockStrategy();
$mock->expects($this->atLeastOnce())->method('getDelay')->will($this->returnValue(false));
$this->assertEquals(false, $mock->getBackoffPeriod(0, $request));
}
public function testReturnsNextValueWhenNullOrTrue()
{
$request = new Request('GET', 'http://www.foo.com');
$mock = $this->getMockStrategy();
$mock->expects($this->atLeastOnce())->method('getDelay')->will($this->returnValue(null));
$mock->expects($this->any())->method('makesDecision')->will($this->returnValue(false));
$mock2 = $this->getMockStrategy();
$mock2->expects($this->atLeastOnce())->method('getDelay')->will($this->returnValue(10));
$mock2->expects($this->atLeastOnce())->method('makesDecision')->will($this->returnValue(true));
$mock->setNext($mock2);
$this->assertEquals(10, $mock->getBackoffPeriod(0, $request));
}
public function testReturnsFalseWhenNullAndNoNext()
{
$request = new Request('GET', 'http://www.foo.com');
$s = new TruncatedBackoffStrategy(2);
$this->assertFalse($s->getBackoffPeriod(0, $request));
}
public function testHasNext()
{
$a = new TruncatedBackoffStrategy(2);
$b = new TruncatedBackoffStrategy(2);
$a->setNext($b);
$this->assertSame($b, $a->getNext());
}
public function testSkipsOtherDecisionsInChainWhenOneReturnsTrue()
{
$a = new CallbackBackoffStrategy(function () { return null; }, true);
$b = new CallbackBackoffStrategy(function () { return true; }, true);
$c = new CallbackBackoffStrategy(function () { return null; }, true);
$d = new CallbackBackoffStrategy(function () { return 10; }, false);
$a->setNext($b);
$b->setNext($c);
$c->setNext($d);
$this->assertEquals(10, $a->getBackoffPeriod(2, new Request('GET', 'http://www.foo.com')));
}
public function testReturnsZeroWhenDecisionMakerReturnsTrueButNoFurtherStrategiesAreInTheChain()
{
$a = new CallbackBackoffStrategy(function () { return null; }, true);
$b = new CallbackBackoffStrategy(function () { return true; }, true);
$a->setNext($b);
$this->assertSame(0, $a->getBackoffPeriod(2, new Request('GET', 'http://www.foo.com')));
}
}