Passed
Push — master ( 5319ee...e6b641 )
by Dani
02:13
created

tests/Http/RequestTest.php (2 issues)

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\Postpay;
8
9
class RequestTest extends TestCase
10
{
11
    public function testGetMethod()
12
    {
13
        $request = new Request('get');
14
        self::assertEquals('GET', $request->getMethod());
15
    }
16
17
    public function testGetPath()
18
    {
19
        $request = new Request('GET', '/');
20
        self::assertEquals('/', $request->getPath());
21
    }
22
23
    public function testAuth()
24
    {
25
        $request = new Request('GET');
26
        $auth = ['user', 'password'];
27
        $request->setAuth($auth);
28
29
        self::assertEquals($auth, $request->getAuth());
30
    }
31
32
    public function testHeaders()
33
    {
34
        $request = new Request('GET');
35
        $headers = ['Test' => true];
36
        $request->setHeaders($headers);
37
38
        self::assertArraySubset($headers, $request->getHeaders());
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit\Framework\Assert::assertArraySubset() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/issues/3494

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
39
    }
40
41
    public function testParams()
42
    {
43
        $request = new Request('GET');
44
        $params = ['test' => true];
45
        $request->setParams($params);
46
47
        self::assertArraySubset($params, $request->getParams());
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit\Framework\Assert::assertArraySubset() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/issues/3494

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
48
    }
49
50
    public function testJson()
51
    {
52
        $request = new Request('GET');
53
        $params = ['test' => true];
54
55
        $request->setParams($params);
56
        self::assertEmpty($request->json());
57
58
        $request->setMethod('POST');
59
        self::assertNotEmpty($request->json());
60
    }
61
62
    public function testApiVersion()
63
    {
64
        $request = new Request('GET');
65
        $version = 'v1';
66
        $request->setApiVersion($version);
67
68
        self::assertEquals($version, $request->getApiVersion());
69
    }
70
71
    public function testIsGraphQL()
72
    {
73
        $request = new Request('GET');
74
        self::assertFalse($request->isGraphQL());
75
76
        $request->setApiVersion(Postpay::GRAPHQL_VERSION);
77
        self::assertTrue($request->isGraphQL());
78
    }
79
80
    public function testGetUrl()
81
    {
82
        $path = '/test';
83
        $request = new Request('GET', $path);
84
85
        self::assertStringEndsWith($path, $request->getUrl());
86
    }
87
}
88