Open Monograph Press  3.3.0
HttpBackoffStrategyTest.php
1 <?php
2 
4 
7 
13 {
14  public function testRetriesWhenCodeMatches()
15  {
16  $this->assertNotEmpty(HttpBackoffStrategy::getDefaultFailureCodes());
17  $strategy = new HttpBackoffStrategy();
18  $this->assertTrue($strategy->makesDecision());
19  $request = $this->getMock('Guzzle\Http\Message\Request', array(), array(), '', false);
20 
21  $response = new Response(200);
22  $this->assertEquals(false, $strategy->getBackoffPeriod(0, $request, $response));
23  $response->setStatus(400);
24  $this->assertEquals(false, $strategy->getBackoffPeriod(0, $request, $response));
25 
26  foreach (HttpBackoffStrategy::getDefaultFailureCodes() as $code) {
27  $this->assertEquals(0, $strategy->getBackoffPeriod(0, $request, $response->setStatus($code)));
28  }
29  }
30 
31  public function testAllowsCustomCodes()
32  {
33  $strategy = new HttpBackoffStrategy(array(204));
34  $request = $this->getMock('Guzzle\Http\Message\Request', array(), array(), '', false);
35  $response = new Response(204);
36  $this->assertEquals(0, $strategy->getBackoffPeriod(0, $request, $response));
37  $response->setStatus(500);
38  $this->assertEquals(false, $strategy->getBackoffPeriod(0, $request, $response));
39  }
40 
41  public function testIgnoresNonErrors()
42  {
43  $strategy = new HttpBackoffStrategy();
44  $request = $this->getMock('Guzzle\Http\Message\Request', array(), array(), '', false);
45  $this->assertEquals(false, $strategy->getBackoffPeriod(0, $request));
46  }
47 }
Guzzle\Tests\GuzzleTestCase
Definition: GuzzleTestCase.php:22
Guzzle\Tests\Plugin\Backoff\HttpBackoffStrategyTest\testRetriesWhenCodeMatches
testRetriesWhenCodeMatches()
Definition: HttpBackoffStrategyTest.php:14
Guzzle\Http\Message\Response
Definition: paymethod/paypal/lib/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php:17
Guzzle\Tests\Plugin\Backoff\HttpBackoffStrategyTest\testIgnoresNonErrors
testIgnoresNonErrors()
Definition: HttpBackoffStrategyTest.php:41
Guzzle\Tests\Plugin\Backoff\HttpBackoffStrategyTest\testAllowsCustomCodes
testAllowsCustomCodes()
Definition: HttpBackoffStrategyTest.php:31
Guzzle\Plugin\Backoff\HttpBackoffStrategy
Definition: HttpBackoffStrategy.php:14
Guzzle\Tests\Plugin\Backoff
Definition: AbstractBackoffStrategyTest.php:3
Guzzle\Plugin\Backoff\AbstractErrorCodeBackoffStrategy\getDefaultFailureCodes
static getDefaultFailureCodes()
Definition: AbstractErrorCodeBackoffStrategy.php:34
Guzzle\Tests\Plugin\Backoff\HttpBackoffStrategyTest
Definition: HttpBackoffStrategyTest.php:12