HttpTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 65 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 39
loc 60
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testShouldBeInstantiated() 0 5 1
A testShouldReturnData() 7 7 1
A testShouldThrowException() 7 7 1
A libCurlReturnData() 12 12 1
A libCurlReturnsNothing() 13 13 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 Ip2c\Test\Unit;
4
5
use Ip2c\Http\Http;
6
use Prophecy\Argument;
7
8
class HttpTest extends \PHPUnit_Framework_TestCase
9
{
10
11
    /** @var Http */
12
    private $sut;
13
14
    public function testShouldBeInstantiated()
15
    {
16
        $this->sut = new Http($this->libCurlReturnData());
17
        $this->assertInstanceOf('Ip2c\Http\Http', $this->sut);
18
    }
19
20 View Code Duplication
    public function testShouldReturnData()
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...
21
    {
22
        $this->sut = new Http($this->libCurlReturnData());
23
        $returnedData = $this->sut->request('http://fake.request.mock');
24
25
        $this->assertTrue($returnedData == 'someData');
26
    }
27
28
    /**
29
     * @expectedException \Exception
30
     * @expectedExceptionCode 1
31
     * @expectedExceptionMessage error
32
     */
33 View Code Duplication
    public function testShouldThrowException()
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...
34
    {
35
        $this->sut = new Http($this->libCurlReturnsNothing());
36
        $returnedData = $this->sut->request('http://fake.request.mock');
37
38
        $this->assertTrue($returnedData == 'someData');
39
    }
40
41 View Code Duplication
    private function libCurlReturnData()
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...
42
    {
43
        $libCurl = $this->prophesize('Ip2c\Curl\LibCurl');
44
45
        $libCurl->init(Argument::any())->willReturn(null);
46
        $libCurl->setOpt(Argument::any(), Argument::any(), Argument::any())->willReturn(null);
47
        $libCurl->exec(Argument::any())->willReturn('someData');
48
        $libCurl->errno(Argument::any())->willReturn(0);
49
        $libCurl->close(Argument::any())->willReturn(null);
50
51
        return $libCurl->reveal();
52
    }
53
54 View Code Duplication
    private function libCurlReturnsNothing()
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...
55
    {
56
        $libCurl = $this->prophesize('Ip2c\Curl\LibCurl');
57
58
        $libCurl->init(Argument::any())->willReturn(null);
59
        $libCurl->setOpt(Argument::any(), Argument::any(), Argument::any())->willReturn(null);
60
        $libCurl->exec(Argument::any())->willReturn('');
61
        $libCurl->errno(Argument::any())->willReturn(1);
62
        $libCurl->error(Argument::any())->willReturn('error');
63
        $libCurl->close(Argument::any())->willReturn(null);
64
65
        return $libCurl->reveal();
66
    }
67
}
68