|
20 | 20 | use Geocoder\Provider\GeoIP2\GeoIP2; |
21 | 21 | use Geocoder\Provider\GeoIP2\GeoIP2Adapter; |
22 | 22 | use GeoIp2\Database\Reader; |
| 23 | +use GeoIp2\Exception\AuthenticationException; |
| 24 | +use GeoIp2\Exception\OutOfQueriesException; |
| 25 | +use Geocoder\Exception\InvalidCredentials; |
| 26 | +use Geocoder\Exception\QuotaExceeded; |
23 | 27 |
|
24 | 28 | /** |
25 | 29 | * @author Jens Wiese <jens@howtrueisfalse.de> |
@@ -223,6 +227,32 @@ public function testGeoIp2Encoding() |
223 | 227 | $this->assertEquals('Timișoara', $locality); |
224 | 228 | } |
225 | 229 |
|
| 230 | + /** |
| 231 | + * @dataProvider provideDataForTestingExceptions |
| 232 | + * |
| 233 | + * @param \Exception $original |
| 234 | + * @param string $replacementClass |
| 235 | + */ |
| 236 | + public function testExceptionConversion(\Exception $original, string $replacementClass) |
| 237 | + { |
| 238 | + $adapter = $this->getGeoIP2AdapterMock($original); |
| 239 | + $provider = new GeoIP2($adapter); |
| 240 | + |
| 241 | + self::expectException($replacementClass); |
| 242 | + self::expectExceptionMessage($original->getMessage()); |
| 243 | + self::expectExceptionCode($original->getCode()); |
| 244 | + |
| 245 | + $results = $provider->geocodeQuery(GeocodeQuery::create('74.200.247.59')); |
| 246 | + } |
| 247 | + |
| 248 | + public static function provideDataForTestingExceptions(): array |
| 249 | + { |
| 250 | + return [ |
| 251 | + [new AuthenticationException('Credentials are no good'), InvalidCredentials::class], |
| 252 | + [new OutOfQueriesException('You ran out'), QuotaExceeded::class], |
| 253 | + ]; |
| 254 | + } |
| 255 | + |
226 | 256 | /** |
227 | 257 | * @param mixed $returnValue |
228 | 258 | * |
|
0 commit comments