Passed
Push — master ( e6b641...f65816 )
by Dani
01:36
created

tests/HttpClients/CurlClientTest.php (3 issues)

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 View Code Duplication
    public function testSend()
0 ignored issues
show
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);
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);
34
35
        self::assertSame(200, $response->getStatusCode());
36
    }
37
38 View Code Duplication
    public function testSendError()
0 ignored issues
show
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);
43
44
        $this->expectException(PostpayException::class);
45
        $response = $client->send(new Request('POST'));
0 ignored issues
show
$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