Test Failed
Push — master ( 5ee2c0...7d1220 )
by Dani
01:37
created

PostpayTest::testGetLastResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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 testGetLastResponse()
39
    {
40
        $postpay = $this->mockClient();
41
        $response = $postpay->get('/');
42
        self::assertEquals($response, $postpay->getLastResponse());
43
    }
44
45
    public function testGet()
46
    {
47
        $response = $this->mockClient()->get('/');
48
        self::assertEquals('GET', $response->getRequest()->getMethod());
49
    }
50
51
    public function testPost()
52
    {
53
        $response = $this->mockClient()->post('/');
54
        self::assertEquals('POST', $response->getRequest()->getMethod());
55
    }
56
57
    public function testPut()
58
    {
59
        $response = $this->mockClient()->put('/');
60
        self::assertEquals('PUT', $response->getRequest()->getMethod());
61
    }
62
63
    public function testPatch()
64
    {
65
        $response = $this->mockClient()->patch('/');
66
        self::assertEquals('PATCH', $response->getRequest()->getMethod());
67
    }
68
69
    public function testDelete()
70
    {
71
        $response = $this->mockClient()->delete('/');
72
        self::assertEquals('DELETE', $response->getRequest()->getMethod());
73
    }
74
75
    public function testQuery()
76
    {
77
        $response = $this->mockClient()->query('{}');
78
        self::assertEquals('POST', $response->getRequest()->getMethod());
79
    }
80
}
81