Open Monograph Press  3.3.0
ErrorResponsePluginTest.php
1 <?php
2 
4 
10 
15 {
16  protected $client;
17 
18  public static function tearDownAfterClass()
19  {
20  self::getServer()->flush();
21  }
22 
23  public function setUp()
24  {
25  $mockError = 'Guzzle\Tests\Mock\ErrorResponseMock';
26  $description = ServiceDescription::factory(array(
27  'operations' => array(
28  'works' => array(
29  'httpMethod' => 'GET',
30  'errorResponses' => array(
31  array('code' => 500, 'class' => $mockError),
32  array('code' => 503, 'reason' => 'foo', 'class' => $mockError),
33  array('code' => 200, 'reason' => 'Error!', 'class' => $mockError)
34  )
35  ),
36  'bad_class' => array(
37  'httpMethod' => 'GET',
38  'errorResponses' => array(
39  array('code' => 500, 'class' => 'Does\\Not\\Exist')
40  )
41  ),
42  'does_not_implement' => array(
43  'httpMethod' => 'GET',
44  'errorResponses' => array(
45  array('code' => 500, 'class' => __CLASS__)
46  )
47  ),
48  'no_errors' => array('httpMethod' => 'GET'),
49  'no_class' => array(
50  'httpMethod' => 'GET',
51  'errorResponses' => array(
52  array('code' => 500)
53  )
54  ),
55  )
56  ));
57  $this->client = new Client($this->getServer()->getUrl());
58  $this->client->setDescription($description);
59  }
60 
65  {
66  $this->getServer()->enqueue("HTTP/1.1 500 Foo\r\nContent-Length: 0\r\n\r\n");
67  $this->client->addSubscriber(new ErrorResponsePlugin());
68  $this->client->getCommand('no_errors')->execute();
69  }
70 
72  {
73  $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
74  $this->client->addSubscriber(new ErrorResponsePlugin());
75  $this->client->getCommand('no_errors')->execute();
76  }
77 
83  {
84  $this->getServer()->enqueue("HTTP/1.1 500 Foo\r\nContent-Length: 0\r\n\r\n");
85  $this->client->addSubscriber(new ErrorResponsePlugin());
86  $this->client->getCommand('bad_class')->execute();
87  }
88 
94  {
95  $this->getServer()->enqueue("HTTP/1.1 500 Foo\r\nContent-Length: 0\r\n\r\n");
96  $this->client->addSubscriber(new ErrorResponsePlugin());
97  $this->client->getCommand('does_not_implement')->execute();
98  }
99 
101  {
102  try {
103  $this->getServer()->enqueue("HTTP/1.1 500 Foo\r\nContent-Length: 0\r\n\r\n");
104  $this->client->addSubscriber(new ErrorResponsePlugin());
105  $command = $this->client->getCommand('works');
106  $command->execute();
107  $this->fail('Exception not thrown');
108  } catch (ErrorResponseMock $e) {
109  $this->assertSame($command, $e->command);
110  $this->assertEquals(500, $e->response->getStatusCode());
111  }
112  }
113 
118  {
119  $this->getServer()->enqueue("HTTP/1.1 200 Error!\r\nContent-Length: 0\r\n\r\n");
120  $this->client->addSubscriber(new ErrorResponsePlugin());
121  $this->client->getCommand('works')->execute();
122  }
123 
125  {
126  $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
127  $this->client->addSubscriber(new ErrorResponsePlugin());
128  $this->client->getCommand('works')->execute();
129  }
130 
131  public function testSkipsWhenNoClassIsSet()
132  {
133  $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
134  $this->client->addSubscriber(new ErrorResponsePlugin());
135  $this->client->getCommand('no_class')->execute();
136  }
137 }
Guzzle\Tests\GuzzleTestCase
Definition: GuzzleTestCase.php:22
Guzzle\Tests\Plugin\ErrorResponse\ErrorResponsePluginTest\tearDownAfterClass
static tearDownAfterClass()
Definition: ErrorResponsePluginTest.php:18
Guzzle\Service\Client
Definition: paymethod/paypal/lib/vendor/guzzle/guzzle/src/Guzzle/Service/Client.php:25
Guzzle\Tests\Plugin\ErrorResponse\ErrorResponsePluginTest\testThrowsWhenCodeAndPhraseMatch
testThrowsWhenCodeAndPhraseMatch()
Definition: ErrorResponsePluginTest.php:117
Guzzle\Service\Description\ServiceDescription\factory
static factory($config, array $options=array())
Definition: ServiceDescription.php:65
Guzzle\Http\Message\Response
Definition: paymethod/paypal/lib/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php:17
Guzzle\Tests\Plugin\ErrorResponse\ErrorResponsePluginTest\setUp
setUp()
Definition: ErrorResponsePluginTest.php:23
Guzzle\Service\Description\ServiceDescription
Definition: ServiceDescription.php:11
Guzzle\Tests\Plugin\ErrorResponse
Definition: ErrorResponsePluginTest.php:3
Guzzle\Tests\Plugin\ErrorResponse\ErrorResponsePluginTest\testThrowsSpecificErrorResponseOnMatch
testThrowsSpecificErrorResponseOnMatch()
Definition: ErrorResponsePluginTest.php:100
Guzzle\Tests\Plugin\ErrorResponse\ErrorResponsePluginTest\testSkipsWhenErrorResponsesIsNotSet
testSkipsWhenErrorResponsesIsNotSet()
Definition: ErrorResponsePluginTest.php:64
Guzzle\Tests\Plugin\ErrorResponse\ErrorResponsePluginTest\testSkipsWhenErrorResponsesIsNotSetAndAllowsSuccess
testSkipsWhenErrorResponsesIsNotSetAndAllowsSuccess()
Definition: ErrorResponsePluginTest.php:71
Guzzle\Tests\Plugin\ErrorResponse\ErrorResponsePluginTest\testSkipsWhenReasonDoesNotMatch
testSkipsWhenReasonDoesNotMatch()
Definition: ErrorResponsePluginTest.php:124
Guzzle\Plugin\ErrorResponse\ErrorResponsePlugin
Definition: ErrorResponsePlugin.php:15
Guzzle\Tests\Plugin\ErrorResponse\ErrorResponsePluginTest
Definition: ErrorResponsePluginTest.php:14
Guzzle\Tests\Plugin\ErrorResponse\ErrorResponsePluginTest\testSkipsWhenNoClassIsSet
testSkipsWhenNoClassIsSet()
Definition: ErrorResponsePluginTest.php:131
Guzzle\Tests\Mock\ErrorResponseMock
Definition: ErrorResponseMock.php:9
Guzzle\Tests\Plugin\ErrorResponse\ErrorResponsePluginTest\testEnsuresErrorResponseExists
testEnsuresErrorResponseExists()
Definition: ErrorResponsePluginTest.php:82
Guzzle\Tests\Plugin\ErrorResponse\ErrorResponsePluginTest\testEnsuresErrorResponseImplementsInterface
testEnsuresErrorResponseImplementsInterface()
Definition: ErrorResponsePluginTest.php:93
Guzzle\Tests\GuzzleTestCase\getServer
static getServer()
Definition: GuzzleTestCase.php:36
Guzzle\Tests\Plugin\ErrorResponse\ErrorResponsePluginTest\$client
$client
Definition: ErrorResponsePluginTest.php:16