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

RequestTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 79
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetMethod() 0 5 1
A testGetPath() 0 5 1
A testAuth() 0 8 1
A testHeaders() 0 8 1
A testParams() 0 8 1
A testJson() 0 11 1
A testApiVersion() 0 8 1
A testIsGraphQL() 0 8 1
A testGetUrl() 0 7 1
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