Fix DownloadGeoLiteDbCommandTest

This commit is contained in:
Alejandro Celaya 2024-12-11 08:50:56 +01:00
parent 84d12f6811
commit 2ede615da8

View File

@ -12,6 +12,7 @@ use Shlinkio\Shlink\CLI\Command\Visit\DownloadGeoLiteDbCommand;
use Shlinkio\Shlink\CLI\Util\ExitCode;
use Shlinkio\Shlink\Core\Exception\GeolocationDbUpdateFailedException;
use Shlinkio\Shlink\Core\Geolocation\GeolocationDbUpdaterInterface;
use Shlinkio\Shlink\Core\Geolocation\GeolocationDownloadProgressHandlerInterface;
use Shlinkio\Shlink\Core\Geolocation\GeolocationResult;
use ShlinkioTest\Shlink\CLI\Util\CliTestUtils;
use Symfony\Component\Console\Tester\CommandTester;
@ -36,9 +37,9 @@ class DownloadGeoLiteDbCommandTest extends TestCase
int $expectedExitCode,
): void {
$this->dbUpdater->expects($this->once())->method('checkDbUpdate')->withAnyParameters()->willReturnCallback(
function (callable $beforeDownload, callable $handleProgress) use ($olderDbExists): void {
$beforeDownload($olderDbExists);
$handleProgress(100, 50);
function (GeolocationDownloadProgressHandlerInterface $handler) use ($olderDbExists): void {
$handler->beforeDownload($olderDbExists);
$handler->handleProgress(100, 50, $olderDbExists);
throw $olderDbExists
? GeolocationDbUpdateFailedException::withOlderDb()
@ -105,8 +106,8 @@ class DownloadGeoLiteDbCommandTest extends TestCase
public static function provideSuccessParams(): iterable
{
yield 'up to date db' => [fn () => GeolocationResult::CHECK_SKIPPED, '[INFO] GeoLite2 db file is up to date.'];
yield 'outdated db' => [function (callable $beforeDownload): GeolocationResult {
$beforeDownload(true);
yield 'outdated db' => [function (GeolocationDownloadProgressHandlerInterface $handler): GeolocationResult {
$handler->beforeDownload(true);
return GeolocationResult::DB_CREATED;
}, '[OK] GeoLite2 db file properly downloaded.'];
}