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

tests/HttpClients/ClientTest.php (2 issues)

mismatching argument types.

Documentation Minor

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\HttpClients;
4
5
use PHPUnit\Framework\TestCase;
6
use Postpay\Exceptions\RESTfulException;
7
use Postpay\Http\Request;
8
use Postpay\Http\Response;
9
use Postpay\HttpClients\Client;
10
use Postpay\HttpClients\ClientInterface;
11
use Postpay\HttpClients\GuzzleClient;
12
13
class ClientTest extends TestCase
14
{
15
    public function testGetClientHandler()
16
    {
17
        $client = new Client();
18
19
        self::assertInstanceOf(
20
            ClientInterface::class,
21
            $client->getClientHandler()
22
        );
23
    }
24
25
    public function testSetClientHandler()
26
    {
27
        $client = new Client();
28
        $clientHandler = new GuzzleClient();
29
        $client->setClientHandler($clientHandler);
30
31
        self::assertEquals($clientHandler, $client->getClientHandler());
32
    }
33
34
    public function testRequest()
35
    {
36
        $clientHandler = $this->createMock(ClientInterface::class);
37
38
        $clientHandler->method('send')->willReturnCallback(
39
            function (Request $request) {
40
                return new Response($request, 200);
41
            }
42
        );
43
        $client = new Client($clientHandler);
1 ignored issue
show
$clientHandler is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a null|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...
44
45
        $response = $client->request(new Request('GET'));
46
        self::assertSame(200, $response->getStatusCode());
47
    }
48
49
    public function testRequestError()
50
    {
51
        $clientHandler = $this->createMock(ClientInterface::class);
52
53
        $clientHandler->method('send')->willReturnCallback(
54
            function (Request $request) {
55
                $body = json_encode([RESTfulException::ERROR_KEY => true]);
56
                return new Response($request, 400, [], $body);
57
            }
58
        );
59
        $client = new Client($clientHandler);
1 ignored issue
show
$clientHandler is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a null|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...
60
61
        $this->expectException(RESTfulException::class);
62
        $client->request(new Request('GET'));
63
    }
64
}
65