|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Postpay\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use InvalidArgumentException; |
|
6
|
|
|
use PHPUnit\Framework\TestCase; |
|
7
|
|
|
use Postpay\Exceptions\PostpayException; |
|
8
|
|
|
use Postpay\Http\Request; |
|
9
|
|
|
use Postpay\Http\Response; |
|
10
|
|
|
use Postpay\HttpClients\Client; |
|
11
|
|
|
use Postpay\HttpClients\ClientInterface; |
|
12
|
|
|
use Postpay\HttpClients\CurlClient; |
|
13
|
|
|
use Postpay\HttpClients\GuzzleClient; |
|
14
|
|
|
use Postpay\Postpay; |
|
15
|
|
|
|
|
16
|
|
|
class PostpayTest extends TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
protected $config = [ |
|
19
|
|
|
'merchant_id' => 'id', |
|
20
|
|
|
'secret_key' => 'sk', |
|
21
|
|
|
]; |
|
22
|
|
|
|
|
23
|
|
|
public function setUp() |
|
24
|
|
|
{ |
|
25
|
|
|
$clientHandler = $this->createMock(ClientInterface::class); |
|
26
|
|
|
$clientHandler->method('send')->willReturnCallback( |
|
27
|
|
|
function (Request $request) { |
|
28
|
|
|
return new Response($request); |
|
29
|
|
|
} |
|
30
|
|
|
); |
|
31
|
|
|
$this->postpay = new Postpay($this->config); |
|
|
|
|
|
|
32
|
|
|
$this->postpay->setClientHandler($clientHandler); |
|
|
|
|
|
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function testCredentialsRequired() |
|
36
|
|
|
{ |
|
37
|
|
|
$this->expectException(PostpayException::class); |
|
38
|
|
|
new Postpay(); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function testGetClient() |
|
42
|
|
|
{ |
|
43
|
|
|
self::assertInstanceOf(Client::class, $this->postpay->getClient()); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function testCreateClientHandler() |
|
47
|
|
|
{ |
|
48
|
|
|
$clientHandler = $this->postpay::CreateClientHandler('curl'); |
|
49
|
|
|
self::assertInstanceOf(CurlClient::class, $clientHandler); |
|
50
|
|
|
|
|
51
|
|
|
$clientHandler = $this->postpay::CreateClientHandler('guzzle'); |
|
52
|
|
|
self::assertInstanceOf(GuzzleClient::class, $clientHandler); |
|
53
|
|
|
|
|
54
|
|
|
$this->expectException(InvalidArgumentException::class); |
|
55
|
|
|
$this->postpay::CreateClientHandler('invalid'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function testGetLastResponse() |
|
59
|
|
|
{ |
|
60
|
|
|
$response = $this->postpay->get('/'); |
|
61
|
|
|
self::assertEquals($response, $this->postpay->getLastResponse()); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function testGet() |
|
65
|
|
|
{ |
|
66
|
|
|
$response = $this->postpay->get('/'); |
|
67
|
|
|
self::assertEquals('GET', $response->getRequest()->getMethod()); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function testPost() |
|
71
|
|
|
{ |
|
72
|
|
|
$response = $this->postpay->post('/'); |
|
73
|
|
|
self::assertEquals('POST', $response->getRequest()->getMethod()); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function testPut() |
|
77
|
|
|
{ |
|
78
|
|
|
$response = $this->postpay->put('/'); |
|
79
|
|
|
self::assertEquals('PUT', $response->getRequest()->getMethod()); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function testPatch() |
|
83
|
|
|
{ |
|
84
|
|
|
$response = $this->postpay->patch('/'); |
|
85
|
|
|
self::assertEquals('PATCH', $response->getRequest()->getMethod()); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function testDelete() |
|
89
|
|
|
{ |
|
90
|
|
|
$response = $this->postpay->delete('/'); |
|
91
|
|
|
self::assertEquals('DELETE', $response->getRequest()->getMethod()); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function testQuery() |
|
95
|
|
|
{ |
|
96
|
|
|
$response = $this->postpay->query('{}'); |
|
97
|
|
|
self::assertEquals('POST', $response->getRequest()->getMethod()); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: