diff --git a/module/Common/config/dependencies.config.php b/module/Common/config/dependencies.config.php index a43d1e5c..b03520a3 100644 --- a/module/Common/config/dependencies.config.php +++ b/module/Common/config/dependencies.config.php @@ -37,6 +37,7 @@ return [ IpGeolocation\IpApiLocationResolver::class => ConfigAbstractFactory::class, IpGeolocation\GeoLite2LocationResolver::class => ConfigAbstractFactory::class, + IpGeolocation\EmptyIpLocationResolver::class => InvokableFactory::class, IpGeolocation\ChainIpLocationResolver::class => ConfigAbstractFactory::class, IpGeolocation\GeoLite2\GeoLite2Options::class => ConfigAbstractFactory::class, IpGeolocation\GeoLite2\DbUpdater::class => ConfigAbstractFactory::class, @@ -83,6 +84,7 @@ return [ IpGeolocation\ChainIpLocationResolver::class => [ IpGeolocation\GeoLite2LocationResolver::class, IpGeolocation\IpApiLocationResolver::class, + IpGeolocation\EmptyIpLocationResolver::class, ], IpGeolocation\GeoLite2\GeoLite2Options::class => ['config.geolite2'], IpGeolocation\GeoLite2\DbUpdater::class => [ diff --git a/module/Common/src/IpGeolocation/ChainIpLocationResolver.php b/module/Common/src/IpGeolocation/ChainIpLocationResolver.php index 8528c89e..2b48a70f 100644 --- a/module/Common/src/IpGeolocation/ChainIpLocationResolver.php +++ b/module/Common/src/IpGeolocation/ChainIpLocationResolver.php @@ -18,8 +18,6 @@ class ChainIpLocationResolver implements IpLocationResolverInterface } /** - * @param string $ipAddress - * @return array * @throws WrongIpException */ public function resolveIpLocation(string $ipAddress): array diff --git a/module/Common/src/IpGeolocation/EmptyIpLocationResolver.php b/module/Common/src/IpGeolocation/EmptyIpLocationResolver.php new file mode 100644 index 00000000..c9e1f4a4 --- /dev/null +++ b/module/Common/src/IpGeolocation/EmptyIpLocationResolver.php @@ -0,0 +1,25 @@ + '', + 'country_name' => '', + 'region_name' => '', + 'city' => '', + 'latitude' => '', + 'longitude' => '', + 'time_zone' => '', + ]; + } +} diff --git a/module/Common/src/IpGeolocation/GeoLite2LocationResolver.php b/module/Common/src/IpGeolocation/GeoLite2LocationResolver.php index 0bced338..24607ff5 100644 --- a/module/Common/src/IpGeolocation/GeoLite2LocationResolver.php +++ b/module/Common/src/IpGeolocation/GeoLite2LocationResolver.php @@ -24,8 +24,6 @@ class GeoLite2LocationResolver implements IpLocationResolverInterface } /** - * @param string $ipAddress - * @return array * @throws WrongIpException */ public function resolveIpLocation(string $ipAddress): array diff --git a/module/Common/src/IpGeolocation/IpApiLocationResolver.php b/module/Common/src/IpGeolocation/IpApiLocationResolver.php index fe6680a8..8ea8be4b 100644 --- a/module/Common/src/IpGeolocation/IpApiLocationResolver.php +++ b/module/Common/src/IpGeolocation/IpApiLocationResolver.php @@ -25,8 +25,6 @@ class IpApiLocationResolver implements IpLocationResolverInterface } /** - * @param string $ipAddress - * @return array * @throws WrongIpException */ public function resolveIpLocation(string $ipAddress): array diff --git a/module/Common/src/IpGeolocation/IpLocationResolverInterface.php b/module/Common/src/IpGeolocation/IpLocationResolverInterface.php index f9e41572..6017db61 100644 --- a/module/Common/src/IpGeolocation/IpLocationResolverInterface.php +++ b/module/Common/src/IpGeolocation/IpLocationResolverInterface.php @@ -8,8 +8,6 @@ use Shlinkio\Shlink\Common\Exception\WrongIpException; interface IpLocationResolverInterface { /** - * @param string $ipAddress - * @return array * @throws WrongIpException */ public function resolveIpLocation(string $ipAddress): array; diff --git a/module/Common/test/IpGeolocation/EmptyIpLocationResolverTest.php b/module/Common/test/IpGeolocation/EmptyIpLocationResolverTest.php new file mode 100644 index 00000000..c394f85e --- /dev/null +++ b/module/Common/test/IpGeolocation/EmptyIpLocationResolverTest.php @@ -0,0 +1,51 @@ + '', + 'country_name' => '', + 'region_name' => '', + 'city' => '', + 'latitude' => '', + 'longitude' => '', + 'time_zone' => '', + ]; + + /** + * @var EmptyIpLocationResolver + */ + private $resolver; + + public function setUp() + { + $this->resolver = new EmptyIpLocationResolver(); + } + + /** + * @test + * @dataProvider provideEmptyResponses + */ + public function alwaysReturnsAnEmptyResponse(array $expected, string $ipAddress) + { + $this->assertEquals($expected, $this->resolver->resolveIpLocation($ipAddress)); + } + + public function provideEmptyResponses(): array + { + return map(range(0, 5), function () { + return [self::EMPTY_RESP, $this->generateRandomString(10)]; + }); + } +}