20
20
21
21
class IP2LocationBinaryTest extends BaseTestCase
22
22
{
23
- private $ binaryFile ;
23
+ private string $ binaryFile ;
24
24
25
25
public function setUp (): void
26
26
{
27
27
// Download this BIN database from https://lite.ip2location.com/database/ip-country-region-city-latitude-longitude-zipcode
28
28
$ this ->binaryFile = __DIR__ .'/fixtures/IP2LOCATION-LITE-DB9.IPV6.BIN ' ;
29
29
}
30
30
31
- protected function getCacheDir ()
31
+ protected function getCacheDir (): string
32
32
{
33
33
return __DIR__ .'/.cached_responses ' ;
34
34
}
@@ -40,23 +40,26 @@ public static function setUpBeforeClass(): void
40
40
}
41
41
}
42
42
43
- public static function provideIps ()
43
+ /**
44
+ * @return array<string, string[]>
45
+ */
46
+ public static function provideIps (): array
44
47
{
45
48
return [
46
49
'8.8.8.8 ' => ['8.8.8.8 ' , 'Mountain View ' , 'United States ' ],
47
50
'123.123.123.123 ' => ['123.123.123.123 ' , 'Beijing ' , 'China ' ],
48
51
];
49
52
}
50
53
51
- public function testThrowIfNotExistBinaryFileGiven ()
54
+ public function testThrowIfNotExistBinaryFileGiven (): void
52
55
{
53
56
$ this ->expectException (\Geocoder \Exception \InvalidArgument::class);
54
57
$ this ->expectExceptionMessage ('Given IP2Location BIN file "NOT_EXIST.BIN" does not exist. ' );
55
58
56
59
new IP2LocationBinary ('NOT_EXIST.BIN ' );
57
60
}
58
61
59
- public function testLocationResultContainsExpectedFieldsForAnAmericanIp ()
62
+ public function testLocationResultContainsExpectedFieldsForAnAmericanIp (): void
60
63
{
61
64
$ provider = new IP2LocationBinary ($ this ->binaryFile );
62
65
$ results = $ provider ->geocodeQuery (GeocodeQuery::create ('8.8.8.8 ' ));
@@ -84,7 +87,7 @@ public function testLocationResultContainsExpectedFieldsForAnAmericanIp()
84
87
$ this ->assertNull ($ result ->getTimezone ());
85
88
}
86
89
87
- public function testLocationResultContainsExpectedFieldsForAChinaIp ()
90
+ public function testLocationResultContainsExpectedFieldsForAChinaIp (): void
88
91
{
89
92
$ provider = new IP2LocationBinary ($ this ->binaryFile );
90
93
$ results = $ provider ->geocodeQuery (GeocodeQuery::create ('123.123.123.123 ' ));
@@ -112,7 +115,7 @@ public function testLocationResultContainsExpectedFieldsForAChinaIp()
112
115
$ this ->assertNull ($ result ->getTimezone ());
113
116
}
114
117
115
- public function testGeocodeWithRealIPv6 ()
118
+ public function testGeocodeWithRealIPv6 (): void
116
119
{
117
120
$ provider = new IP2LocationBinary ($ this ->binaryFile );
118
121
$ results = $ provider ->geocodeQuery (GeocodeQuery::create ('2001:4860:4860::8888 ' ));
@@ -143,7 +146,7 @@ public function testGeocodeWithRealIPv6()
143
146
/**
144
147
* @dataProvider provideIps
145
148
*/
146
- public function testFindLocationByIp ($ ip , $ expectedCity , $ expectedCountry )
149
+ public function testFindLocationByIp (string $ ip , ? string $ expectedCity , ? string $ expectedCountry ): void
147
150
{
148
151
$ provider = new IP2LocationBinary ($ this ->binaryFile );
149
152
$ results = $ provider ->geocodeQuery (GeocodeQuery::create ($ ip ));
@@ -158,14 +161,14 @@ public function testFindLocationByIp($ip, $expectedCity, $expectedCountry)
158
161
$ this ->assertEquals ($ expectedCountry , $ result ->getCountry ()->getName ());
159
162
}
160
163
161
- public function testGetName ()
164
+ public function testGetName (): void
162
165
{
163
166
$ provider = new IP2LocationBinary ($ this ->binaryFile );
164
167
165
168
$ this ->assertEquals ('ip2location_binary ' , $ provider ->getName ());
166
169
}
167
170
168
- public function testThrowIfInvalidIpAddressGiven ()
171
+ public function testThrowIfInvalidIpAddressGiven (): void
169
172
{
170
173
$ this ->expectException (\Geocoder \Exception \UnsupportedOperation::class);
171
174
$ this ->expectExceptionMessage ('The IP2LocationBinary provider does not support street addresses. ' );
@@ -175,7 +178,7 @@ public function testThrowIfInvalidIpAddressGiven()
175
178
$ provider ->geocodeQuery (GeocodeQuery::create ('invalidIp ' ));
176
179
}
177
180
178
- public function testThrowOnReverseMethodUsage ()
181
+ public function testThrowOnReverseMethodUsage (): void
179
182
{
180
183
$ this ->expectException (\Geocoder \Exception \UnsupportedOperation::class);
181
184
$ this ->expectExceptionMessage ('The IP2LocationBinary is not able to do reverse geocoding. ' );
0 commit comments