Passed
Push — master ( 5319ee...e6b641 )
by Dani
02:13
created

tests/PostpayTest.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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);
1 ignored issue
show
$clientHandler is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Postpay\HttpClients\ClientInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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