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

CurlClientTest::testSendRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 1
nc 1
nop 0
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 View Code Duplication
    public function testSend()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
    {
15
        $curl = $this->createMock(Curl::class);
16
        $curl->method('getInfo')->willReturn(200);
17
        $client = new CurlClient($curl);
1 ignored issue
show
Documentation introduced by
$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
Documentation introduced by
$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 View Code Duplication
    public function testSendError()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
    {
40
        $curl = $this->createMock(Curl::class);
41
        $curl->method('errno')->willReturn(1);
42
        $client = new CurlClient($curl);
1 ignored issue
show
Documentation introduced by
$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
        $response = $client->send(new Request('POST'));
0 ignored issues
show
Unused Code introduced by
$response is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
46
    }
47
48
    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