public function get($url) { $response = $this->httpClient->get($url); $contentTypes = $response->getHeader('content-type'); $contentType = array_shift($contentTypes); if (!array_key_exists($contentType, $this->processors)) { throw new UnknownContentTypeException($contentType); } $processor = $this->processors[$contentType]; return $processor->process($response, $this); }
function it_returns_a_processed_resource(ResponseInterface $response, HttpClient $httpClient, Processor $processor) { $response->getHeader('content-type')->willReturn(['application/hal+json']); $resource = new Resource([], []); $httpClient->get('http://api.test.com/')->willReturn($response); $processor->process($response, $this)->willReturn($resource); $this->get('http://api.test.com/')->shouldReturn($resource); }