|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @project Promopult Integra client library |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace Promopult\Integra\Test; |
|
7
|
|
|
|
|
8
|
|
|
class ClientTest extends \PHPUnit\Framework\TestCase |
|
9
|
|
|
{ |
|
10
|
|
|
// ToDo: network error tests |
|
11
|
|
|
// ToDo: incorrect response tests |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @dataProvider methodDataProvider |
|
15
|
|
|
*/ |
|
16
|
15 |
|
public function testMethods(string $method, array $correctData, array $incorrectData): void |
|
17
|
|
|
{ |
|
18
|
15 |
|
$client = $this->createClient(); |
|
19
|
|
|
|
|
20
|
15 |
|
$correctResponse = $client->$method($correctData); |
|
21
|
|
|
|
|
22
|
15 |
|
$this->assertInstanceOf(\Promopult\Integra\Response::class, $correctResponse); |
|
23
|
|
|
|
|
24
|
|
|
// ToDo: check response data |
|
25
|
15 |
|
} |
|
26
|
|
|
|
|
27
|
15 |
|
private function createClient(): \Promopult\Integra\Client |
|
28
|
|
|
{ |
|
29
|
15 |
|
$mock = new \GuzzleHttp\Handler\MockHandler([ |
|
30
|
|
|
// Correct API response |
|
31
|
15 |
|
new \GuzzleHttp\Psr7\Response(200, [], json_encode([ |
|
32
|
15 |
|
'version' => 1, |
|
33
|
|
|
'notices' => [], |
|
34
|
|
|
'status' => [ |
|
35
|
|
|
'code' => 0, |
|
36
|
|
|
'message' => '' |
|
37
|
|
|
], |
|
38
|
|
|
'error' => false |
|
39
|
|
|
])), |
|
40
|
|
|
|
|
41
|
|
|
// ToDo: wrong response |
|
42
|
|
|
|
|
43
|
|
|
// ToDo: Network error |
|
44
|
|
|
//new \GuzzleHttp\Exception\RequestException("Error Communicating with Server", new \GuzzleHttp\Psr7\Request('GET', 'test')) |
|
45
|
|
|
]); |
|
46
|
|
|
|
|
47
|
15 |
|
$httpClient = new \GuzzleHttp\Client([ |
|
48
|
15 |
|
'handler' => \GuzzleHttp\HandlerStack::create($mock) |
|
49
|
|
|
]); |
|
50
|
|
|
|
|
51
|
15 |
|
return new \Promopult\Integra\Client( |
|
52
|
15 |
|
new \Promopult\Integra\Test\CredentialsMock, |
|
53
|
15 |
|
new \Promopult\Integra\Test\CryptMock, |
|
54
|
15 |
|
new \Http\Adapter\Guzzle6\Client($httpClient) |
|
55
|
|
|
); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
public function methodDataProvider(): array |
|
60
|
|
|
{ |
|
61
|
|
|
// methodName | correctParams | incorrectParams |
|
62
|
|
|
return [ |
|
63
|
|
|
['hello', [], []], |
|
64
|
|
|
['createUser', [], []], |
|
65
|
|
|
['cryptLogin', [], []], |
|
66
|
|
|
['archiveUser', [], []], |
|
67
|
|
|
['unarchiveUser', [], []], |
|
68
|
|
|
['doPayment', [], []], |
|
69
|
|
|
['confirmPayment', [], []], |
|
70
|
|
|
['declinePayment', [], []], |
|
71
|
|
|
['getUserData', [], []], |
|
72
|
|
|
['getUsersData', [], []], |
|
73
|
|
|
['getUserMessages', [], []], |
|
74
|
|
|
['getMessages', [], []], |
|
75
|
|
|
['getMessageTemplates', [], []], |
|
76
|
|
|
['readMessages', [], []], |
|
77
|
|
|
['changeUrl', [], []], |
|
78
|
|
|
]; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|