CurlClientTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 57.45 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 27
loc 47
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testSend() 9 9 1
A testSendRequest() 0 14 1
A testSendError() 9 9 1
A testGetRequestHeaders() 9 9 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 mongkok
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
Duplication introduced by mongkok
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
        $client->send(new Request('POST'));
46
    }
47
48 View Code Duplication
    public function testGetRequestHeaders()
0 ignored issues
show
Duplication introduced by mongkok
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...
49
    {
50
        $curl = new  CurlClient();
51
        $request = new Request('GET');
52
        $request->setHeaders(['test' => true]);
53
        $headers = $curl->getRequestHeaders($request);
54
55
        self::assertSame('test: 1', $headers[0]);
56
    }
57
}
58