Total Complexity | 3 |
Total Lines | 54 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
14 | class IpApiLocationResolverTest extends TestCase |
||
15 | { |
||
16 | /** |
||
17 | * @var IpApiLocationResolver |
||
18 | */ |
||
19 | protected $ipResolver; |
||
20 | /** |
||
21 | * @var ObjectProphecy |
||
22 | */ |
||
23 | protected $client; |
||
24 | |||
25 | public function setUp() |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * @test |
||
33 | */ |
||
34 | public function correctIpReturnsDecodedInfo() |
||
35 | { |
||
36 | $actual = [ |
||
37 | 'countryCode' => 'bar', |
||
38 | 'lat' => 5, |
||
39 | 'lon' => 10, |
||
40 | ]; |
||
41 | $expected = [ |
||
42 | 'country_code' => 'bar', |
||
43 | 'country_name' => '', |
||
44 | 'region_name' => '', |
||
45 | 'city' => '', |
||
46 | 'latitude' => 5, |
||
47 | 'longitude' => 10, |
||
48 | 'time_zone' => '', |
||
49 | ]; |
||
50 | $response = new Response(); |
||
51 | $response->getBody()->write(json_encode($actual)); |
||
52 | $response->getBody()->rewind(); |
||
53 | |||
54 | $this->client->get('http://ip-api.com/json/1.2.3.4')->willReturn($response) |
||
55 | ->shouldBeCalledOnce(); |
||
56 | $this->assertEquals($expected, $this->ipResolver->resolveIpLocation('1.2.3.4')); |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * @test |
||
61 | * @expectedException \Shlinkio\Shlink\Common\Exception\WrongIpException |
||
62 | */ |
||
63 | public function guzzleExceptionThrowsShlinkException() |
||
68 | } |
||
69 | } |
||
70 |