1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace spec\TomPHP\HalClient; |
4
|
|
|
|
5
|
|
|
use PhpSpec\ObjectBehavior; |
6
|
|
|
use Prophecy\Argument; |
7
|
|
|
use Psr\Http\Message\ResponseInterface; |
8
|
|
|
use TomPHP\HalClient\Exception\UnknownContentTypeException; |
9
|
|
|
use TomPHP\HalClient\HttpClient; |
10
|
|
|
use TomPHP\HalClient\Processor; |
11
|
|
|
use TomPHP\HalClient\Resource\Resource; |
12
|
|
|
|
13
|
|
|
class ClientSpec extends ObjectBehavior |
14
|
|
|
{ |
15
|
|
|
function let(HttpClient $httpClient, Processor $processor) |
16
|
|
|
{ |
17
|
|
|
$processor->getContentType()->willReturn('application/hal+json'); |
18
|
|
|
$processor->process(Argument::any())->willReturn(); |
19
|
|
|
|
20
|
|
|
$this->beConstructedWith($httpClient, [$processor]); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
function it_throws_if_content_type_is_unknown(HttpClient $httpClient, ResponseInterface $response) |
24
|
|
|
{ |
25
|
|
|
$response->getHeader('content-type')->willReturn(['application/unknown-type']); |
26
|
|
|
$httpClient->get('http://api.test.com/')->willReturn($response); |
27
|
|
|
|
28
|
|
|
$this->shouldThrow( |
29
|
|
|
new UnknownContentTypeException('application/unknown-type') |
30
|
|
|
)->duringGet('http://api.test.com/'); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
function it_returns_a_processed_resource(ResponseInterface $response, HttpClient $httpClient, Processor $processor) |
34
|
|
|
{ |
35
|
|
|
$response->getHeader('content-type')->willReturn(['application/hal+json']); |
36
|
|
|
$resource = new Resource([], []); |
37
|
|
|
|
38
|
|
|
$httpClient->get('http://api.test.com/')->willReturn($response); |
39
|
|
|
|
40
|
|
|
$processor->process($response, $this)->willReturn($resource); |
41
|
|
|
|
42
|
|
|
$this->get('http://api.test.com/')->shouldReturn($resource); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|