/**
  * @covers Guzzle\Http\Exception\BadResponseException
  */
 public function testBadResponseException()
 {
     $e = new BadResponseException('Message');
     $response = new Response(200);
     $e->setResponse($response);
     $this->assertEquals($response, $e->getResponse());
 }
示例#2
0
 /**
  * @expectedException League\OAuth2\Client\Exception\IDPException
  */
 public function testGetAccessTokenFailure()
 {
     $response = m::mock('Guzzle\\Http\\Message\\Response');
     $response->shouldReceive('getBody')->times(1)->andReturn('{"type": "internal_server_error", "message": "Something went wrong"}');
     $exception = new BadResponseException();
     $exception->setResponse($response);
     $request = m::mock('Guzzle\\Http\\Message\\Request');
     $request->shouldReceive('setBody')->with($body = m::type('string'), $type = 'application/json')->times(1)->andReturn($request);
     $request->shouldReceive('send')->times(1)->andThrow($exception);
     $client = m::mock('Guzzle\\Service\\Client');
     $client->shouldReceive('post')->with($this->provider->urlRenewToken(), m::on(function ($headers) {
         return !empty($headers['Authorization']) && strpos($headers['Authorization'], 'Client') === 0;
     }))->times(1)->andReturn($request);
     $this->provider->setHttpClient($client);
     $this->provider->getAccessToken('renew_token', ['access_token' => 'mock_token']);
 }
示例#3
0
 /**
  * @covers PusherService::handleException
  * @dataProvider exceptionDataProvider
  */
 public function testExceptionsAreThrownOnErrors($statusCode, $expectedException)
 {
     $method = new ReflectionMethod('ZfrPusher\\Service\\PusherService', 'handleException');
     $method->setAccessible(true);
     $exception = new BadResponseException();
     $exception->setResponse(new Response($statusCode));
     $this->setExpectedException($expectedException);
     $method->invoke($this->service, $exception);
 }