2020
2121class IP2LocationBinaryTest extends BaseTestCase
2222{
23- private $ binaryFile ;
23+ private string $ binaryFile ;
2424
2525 public function setUp (): void
2626 {
2727 // Download this BIN database from https://lite.ip2location.com/database/ip-country-region-city-latitude-longitude-zipcode
2828 $ this ->binaryFile = __DIR__ .'/fixtures/IP2LOCATION-LITE-DB9.IPV6.BIN ' ;
2929 }
3030
31- protected function getCacheDir ()
31+ protected function getCacheDir (): string
3232 {
3333 return __DIR__ .'/.cached_responses ' ;
3434 }
@@ -40,23 +40,26 @@ public static function setUpBeforeClass(): void
4040 }
4141 }
4242
43- public static function provideIps ()
43+ /**
44+ * @return array<string, string[]>
45+ */
46+ public static function provideIps (): array
4447 {
4548 return [
4649 '8.8.8.8 ' => ['8.8.8.8 ' , 'Mountain View ' , 'United States ' ],
4750 '123.123.123.123 ' => ['123.123.123.123 ' , 'Beijing ' , 'China ' ],
4851 ];
4952 }
5053
51- public function testThrowIfNotExistBinaryFileGiven ()
54+ public function testThrowIfNotExistBinaryFileGiven (): void
5255 {
5356 $ this ->expectException (\Geocoder \Exception \InvalidArgument::class);
5457 $ this ->expectExceptionMessage ('Given IP2Location BIN file "NOT_EXIST.BIN" does not exist. ' );
5558
5659 new IP2LocationBinary ('NOT_EXIST.BIN ' );
5760 }
5861
59- public function testLocationResultContainsExpectedFieldsForAnAmericanIp ()
62+ public function testLocationResultContainsExpectedFieldsForAnAmericanIp (): void
6063 {
6164 $ provider = new IP2LocationBinary ($ this ->binaryFile );
6265 $ results = $ provider ->geocodeQuery (GeocodeQuery::create ('8.8.8.8 ' ));
@@ -84,7 +87,7 @@ public function testLocationResultContainsExpectedFieldsForAnAmericanIp()
8487 $ this ->assertNull ($ result ->getTimezone ());
8588 }
8689
87- public function testLocationResultContainsExpectedFieldsForAChinaIp ()
90+ public function testLocationResultContainsExpectedFieldsForAChinaIp (): void
8891 {
8992 $ provider = new IP2LocationBinary ($ this ->binaryFile );
9093 $ results = $ provider ->geocodeQuery (GeocodeQuery::create ('123.123.123.123 ' ));
@@ -112,7 +115,7 @@ public function testLocationResultContainsExpectedFieldsForAChinaIp()
112115 $ this ->assertNull ($ result ->getTimezone ());
113116 }
114117
115- public function testGeocodeWithRealIPv6 ()
118+ public function testGeocodeWithRealIPv6 (): void
116119 {
117120 $ provider = new IP2LocationBinary ($ this ->binaryFile );
118121 $ results = $ provider ->geocodeQuery (GeocodeQuery::create ('2001:4860:4860::8888 ' ));
@@ -143,7 +146,7 @@ public function testGeocodeWithRealIPv6()
143146 /**
144147 * @dataProvider provideIps
145148 */
146- public function testFindLocationByIp ($ ip , $ expectedCity , $ expectedCountry )
149+ public function testFindLocationByIp (string $ ip , ? string $ expectedCity , ? string $ expectedCountry ): void
147150 {
148151 $ provider = new IP2LocationBinary ($ this ->binaryFile );
149152 $ results = $ provider ->geocodeQuery (GeocodeQuery::create ($ ip ));
@@ -158,14 +161,14 @@ public function testFindLocationByIp($ip, $expectedCity, $expectedCountry)
158161 $ this ->assertEquals ($ expectedCountry , $ result ->getCountry ()->getName ());
159162 }
160163
161- public function testGetName ()
164+ public function testGetName (): void
162165 {
163166 $ provider = new IP2LocationBinary ($ this ->binaryFile );
164167
165168 $ this ->assertEquals ('ip2location_binary ' , $ provider ->getName ());
166169 }
167170
168- public function testThrowIfInvalidIpAddressGiven ()
171+ public function testThrowIfInvalidIpAddressGiven (): void
169172 {
170173 $ this ->expectException (\Geocoder \Exception \UnsupportedOperation::class);
171174 $ this ->expectExceptionMessage ('The IP2LocationBinary provider does not support street addresses. ' );
@@ -175,7 +178,7 @@ public function testThrowIfInvalidIpAddressGiven()
175178 $ provider ->geocodeQuery (GeocodeQuery::create ('invalidIp ' ));
176179 }
177180
178- public function testThrowOnReverseMethodUsage ()
181+ public function testThrowOnReverseMethodUsage (): void
179182 {
180183 $ this ->expectException (\Geocoder \Exception \UnsupportedOperation::class);
181184 $ this ->expectExceptionMessage ('The IP2LocationBinary is not able to do reverse geocoding. ' );
0 commit comments