ApiResponseTest::testGetHeader()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
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);
0 ignored issues
show
Bug introduced by
The method willReturn cannot be called on $this->response->getStatusCode() (of type integer).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
28
        $this->assertSame($expectedValue, $this->apiResponse->getStatusCode());
29
    }
30
31
    public function testGetHeaders()
32
    {
33
        $expectedValue = [];
34
        $this->response->getHeaders()->willReturn($expectedValue);
0 ignored issues
show
Bug introduced by
The method willReturn cannot be called on $this->response->getHeaders() (of type array<integer,array<integer,string>>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
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]);
0 ignored issues
show
Bug introduced by
The method willReturn cannot be called on $this->response->getHeader('Content-Type') (of type array<integer,string>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
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);
0 ignored issues
show
Bug introduced by
The method willReturn cannot be called on $stream->__toString() (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
53
        $this->response->getBody()->willReturn($stream->reveal());
0 ignored issues
show
Bug introduced by
The method reveal() does not seem to exist on object<Psr\Http\Message\StreamInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method willReturn() does not seem to exist on object<Psr\Http\Message\StreamInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
54
55
        $this->assertSame($expectedValue, $this->apiResponse->getBody());
56
    }
57
58
    public function testIsRedirect()
59
    {
60
        $this->response->getStatusCode()->willReturn(301);
0 ignored issues
show
Bug introduced by
The method willReturn cannot be called on $this->response->getStatusCode() (of type integer).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
61
        $this->assertTrue($this->apiResponse->isRedirect());
62
    }
63
}
64