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'); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
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.