Completed
Push — master ( 58e43f...ab79d7 )
by Dani
02:22
created

tests/HttpClients/CurlClientTest.php (3 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\PostpayException;
7
use Postpay\Http\Request;
8
use Postpay\HttpClients\Curl;
9
use Postpay\HttpClients\CurlClient;
10
11
class CurlClientTest extends TestCase
12
{
13
    public function testSend()
14
    {
15
        $curl = $this->createMock(Curl::class);
16
        $curl->method('getInfo')->willReturn(200);
17
        $client = new CurlClient($curl);
1 ignored issue
show
$curl is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a null|object<Postpay\HttpClients\Curl>.

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...
18
        $response = $client->send(new Request('GET'));
19
20
        self::assertSame(200, $response->getStatusCode());
21
    }
22
23
    public function testSendRequest()
24
    {
25
        $request = $this->createMock(Request::class);
26
        $url = 'https://postman-echo.com/basic-auth';
27
        $request->method('getUrl')->willReturn($url);
28
        $request->method('getMethod')->willReturn('GET');
29
        $request->method('getHeaders')->willReturn([]);
30
        $request->method('getAuth')->willReturn(['postman', 'password']);
31
32
        $client = new CurlClient();
33
        $response = $client->send($request);
1 ignored issue
show
$request is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Postpay\Http\Request>.

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...
34
35
        self::assertSame(200, $response->getStatusCode());
36
    }
37
38
    public function testSendError()
39
    {
40
        $curl = $this->createMock(Curl::class);
41
        $curl->method('errno')->willReturn(1);
42
        $client = new CurlClient($curl);
1 ignored issue
show
$curl is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a null|object<Postpay\HttpClients\Curl>.

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...
43
44
        $this->expectException(PostpayException::class);
45
        $client->send(new Request('POST'));
46
    }
47
48 View Code Duplication
    public function testGetRequestHeaders()
49
    {
50
        $curl = new  CurlClient();
51
        $request = new Request('GET');
52
        $request->setHeaders(['test' => true]);
53
        $headers = $curl->getRequestHeaders($request);
54
55
        self::assertEquals('test: 1', $headers[0]);
56
    }
57
}
58