2019-04-14 11:10:10 +03:00
|
|
|
<?php
|
2019-10-05 18:26:10 +03:00
|
|
|
|
2019-04-14 11:10:10 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioTest\Shlink\CLI\Exception;
|
|
|
|
|
|
|
|
use Exception;
|
2023-02-09 22:42:18 +03:00
|
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
|
|
use PHPUnit\Framework\Attributes\Test;
|
2019-04-14 11:10:10 +03:00
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use RuntimeException;
|
|
|
|
use Shlinkio\Shlink\CLI\Exception\GeolocationDbUpdateFailedException;
|
|
|
|
use Throwable;
|
|
|
|
|
|
|
|
class GeolocationDbUpdateFailedExceptionTest extends TestCase
|
|
|
|
{
|
2023-02-09 22:42:18 +03:00
|
|
|
#[Test, DataProvider('providePrev')]
|
2021-02-06 23:37:58 +03:00
|
|
|
public function withOlderDbBuildsException(?Throwable $prev): void
|
2019-04-14 11:10:10 +03:00
|
|
|
{
|
2021-02-06 23:37:58 +03:00
|
|
|
$e = GeolocationDbUpdateFailedException::withOlderDb($prev);
|
2019-04-14 11:10:10 +03:00
|
|
|
|
2021-02-06 23:37:58 +03:00
|
|
|
self::assertTrue($e->olderDbExists());
|
2020-10-04 01:35:14 +03:00
|
|
|
self::assertEquals(
|
2021-02-06 23:37:58 +03:00
|
|
|
'An error occurred while updating geolocation database, but an older DB is already present.',
|
2020-01-01 22:48:31 +03:00
|
|
|
$e->getMessage(),
|
2019-04-14 11:10:10 +03:00
|
|
|
);
|
2020-10-04 01:35:14 +03:00
|
|
|
self::assertEquals(0, $e->getCode());
|
|
|
|
self::assertEquals($prev, $e->getPrevious());
|
2019-04-14 11:10:10 +03:00
|
|
|
}
|
|
|
|
|
2023-02-09 22:42:18 +03:00
|
|
|
#[Test, DataProvider('providePrev')]
|
2021-02-06 23:37:58 +03:00
|
|
|
public function withoutOlderDbBuildsException(?Throwable $prev): void
|
2019-04-14 11:10:10 +03:00
|
|
|
{
|
2021-02-06 23:37:58 +03:00
|
|
|
$e = GeolocationDbUpdateFailedException::withoutOlderDb($prev);
|
|
|
|
|
|
|
|
self::assertFalse($e->olderDbExists());
|
|
|
|
self::assertEquals(
|
|
|
|
'An error occurred while updating geolocation database, and an older version could not be found.',
|
|
|
|
$e->getMessage(),
|
|
|
|
);
|
|
|
|
self::assertEquals(0, $e->getCode());
|
|
|
|
self::assertEquals($prev, $e->getPrevious());
|
|
|
|
}
|
|
|
|
|
2023-02-09 11:32:38 +03:00
|
|
|
public static function providePrev(): iterable
|
2021-02-06 23:37:58 +03:00
|
|
|
{
|
|
|
|
yield 'no prev' => [null];
|
|
|
|
yield 'RuntimeException' => [new RuntimeException('prev')];
|
|
|
|
yield 'Exception' => [new Exception('prev')];
|
|
|
|
}
|
|
|
|
|
2023-02-09 22:42:18 +03:00
|
|
|
#[Test]
|
2021-02-06 23:37:58 +03:00
|
|
|
public function withInvalidEpochInOldDbBuildsException(): void
|
|
|
|
{
|
|
|
|
$e = GeolocationDbUpdateFailedException::withInvalidEpochInOldDb('foobar');
|
|
|
|
|
|
|
|
self::assertTrue($e->olderDbExists());
|
|
|
|
self::assertEquals(
|
|
|
|
'Build epoch with value "foobar" from existing geolocation database, could not be parsed to integer.',
|
|
|
|
$e->getMessage(),
|
|
|
|
);
|
2019-04-14 11:10:10 +03:00
|
|
|
}
|
|
|
|
}
|