function it_makes_http_get_request(HttpClientInterface $httpClient, RequestFactoryInterface $requestFactory, RequestInterface $request, ResponseInterface $response, StreamInterface $stream) { $expectedResponse = 'response'; $apiHttpPathAndQuery = ApiHttpPathAndQuery::createForPathAndQuery(self::API_PATH, self::API_QUERY); $uri = sprintf('%s/%s', self::API_ENDPOINT, $apiHttpPathAndQuery->getPathAndQuery()); $requestFactory->createRequest(ApiHttpClient::GET_REQUEST, $uri, $this->apiHttpClientConfiguration->buildHeaders())->shouldBeCalled()->willReturn($request); $httpClient->sendRequest($request)->willReturn($response); $response->getBody()->willReturn($stream); $response->getStatusCode()->willReturn(200); $stream->getContents()->willReturn($expectedResponse); $this->get($apiHttpPathAndQuery)->shouldReturn($expectedResponse); }
/** * {@inheritdoc} */ public function get(ApiHttpPathAndQuery $apiHttpPathAndQuery) { try { $request = $this->requestFactory->createRequest(self::GET_REQUEST, $this->apiHttpClientConfiguration->buildUri($apiHttpPathAndQuery), $this->apiHttpClientConfiguration->buildHeaders()); $response = $this->httpClient->sendRequest($request); } catch (Exception $exception) { if ($this->isNotFoundError($exception)) { throw new ApiHttpClientNotFoundException($this->apiHttpClientConfiguration->buildUri($apiHttpPathAndQuery)); } throw new ApiHttpClientException($exception->getMessage(), $exception->getCode(), $exception); } return $response->getBody()->getContents(); }