Passed
Push — master ( b111b6...d62ebd )
by
unknown
01:46
created

RequestTest::testAdditionalHeadersAfterInit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace QuickPay\Tests;
4
5
use QuickPay\API\Client;
6
use QuickPay\API\Request;
7
use QuickPay\API\Response;
8
9
class RequestTest extends \PHPUnit_Framework_TestCase
10
{
11
	/**
12
	 * @var Client
13
	 */
14
    protected $client;
15
16
	/**
17
	 * @var Request
18
	 */
19
    protected $request;
20
21
    public function setUp()
22
    {
23
        $this->client = new Client();
24
        $this->request = new Request($this->client);
25
    }
26
27
    public function testResponseInstance()
28
    {
29
        $pingResponse = $this->request->get('/ping');
30
31
        $this->assertTrue(($pingResponse instanceof Response));
32
    }
33
34
    public function testBadAuthentication()
35
    {
36
        $client = new Client(':foo');
37
        $request = new Request($client);
38
39
        $response = $request->get('/ping');
40
41
        $this->assertEquals(401, $response->httpStatus());
42
    }
43
44
    public function testSuccessfulGetResponse()
45
    {
46
        $pingResponse = $this->request->get('/ping');
47
48
        $this->assertTrue($pingResponse->isSuccess());
49
    }
50
51
    public function testFailedGetResponse()
52
    {
53
        $pingResponse = $this->request->get('/foobar');
54
55
        $this->assertFalse($pingResponse->isSuccess());
56
    }
57
58
    public function testSuccesfulPostResponse()
59
    {
60
        $pingResponse = $this->request->post('/ping');
61
62
        $this->assertTrue($pingResponse->isSuccess());
63
    }
64
65
    public function testFailedPostResponse()
66
    {
67
        $pingResponse = $this->request->post('/foobar');
68
69
        $this->assertFalse($pingResponse->isSuccess());
70
    }
71
72
    /**
73
     * Test function added to make sure that issue gh-54 is fixed.
74
     */
75
    public function testBasket()
76
    {
77
        $basket = [];
78
        $basket[0] = [
79
            'qty' => 1,
80
            'item_no' => 2,
81
            'item_name' => 'Test 1',
82
            'item_price' => 100,
83
            'vat_rate' => 0.25,
84
        ];
85
        $basket[1] = [
86
            'qty' => 1,
87
            'item_no' => 2,
88
            'item_name' => 'Test 2',
89
            'item_price' => 100,
90
            'vat_rate' => 0.25,
91
        ];
92
93
        $form = [
94
            'currency' => 'DKK',
95
            'order_id' => 1,
96
            'basket' => $basket,
97
        ];
98
99
        $query = $this->request->httpBuildQuery($form);
100
101
        $expected = 'currency=DKK&order_id=1&basket[][qty]=1&basket[][item_no]=2&basket[][item_name]=Test 1&basket[][item_price]=100&basket[][vat_rate]=0.25&basket[][qty]=1&basket[][item_no]=2&basket[][item_name]=Test 2&basket[][item_price]=100&basket[][vat_rate]=0.25';
102
103
        $this->assertEquals(urldecode($query), $expected);
104
    }
105
106
    public function testStandardHeaders()
107
    {
108
        $pingResponse = $this->request->get('/ping');
0 ignored issues
show
Unused Code introduced by
$pingResponse is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
109
        $this->assertContains('Accept: application/json', curl_getinfo($this->client->ch, CURLINFO_HEADER_OUT));
110
    }
111
112
    public function testAdditionalHeadersOnInit()
113
    {
114
        $extra_headers = array('SpecialVar: foo');
115
        $client = new Client(null, $extra_headers);
116
        $request = new Request($client);
117
        $pingResponse = $request->get('/ping');
0 ignored issues
show
Unused Code introduced by
$pingResponse is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
118
        $this->assertContains($extra_headers[0], curl_getinfo($client->ch, CURLINFO_HEADER_OUT));
119
    }
120
121
    public function testAdditionalHeadersAfterInit()
122
    {
123
        $extra_headers = array('NewVar: foo');
124
        $this->client->setHeaders($extra_headers);
125
        $request = new Request($this->client);
126
        $pingResponse = $request->get('/ping');
0 ignored issues
show
Unused Code introduced by
$pingResponse is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
127
        $this->assertContains($extra_headers[0], curl_getinfo($this->client->ch, CURLINFO_HEADER_OUT));
128
    }
129
}
130