Extracted logic to geolocate a visit, handling possible domain errors

This commit is contained in:
Alejandro Celaya
2022-09-18 18:44:01 +02:00
parent fe41e9d573
commit 83b7d5a5f1
11 changed files with 214 additions and 31 deletions

View File

@@ -9,6 +9,7 @@ use LogicException;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Exception\IpCannotBeLocatedException;
use Shlinkio\Shlink\Core\Exception\RuntimeException;
use Shlinkio\Shlink\Core\Visit\Model\UnlocatableIpType;
use Throwable;
class IpCannotBeLocatedExceptionTest extends TestCase
@@ -22,6 +23,7 @@ class IpCannotBeLocatedExceptionTest extends TestCase
self::assertEquals('Ignored visit with no IP address', $e->getMessage());
self::assertEquals(0, $e->getCode());
self::assertNull($e->getPrevious());
self::assertEquals(UnlocatableIpType::EMPTY_ADDRESS, $e->type);
}
/** @test */
@@ -33,6 +35,7 @@ class IpCannotBeLocatedExceptionTest extends TestCase
self::assertEquals('Ignored localhost address', $e->getMessage());
self::assertEquals(0, $e->getCode());
self::assertNull($e->getPrevious());
self::assertEquals(UnlocatableIpType::LOCALHOST, $e->type);
}
/**
@@ -47,6 +50,7 @@ class IpCannotBeLocatedExceptionTest extends TestCase
self::assertEquals('An error occurred while locating IP', $e->getMessage());
self::assertEquals($prev->getCode(), $e->getCode());
self::assertSame($prev, $e->getPrevious());
self::assertEquals(UnlocatableIpType::ERROR, $e->type);
}
public function provideErrors(): iterable