diff --git a/Tests/GeoIP2AdapterTest.php b/Tests/GeoIP2AdapterTest.php index f1ca60a..6ec1548 100644 --- a/Tests/GeoIP2AdapterTest.php +++ b/Tests/GeoIP2AdapterTest.php @@ -41,13 +41,13 @@ public function setUp(): void $this->adapter = new GeoIP2Adapter($this->getGeoIP2ProviderMock()); } - public function testGetName() + public function testGetName(): void { $expectedName = 'maxmind_geoip2'; $this->assertEquals($expectedName, $this->adapter->getName()); } - public function testGetContentMustBeCalledWithUrl() + public function testGetContentMustBeCalledWithUrl(): void { $this->expectException(\Geocoder\Exception\InvalidArgument::class); $this->expectExceptionMessage('must be called with a valid url. Got "127.0.0.1" instead.'); @@ -56,7 +56,7 @@ public function testGetContentMustBeCalledWithUrl() $this->adapter->getContent($url); } - public function testAddressPassedToReaderMustBeIpAddress() + public function testAddressPassedToReaderMustBeIpAddress(): void { $this->expectException(\Geocoder\Exception\InvalidArgument::class); $this->expectExceptionMessage('URL must contain a valid query-string (an IP address, 127.0.0.1 for instance)'); @@ -65,7 +65,10 @@ public function testAddressPassedToReaderMustBeIpAddress() $this->adapter->getContent($url); } - public static function provideDataForSwitchingRequestMethods() + /** + * @return array + */ + public static function provideDataForSwitchingRequestMethods(): array { return [ [GeoIP2Adapter::GEOIP2_MODEL_CITY], @@ -76,7 +79,7 @@ public static function provideDataForSwitchingRequestMethods() /** * @dataProvider provideDataForSwitchingRequestMethods */ - public function testIpAddressIsPassedCorrectToReader($geoIp2Model) + public function testIpAddressIsPassedCorrectToReader(string $geoIp2Model): void { $geoIp2Provider = $this->getGeoIP2ProviderMock(); $geoIp2Provider @@ -91,7 +94,7 @@ public function testIpAddressIsPassedCorrectToReader($geoIp2Model) $adapter->getContent('file://geoip?127.0.0.1'); } - public function testNotSupportedGeoIP2ModelLeadsToException() + public function testNotSupportedGeoIP2ModelLeadsToException(): void { $this->expectException(\Geocoder\Exception\UnsupportedOperation::class); $this->expectExceptionMessage('Model "unsupported_model" is not available.'); @@ -99,7 +102,7 @@ public function testNotSupportedGeoIP2ModelLeadsToException() new GeoIP2Adapter($this->getGeoIP2ProviderMock(), 'unsupported_model'); } - public function testReaderResponseIsJsonEncoded() + public function testReaderResponseIsJsonEncoded(): void { $cityModel = $this->getGeoIP2ModelMock(GeoIP2Adapter::GEOIP2_MODEL_CITY); @@ -135,6 +138,7 @@ protected function getGeoIP2ProviderMock() */ protected function getGeoIP2ModelMock($geoIP2Model) { + /** @var class-string $mockClass */ $mockClass = '\\GeoIp2\\Model\\'.ucfirst($geoIP2Model); $mock = $this->getMockBuilder($mockClass)->disableOriginalConstructor()->getMock(); diff --git a/Tests/GeoIP2Test.php b/Tests/GeoIP2Test.php index a96796f..3ce72e4 100644 --- a/Tests/GeoIP2Test.php +++ b/Tests/GeoIP2Test.php @@ -41,17 +41,17 @@ public function setUp(): void $this->provider = new GeoIP2($this->getGeoIP2AdapterMock()); } - protected function getCacheDir() + protected function getCacheDir(): string { return __DIR__.'/.cached_responses'; } - public function testGetName() + public function testGetName(): void { $this->assertEquals('geoip2', $this->provider->getName()); } - public function testQueryingReverseLeadsToException() + public function testQueryingReverseLeadsToException(): void { $this->expectException(\Geocoder\Exception\UnsupportedOperation::class); $this->expectExceptionMessage('The GeoIP2 provider is not able to do reverse geocoding.'); @@ -59,7 +59,7 @@ public function testQueryingReverseLeadsToException() $this->provider->reverseQuery(ReverseQuery::fromCoordinates(50, 9)); } - public function testGeocodeWithLocalhostIPv4() + public function testGeocodeWithLocalhostIPv4(): void { $results = $this->provider->geocodeQuery(GeocodeQuery::create('127.0.0.1')); @@ -73,7 +73,7 @@ public function testGeocodeWithLocalhostIPv4() $this->assertEquals('localhost', $result->getCountry()->getName()); } - public function testOnlyIpAddressesCouldBeResolved() + public function testOnlyIpAddressesCouldBeResolved(): void { $this->expectException(\Geocoder\Exception\UnsupportedOperation::class); $this->expectExceptionMessage('The GeoIP2 provider does not support street addresses, only IP addresses.'); @@ -84,7 +84,7 @@ public function testOnlyIpAddressesCouldBeResolved() /** * Provides data for geocode test. * - * @return array + * @return array>|float|int|string|null>|string>> */ public static function provideDataForRetrievingGeodata() { @@ -163,9 +163,9 @@ public static function provideDataForRetrievingGeodata() /** * @dataProvider provideDataForRetrievingGeodata * - * @param string $address + * @param array $expectedGeodata */ - public function testRetrievingGeodata($address, $adapterResponse, $expectedGeodata) + public function testRetrievingGeodata(string $address, string $adapterResponse, array $expectedGeodata): void { $adapter = $this->getGeoIP2AdapterMock($adapterResponse); $provider = new GeoIP2($adapter); @@ -212,7 +212,7 @@ public function testRetrievingGeodata($address, $adapterResponse, $expectedGeoda } } - public function testRetrievingGeodataNotExistingLocation() + public function testRetrievingGeodataNotExistingLocation(): void { $adapter = $this->getGeoIP2AdapterMock(''); $provider = new GeoIP2($adapter); @@ -222,7 +222,7 @@ public function testRetrievingGeodataNotExistingLocation() $this->assertEquals(0, $result->count()); } - public function testGeoIp2Encoding() + public function testGeoIp2Encoding(): void { $reader = new Reader(__DIR__.'/fixtures/GeoLite2-City.mmdb'); $adapter = new GeoIP2Adapter($reader); @@ -234,7 +234,7 @@ public function testGeoIp2Encoding() /** * @dataProvider provideDataForTestingExceptions */ - public function testExceptionConversion(\Exception $original, string $replacementClass) + public function testExceptionConversion(\Exception $original, string $replacementClass): void { $adapter = $this->getGeoIP2AdapterMock($original); $provider = new GeoIP2($adapter); @@ -246,6 +246,9 @@ public function testExceptionConversion(\Exception $original, string $replacemen $results = $provider->geocodeQuery(GeocodeQuery::create('74.200.247.59')); } + /** + * @return array> + */ public static function provideDataForTestingExceptions(): array { return [ @@ -255,6 +258,8 @@ public static function provideDataForTestingExceptions(): array } /** + * @param \Exception|string $returnValue + * * @return GeoIP2Adapter&MockObject */ private function getGeoIP2AdapterMock($returnValue = '')