ResponseTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 49
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testShouldBeInstantiated() 0 4 1
A testShouldReturnData() 0 10 1
A responses() 0 8 1
A testShouldRaiseException() 0 4 1
1
<?php
2
3
namespace Ip2c\Test\Unit;
4
5
use Ip2c\Http\Response;
6
7
class ResponseTest extends \PHPUnit_Framework_TestCase
8
{
9
10
    /** @var Response */
11
    private $sut;
12
13
    public function setUp()
14
    {
15
        $this->sut = new Response('1;ES;ESP;Spain');
16
    }
17
18
    public function testShouldBeInstantiated()
19
    {
20
        $this->assertInstanceOf('Ip2c\Http\Response', $this->sut);
21
    }
22
23
    /** @dataProvider responses */
24
    public function testShouldReturnData($response, $status, $iso2, $iso3, $name)
25
    {
26
27
        $responseObj = new Response($response);
28
29
        $this->assertEquals($responseObj->status(), $status);
30
        $this->assertEquals($responseObj->iso2(), $iso2);
31
        $this->assertEquals($responseObj->iso3(), $iso3);
32
        $this->assertEquals($responseObj->name(), $name);
33
    }
34
35
    public function responses()
36
    {
37
        return array(
38
            array('1;ES;ESP;Spain', 1, 'ES', 'ESP', 'Spain'),
39
            array('2;AA;AAA;A Letter', 2, 'AA', 'AAA', 'A Letter'),
40
            array('3;BB;BBB;B Letter', 3, 'BB', 'BBB', 'B Letter')
41
        );
42
    }
43
44
    /**
45
     * @expectedException \Exception
46
     * @expectedExceptionCode 1
47
     * @expectedExceptionMessage Inconsistent response from Ip2c
48
     */
49
    public function testShouldRaiseException()
50
    {
51
        $responseObj = new Response('1;ES;ESP');
0 ignored issues
show
Unused Code introduced by
$responseObj 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...
52
    }
53
54
55
}
56