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