shlink/module/CLI/test/Exception/GeolocationDbUpdateFailedExceptionTest.php

68 lines
2.0 KiB
PHP
Raw Normal View History

<?php
2019-10-05 10:26:10 -05:00
declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI\Exception;
use Exception;
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());
2020-10-03 17:35:14 -05:00
self::assertEquals(
'An error occurred while updating geolocation database, but an older DB is already present.',
2020-01-01 13:48:31 -06:00
$e->getMessage(),
);
2020-10-03 17:35:14 -05:00
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());
}
2023-02-09 02:32:38 -06:00
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(),
);
}
}