/** * @param int $code * @param string $class * * @dataProvider dataProviderErrorCodes */ public function testClientThrowsRateLimitException($code, $class) { $this->setExpectedException($class); $this->createTestConfig(); $request = new Request('POST', 'http://not-important'); $response = new Response($code); $requestException = new RequestException('Not Important', $request, $response); $httpClientMock = $this->getMock('GuzzleHttp\\Client', ['send']); $httpClientMock->expects($this->at(0))->method('send')->will($this->throwException($requestException)); if ($code === 401) { // 401 renew auth token handling $jsonResponseData = ['access_token' => '__token__', 'expires_in' => '1337']; $renewAuthTokenResponse = new Response(200); $renewAuthTokenResponse->setBody(Stream::factory(json_encode($jsonResponseData))); $httpClientMock->expects($this->at(1))->method('send')->will($this->returnValue($renewAuthTokenResponse)); $httpClientMock->expects($this->at(2))->method('send')->will($this->throwException($requestException)); } $client = new Api\Client('__oauthId__', $this->app['hc.config'], $this->app['hc.api_registry'], $httpClientMock, $this->app['logger']); $client->send('/not-important', []); }
/** * @param Api\Response $response */ public function sendRoomMsg(Api\Response $response) { $uri = sprintf('room/%d/notification', $this->request->getRoom()->getId()); $this->client->send($uri, $response->toArray()); }