예제 #1
0
 /**
  * @covers Guzzle\Http\Exception\BadResponseException::factory
  */
 public function testCreatesServerErrorExceptionOnServerError()
 {
     $request = new Request('GET', 'http://www.example.com');
     $response = new Response(503);
     $e = BadResponseException::factory($request, $response);
     $this->assertInstanceOf('Guzzle\\Http\\Exception\\ServerErrorResponseException', $e);
 }
예제 #2
0
 /**
  * @param Event $event
  */
 public function onRequestSent(Event $event)
 {
     $body = json_decode($event['response']->getBody(true), true);
     if (!isset($body['ok']) || !$body['ok']) {
         throw BadResponseException::factory($event['request'], $event['response']);
     }
 }
예제 #3
0
 /**
  * @dataProvider getErrorMapping
  * @param string $httpMethod
  * @param int    $statusCode
  * @param string $description
  */
 public function testErrorDescriptions($httpMethod, $statusCode, $description)
 {
     $request = RequestFactory::getInstance()->fromMessage("{$httpMethod} /container/ HTTP/1.1\r\n" . "Host: www.foo.bar\r\n");
     $response = new Response($statusCode);
     $prevException = BadResponseException::factory($request, $response);
     $httpException = HttpException::factory($prevException);
     $this->assertEquals($description, $httpException->getDescription());
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public function getXML($resource, array $params = array(), array $headers = array(), array $options = array())
 {
     $response = $this->get($resource, $params, $headers, $options);
     if (!$response->isSuccessful()) {
         throw GuzzleRestException::createFromException(BadResponseException::factory($this->lastGuzzleRequest, $response->getSourceResponse()));
     }
     return $response->xml();
 }
예제 #5
0
 public function testIsAuthenticationValidServerError()
 {
     $that = $this;
     $request = $this->createMockRequest(function ($request) use($that) {
         return $that->throwException(BadResponseException::factory($request, $that->createMockResponse()));
     });
     $this->getMockHttpClient()->expects($this->once())->method('post')->will($this->returnValue($request));
     $this->setExpectedException('Guzzle\\Http\\Exception\\BadResponseException');
     $this->assertFalse($this->resource->isAuthenticationValid('foo', 'bar'));
 }
예제 #6
0
 public function testSendHandlesBadResponseException()
 {
     $request = new Request('GET', 'https://example.com');
     $expected = new Response(200, null, 'sometest');
     $clientMock = $this->getGuzzleClientMock(array('send'));
     $clientMock->expects($this->once())->method('send')->with($request)->will($this->throwException(BadResponseException::factory($request, $expected)));
     $httpClient = new HttpClient($clientMock);
     $actual = $httpClient->send($request);
     $this->assertEquals($expected, $actual, 'Expected response from BadResponseException.');
 }
 /**
  * Default method that will throw exceptions if an unsuccessful response
  * is received.
  *
  * @param Event $event Received
  * @throws BadResponseException if the response is not successful
  */
 public static function onRequestError(Event $event)
 {
     $e = BadResponseException::factory($event['request'], $event['response']);
     $event['request']->dispatch('request.exception', array('request' => $event['request'], 'response' => $event['response'], 'exception' => $e));
     throw $e;
 }
 /**
  * Default method that will throw exceptions if an unsuccessful response is received.
  *
  * @param Event $event Received
  * @throws BadResponseException if the response is not successful
  */
 public static function onRequestError(Event $event)
 {
     $e = BadResponseException::factory($event['request'], $event['response']);
     $event['request']->setState(self::STATE_ERROR, array('exception' => $e) + $event->toArray());
     throw $e;
 }
예제 #9
0
 private function createGuzzleException($statusCode, $body = null)
 {
     return \Guzzle\Http\Exception\BadResponseException::factory(new \Guzzle\Http\Message\Request('GET', 'http://example.com/'), new \Guzzle\Http\Message\Response($statusCode, null, $body));
 }
예제 #10
0
 /**
  *
  * @param \Guzzle\Http\Message\Response $response            
  * @return \Guzzle\Http\Client
  */
 protected function getHttpClientMock(Response $response)
 {
     $client = $this->getMockBuilder('\\Guzzle\\Http\\Client')->setMethods(array('send'))->getMock();
     if ($response->isError()) {
         $request = $this->getMockBuilder('\\Guzzle\\Http\\Message\\Request')->disableOriginalConstructor()->getMock();
         $e = BadResponseException::factory($request, $response);
         $client->expects($this->any())->method('send')->will($this->throwException($e));
     } else {
         $client->expects($this->any())->method('send')->will($this->returnValue($response));
     }
     return $client;
 }