Test Failed
Pull Request — master (#65)
by
unknown
02:00
created

ResponseTest   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 126
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

11 Methods

Rating   Name   Duplication   Size   Complexity  
A testSuccessResponseHTTPCodes() 0 8 1
A providerTestSuccessResponseHTTPCodes() 0 10 1
A testReturnOfHTTPStatusCodes() 0 8 1
A providerTestReturnOfHTTPStatusCodes() 0 8 1
A testReturnOfResponseDataAsArray() 0 8 1
A testReturnOfEmptyResponseDataAsArray() 0 8 1
A testReturnOfResponseDataAsObject() 0 8 1
A testReturnOfEmptyResponseDataAsObject() 0 8 1
A testReturnOfResponseDataAsRaw() 0 10 1
A testReturnOfResponseHeadersArrayKeyValuePairArray() 0 9 1
A testReturnOfResponseHeaderServer() 0 7 1
1
<?php
2
3
namespace QuickPay\Tests;
4
5
use QuickPay\API\Response;
6
7
class ResponseTest extends \PHPUnit_Framework_TestCase
8
{
9
    private $responseTestHeaders = "Server: nginx
10
    Date: Fri, 09 Apr 2021 09:13:04 GMT
11
    Content-Type: application/json";
12
    private $responseTestData = '{ "key1": "value1", "key2": "value2" }';
13
14
    /**
15
     * Test the success response HTTP codes.
16
     *
17
     * @param string $httpCode       The HTTP code we want to test
18
     * @param string $expectedResult What we expect the result to be
19
     *
20
     * @dataProvider providerTestSuccessResponseHTTPCodes
21
     */
22
    public function testSuccessResponseHTTPCodes($httpCode, $expectedResult)
23
    {
24
        $response = new Response($httpCode, '', '', '');
25
26
        $result = $response->isSuccess();
27
28
        $this->assertEquals($result, $expectedResult);
29
    }
30
31
    public function providerTestSuccessResponseHTTPCodes()
32
    {
33
        return array(
34
            array(200, true),
35
            array(255, true),
36
            array(299, true),
37
            array(300, false),
38
            array(400, false)
39
        );
40
    }
41
42
    /**
43
     * Test the return of HTTP status codes.
44
     *
45
     * @param string $httpCode     The HTTP code we want to test
46
     * @param string $expectedCode What we expect the result to be
47
     *
48
     * @dataProvider providerTestReturnOfHTTPStatusCodes
49
     */
50
    public function testReturnOfHTTPStatusCodes($httpCode, $expectedCode)
51
    {
52
        $response = new Response($httpCode, '', '', '');
53
54
        $statusCode = $response->httpStatus();
55
56
        $this->assertEquals($statusCode, $expectedCode);
57
    }
58
59
    public function providerTestReturnOfHTTPStatusCodes()
60
    {
61
        return array(
62
            array(200, 200),
63
            array(300, 300),
64
            array(500, 500)
65
        );
66
    }
67
68
    public function testReturnOfResponseDataAsArray()
69
    {
70
        $response = new Response(200, '', '', $this->responseTestData);
71
72
        $responseArray = $response->asArray();
73
74
        $this->assertTrue(is_array($responseArray));
75
    }
76
77
    public function testReturnOfEmptyResponseDataAsArray()
78
    {
79
        $response = new Response(200, '', '', '');
80
81
        $responseArray = $response->asArray();
82
83
        $this->assertTrue(is_array($responseArray));
84
    }
85
86
    public function testReturnOfResponseDataAsObject()
87
    {
88
        $response = new Response(200, '', '', $this->responseTestData);
89
90
        $responseObject = $response->asObject();
91
92
        $this->assertTrue(is_object($responseObject));
93
    }
94
95
    public function testReturnOfEmptyResponseDataAsObject()
96
    {
97
        $response = new Response(200, '', '', '');
98
99
        $responseObject = $response->asObject();
100
101
        $this->assertTrue(is_object($responseObject));
102
    }
103
104
    public function testReturnOfResponseDataAsRaw()
105
    {
106
        $response = new Response(200, '', '', $this->responseTestData);
107
108
        list($statusCode, $headers, $responseRaw) = $response->asRaw();
109
110
        $this->assertTrue(is_int($statusCode));
111
        $this->assertTrue(is_array($headers));
112
        $this->assertTrue(is_string($responseRaw));
113
    }
114
    
115
    public function testReturnOfResponseHeadersArrayKeyValuePairArray()
116
    {
117
        $response = new Response(200, '', $this->responseTestHeaders, $this->responseTestData);
118
        $headers = $response->getHeaders();
119
        
120
        $isAssociativeArray = (bool)count(array_filter(array_keys($headers), 'is_string')) > 0;
121
122
        $this->assertTrue($isAssociativeArray);
123
    }
124
125
    public function testReturnOfResponseHeaderServer()
126
    {
127
        $response = new Response(200, '', $this->responseTestHeaders, $this->responseTestData);
128
        $header = $response->getHeader('Server');
129
130
        $this->assertTrue(is_string($header));
131
    }
132
}
133