1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Franjid\ApiWrapperBundle\Tests\Api; |
4
|
|
|
|
5
|
|
|
use Franjid\ApiWrapperBundle\Api\ApiResponse; |
6
|
|
|
use Franjid\ApiWrapperBundle\Api\ApiResponseInterface; |
7
|
|
|
use Psr\Http\Message\ResponseInterface; |
8
|
|
|
use Psr\Http\Message\StreamInterface; |
9
|
|
|
|
10
|
|
|
class ApiResponseTest extends \PHPUnit_Framework_TestCase |
11
|
|
|
{ |
12
|
|
|
/** @var ResponseInterface $response */ |
13
|
|
|
protected $response; |
14
|
|
|
|
15
|
|
|
/** @var ApiResponseInterface $apiResponse */ |
16
|
|
|
protected $apiResponse; |
17
|
|
|
|
18
|
|
|
public function setUp() |
19
|
|
|
{ |
20
|
|
|
$this->response = $this->prophesize(ResponseInterface::class); |
21
|
|
|
$this->apiResponse = new ApiResponse($this->response->reveal()); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function testGetStatusCode() |
25
|
|
|
{ |
26
|
|
|
$expectedValue = 200; |
27
|
|
|
$this->response->getStatusCode()->willReturn($expectedValue); |
|
|
|
|
28
|
|
|
$this->assertSame($expectedValue, $this->apiResponse->getStatusCode()); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testGetHeaders() |
32
|
|
|
{ |
33
|
|
|
$expectedValue = []; |
34
|
|
|
$this->response->getHeaders()->willReturn($expectedValue); |
|
|
|
|
35
|
|
|
$this->assertSame($expectedValue, $this->apiResponse->getHeaders()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testGetHeader() |
39
|
|
|
{ |
40
|
|
|
$expectedValue = 'application/json'; |
41
|
|
|
$this->response->getHeader('Content-Type')->willReturn([$expectedValue]); |
|
|
|
|
42
|
|
|
$this->assertSame($expectedValue, $this->apiResponse->getHeader('Content-Type')); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testGetBody() |
46
|
|
|
{ |
47
|
|
|
$expectedValue = '{"test": true}'; |
48
|
|
|
|
49
|
|
|
/** @var StreamInterface $stream */ |
50
|
|
|
$stream = $this->prophesize(StreamInterface::class); |
51
|
|
|
|
52
|
|
|
$stream->__toString()->willReturn($expectedValue); |
|
|
|
|
53
|
|
|
$this->response->getBody()->willReturn($stream->reveal()); |
|
|
|
|
54
|
|
|
|
55
|
|
|
$this->assertSame($expectedValue, $this->apiResponse->getBody()); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testIsRedirect() |
59
|
|
|
{ |
60
|
|
|
$this->response->getStatusCode()->willReturn(301); |
|
|
|
|
61
|
|
|
$this->assertTrue($this->apiResponse->isRedirect()); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.