mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-28 09:03:07 +03:00
63 lines
2 KiB
PHP
63 lines
2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace ShlinkioTest\Shlink\CLI\Exception;
|
|
|
|
use Exception;
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
use PHPUnit\Framework\Attributes\Test;
|
|
use PHPUnit\Framework\TestCase;
|
|
use RuntimeException;
|
|
use Shlinkio\Shlink\CLI\Exception\GeolocationDbUpdateFailedException;
|
|
use Throwable;
|
|
|
|
class GeolocationDbUpdateFailedExceptionTest extends TestCase
|
|
{
|
|
#[Test, DataProvider('providePrev')]
|
|
public function withOlderDbBuildsException(?Throwable $prev): void
|
|
{
|
|
$e = GeolocationDbUpdateFailedException::withOlderDb($prev);
|
|
|
|
self::assertTrue($e->olderDbExists());
|
|
self::assertEquals(
|
|
'An error occurred while updating geolocation database, but an older DB is already present.',
|
|
$e->getMessage(),
|
|
);
|
|
self::assertEquals(0, $e->getCode());
|
|
self::assertEquals($prev, $e->getPrevious());
|
|
}
|
|
|
|
#[Test, DataProvider('providePrev')]
|
|
public function withoutOlderDbBuildsException(?Throwable $prev): void
|
|
{
|
|
$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());
|
|
}
|
|
|
|
public static function providePrev(): iterable
|
|
{
|
|
yield 'no prev' => [null];
|
|
yield 'RuntimeException' => [new RuntimeException('prev')];
|
|
yield 'Exception' => [new Exception('prev')];
|
|
}
|
|
|
|
#[Test]
|
|
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(),
|
|
);
|
|
}
|
|
}
|