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 $postpay; |
19
|
|
|
|
20
|
|
|
protected $config = [ |
21
|
|
|
'merchant_id' => 'id', |
22
|
|
|
'secret_key' => 'sk', |
23
|
|
|
]; |
24
|
|
|
|
25
|
|
|
protected function setUp() |
26
|
|
|
{ |
27
|
|
|
$clientHandler = $this->createMock(ClientInterface::class); |
28
|
|
|
$clientHandler->method('send')->willReturnCallback( |
29
|
|
|
function (Request $request) { |
30
|
|
|
return new Response($request); |
31
|
|
|
} |
32
|
|
|
); |
33
|
|
|
$this->postpay = new Postpay($this->config); |
34
|
|
|
$this->postpay->setClientHandler($clientHandler); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testCredentialsRequired() |
38
|
|
|
{ |
39
|
|
|
$this->expectException(PostpayException::class); |
40
|
|
|
new Postpay(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testGetClient() |
44
|
|
|
{ |
45
|
|
|
self::assertInstanceOf(Client::class, $this->postpay->getClient()); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testCreateClientHandler() |
49
|
|
|
{ |
50
|
|
|
$postpay = $this->postpay; |
51
|
|
|
|
52
|
|
|
$clientHandler = $postpay::CreateClientHandler('curl'); |
53
|
|
|
self::assertInstanceOf(CurlClient::class, $clientHandler); |
54
|
|
|
|
55
|
|
|
$clientHandler = $postpay::CreateClientHandler('guzzle'); |
56
|
|
|
self::assertInstanceOf(GuzzleClient::class, $clientHandler); |
57
|
|
|
|
58
|
|
|
$this->expectException(InvalidArgumentException::class); |
59
|
|
|
$postpay::CreateClientHandler('invalid'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testGetLastResponse() |
63
|
|
|
{ |
64
|
|
|
$response = $this->postpay->get('/'); |
65
|
|
|
self::assertSame($response, $this->postpay->getLastResponse()); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testGet() |
69
|
|
|
{ |
70
|
|
|
$response = $this->postpay->get('/'); |
71
|
|
|
self::assertSame('GET', $response->getRequest()->getMethod()); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function testPost() |
75
|
|
|
{ |
76
|
|
|
$response = $this->postpay->post('/'); |
77
|
|
|
self::assertSame('POST', $response->getRequest()->getMethod()); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function testPut() |
81
|
|
|
{ |
82
|
|
|
$response = $this->postpay->put('/'); |
83
|
|
|
self::assertSame('PUT', $response->getRequest()->getMethod()); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function testPatch() |
87
|
|
|
{ |
88
|
|
|
$response = $this->postpay->patch('/'); |
89
|
|
|
self::assertSame('PATCH', $response->getRequest()->getMethod()); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function testDelete() |
93
|
|
|
{ |
94
|
|
|
$response = $this->postpay->delete('/'); |
95
|
|
|
self::assertSame('DELETE', $response->getRequest()->getMethod()); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function testQuery() |
99
|
|
|
{ |
100
|
|
|
$response = $this->postpay->query('{}'); |
101
|
|
|
self::assertSame('POST', $response->getRequest()->getMethod()); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|