Passed
Push — master ( e6b641...f65816 )
by Dani
01:36
created

tests/Http/ResponseTest.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Postpay\Tests\Http;
4
5
use PHPUnit\Framework\TestCase;
6
use Postpay\Http\Request;
7
use Postpay\Http\Response;
8
use Postpay\Exceptions\RESTfulException;
9
10
class ResponseTest extends TestCase
11
{
12
    public function setUp()
13
    {
14
        $this->request = new Request('GET');
0 ignored issues
show
The property request does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
15
    }
16
17
    public function testGetRequest()
18
    {
19
        $response = new Response($this->request);
20
21
        self::assertEquals($this->request, $response->getRequest());
22
    }
23
24
    public function testGetStatusCode()
25
    {
26
        $response = new Response($this->request, 200);
27
        self::assertSame(200, $response->getStatusCode());
28
    }
29
30
    public function testGetHeaders()
31
    {
32
        $headers = ['test' => true];
33
        $response = new Response($this->request, 200, $headers);
34
35
        self::assertEquals($headers, $response->getHeaders());
36
    }
37
38
    public function testJson()
39
    {
40
        $json = ['test' => true];
41
        $response = new Response($this->request, 200, [], json_encode($json));
42
43
        self::assertEquals($json, $response->json());
44
    }
45
46
    public function testIsError()
47
    {
48
        $body = json_encode([RESTfulException::ERROR_KEY => true]);
49
        $response = new Response($this->request, 400, [], $body);
50
51
        self::assertTrue($response->isError());
52
53
        self::assertInstanceOf(
54
            RESTfulException::class,
55
            $response->getThrownException()
56
        );
57
    }
58
59
    public function testDecodeNonJson()
60
    {
61
        $response = new Response($this->request, 200, [], '-');
62
63
        self::assertEmpty($response->json());
64
    }
65
}
66