|
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
|
|
|
protected $request; |
|
12
|
|
|
|
|
13
|
|
|
public function setUp() |
|
14
|
|
|
{ |
|
15
|
|
|
$client = new Client(); |
|
16
|
|
|
$this->request = new Request($client); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public function testResponseInstance() |
|
20
|
|
|
{ |
|
21
|
|
|
$pingResponse = $this->request->get('/ping'); |
|
22
|
|
|
|
|
23
|
|
|
$this->assertTrue(($pingResponse instanceof Response)); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function testBadAuthentication() |
|
27
|
|
|
{ |
|
28
|
|
|
$client = new Client(':foo'); |
|
29
|
|
|
$request = new Request($client); |
|
30
|
|
|
|
|
31
|
|
|
$response = $request->get('/ping'); |
|
32
|
|
|
|
|
33
|
|
|
$this->assertEquals(401, $response->httpStatus()); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function testSuccessfulGetResponse() |
|
37
|
|
|
{ |
|
38
|
|
|
$pingResponse = $this->request->get('/ping'); |
|
39
|
|
|
|
|
40
|
|
|
$this->assertTrue($pingResponse->isSuccess()); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function testFailedGetResponse() |
|
44
|
|
|
{ |
|
45
|
|
|
$pingResponse = $this->request->get('/foobar'); |
|
46
|
|
|
|
|
47
|
|
|
$this->assertFalse($pingResponse->isSuccess()); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testSuccesfulPostResponse() |
|
51
|
|
|
{ |
|
52
|
|
|
$pingResponse = $this->request->post('/ping'); |
|
53
|
|
|
|
|
54
|
|
|
$this->assertTrue($pingResponse->isSuccess()); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function testFailedPostResponse() |
|
58
|
|
|
{ |
|
59
|
|
|
$pingResponse = $this->request->post('/foobar'); |
|
60
|
|
|
|
|
61
|
|
|
$this->assertFalse($pingResponse->isSuccess()); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function testBasket() |
|
65
|
|
|
{ |
|
66
|
|
|
$basket = []; |
|
67
|
|
|
$basket[0] = [ |
|
68
|
|
|
'qty' => 1, |
|
69
|
|
|
'item_no' => 2, |
|
70
|
|
|
'item_name' => 'Test 1', |
|
71
|
|
|
'item_price' => 100, |
|
72
|
|
|
'vat_rate' => 0.25, |
|
73
|
|
|
]; |
|
74
|
|
|
$basket[1] = [ |
|
75
|
|
|
'qty' => 1, |
|
76
|
|
|
'item_no' => 2, |
|
77
|
|
|
'item_name' => 'Test 2', |
|
78
|
|
|
'item_price' => 100, |
|
79
|
|
|
'vat_rate' => 0.25, |
|
80
|
|
|
]; |
|
81
|
|
|
|
|
82
|
|
|
$form = [ |
|
83
|
|
|
'currency' => 'DKK', |
|
84
|
|
|
'order_id' => 1, |
|
85
|
|
|
'basket' => $basket, |
|
86
|
|
|
]; |
|
87
|
|
|
|
|
88
|
|
|
$query = $this->crpost($form); |
|
|
|
|
|
|
89
|
|
|
print_r(urldecode($query)); |
|
90
|
|
|
|
|
91
|
|
|
$payment = $this->request->post('/payments', $form); |
|
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Remove keys of multi array to post |
|
97
|
|
|
* |
|
98
|
|
|
* @param array $a |
|
99
|
|
|
* @param string $b |
|
100
|
|
|
* @param int $c |
|
101
|
|
|
* @return bool|string |
|
102
|
|
|
*/ |
|
103
|
|
|
public function handleArrayData($a, $b = '', $c=0) |
|
|
|
|
|
|
104
|
|
|
{ |
|
105
|
|
|
if (!is_array($a)) { |
|
106
|
|
|
return false; |
|
107
|
|
|
} |
|
108
|
|
|
foreach ((array)$a as $k => $v) { |
|
109
|
|
|
if ($c) { |
|
110
|
|
|
if(is_numeric($k)) { |
|
|
|
|
|
|
111
|
|
|
$k = $b."[]"; |
|
112
|
|
|
} else { |
|
113
|
|
|
$k = $b."[$k]"; |
|
114
|
|
|
} |
|
115
|
|
|
} else { |
|
116
|
|
|
if (is_int($k)) { |
|
117
|
|
|
$k = $b.$k; |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
if (is_array($v)||is_object($v)) { |
|
122
|
|
|
$r[] = $this->crpost($v,$k,1); |
|
|
|
|
|
|
123
|
|
|
continue; |
|
124
|
|
|
} |
|
125
|
|
|
$r[] = urlencode($k)."=".urlencode($v); |
|
|
|
|
|
|
126
|
|
|
} |
|
127
|
|
|
return implode("&", $r); |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.