1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32:
<?php
namespace Guzzle\Tests\Plugin\Backoff;
use Guzzle\Plugin\Backoff\CallbackBackoffStrategy;
class CallbackBackoffStrategyTest extends \Guzzle\Tests\GuzzleTestCase
{
public function testEnsuresIsCallable()
{
$strategy = new CallbackBackoffStrategy(new \stdClass(), true);
}
public function testRetriesWithCallable()
{
$request = $this->getMock('Guzzle\Http\Message\Request', array(), array(), '', false);
$strategy = new CallbackBackoffStrategy(function () { return 10; }, true);
$this->assertTrue($strategy->makesDecision());
$this->assertEquals(10, $strategy->getBackoffPeriod(0, $request));
$strategy = new CallbackBackoffStrategy(function () { return null; }, false);
$this->assertFalse($strategy->makesDecision());
$this->assertFalse($strategy->getBackoffPeriod(0, $request));
}
}