1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Postpay\Tests; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use Postpay\Http\Request; |
7
|
|
|
use Postpay\Http\Response; |
8
|
|
|
use Postpay\HttpClients\Client; |
9
|
|
|
use Postpay\HttpClients\ClientInterface; |
10
|
|
|
use Postpay\Postpay; |
11
|
|
|
|
12
|
|
|
class PostpayTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
protected $config = [ |
15
|
|
|
'merchant_id' => 'id', |
16
|
|
|
'secret_key' => 'sk', |
17
|
|
|
]; |
18
|
|
|
|
19
|
|
|
protected function mockClient() |
20
|
|
|
{ |
21
|
|
|
$client = $this->createMock(ClientInterface::class); |
22
|
|
|
|
23
|
|
|
$client->method('send')->willReturnCallback( |
24
|
|
|
function (Request $request) { |
25
|
|
|
return new Response($request); |
26
|
|
|
} |
27
|
|
|
); |
28
|
|
|
$config = array_merge($this->config, ['client' => $client]); |
29
|
|
|
return new Postpay($config); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testGetClient() |
33
|
|
|
{ |
34
|
|
|
$postpay = new Postpay($this->config); |
35
|
|
|
self::assertInstanceOf(Client::class, $postpay->getClient()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testGet() |
39
|
|
|
{ |
40
|
|
|
$response = $this->mockClient()->get('/'); |
41
|
|
|
self::assertEquals('GET', $response->getRequest()->getMethod()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testPost() |
45
|
|
|
{ |
46
|
|
|
$response = $this->mockClient()->post('/'); |
47
|
|
|
self::assertEquals('POST', $response->getRequest()->getMethod()); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testPut() |
51
|
|
|
{ |
52
|
|
|
$response = $this->mockClient()->put('/'); |
53
|
|
|
self::assertEquals('PUT', $response->getRequest()->getMethod()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testPatch() |
57
|
|
|
{ |
58
|
|
|
$response = $this->mockClient()->patch('/'); |
59
|
|
|
self::assertEquals('PATCH', $response->getRequest()->getMethod()); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testDelete() |
63
|
|
|
{ |
64
|
|
|
$response = $this->mockClient()->delete('/'); |
65
|
|
|
self::assertEquals('DELETE', $response->getRequest()->getMethod()); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testQuery() |
69
|
|
|
{ |
70
|
|
|
$response = $this->mockClient()->query('{}'); |
71
|
|
|
self::assertEquals('POST', $response->getRequest()->getMethod()); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|