mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Fix UpdateGeoLiteDbTest
This commit is contained in:
parent
b8ac9f3673
commit
4f3c2c7d2d
@ -14,6 +14,7 @@ use RuntimeException;
|
|||||||
use Shlinkio\Shlink\Core\EventDispatcher\Event\GeoLiteDbCreated;
|
use Shlinkio\Shlink\Core\EventDispatcher\Event\GeoLiteDbCreated;
|
||||||
use Shlinkio\Shlink\Core\EventDispatcher\UpdateGeoLiteDb;
|
use Shlinkio\Shlink\Core\EventDispatcher\UpdateGeoLiteDb;
|
||||||
use Shlinkio\Shlink\Core\Geolocation\GeolocationDbUpdaterInterface;
|
use Shlinkio\Shlink\Core\Geolocation\GeolocationDbUpdaterInterface;
|
||||||
|
use Shlinkio\Shlink\Core\Geolocation\GeolocationDownloadProgressHandlerInterface;
|
||||||
use Shlinkio\Shlink\Core\Geolocation\GeolocationResult;
|
use Shlinkio\Shlink\Core\Geolocation\GeolocationResult;
|
||||||
|
|
||||||
use function array_map;
|
use function array_map;
|
||||||
@ -51,11 +52,11 @@ class UpdateGeoLiteDbTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[Test, DataProvider('provideFlags')]
|
#[Test, DataProvider('provideFlags')]
|
||||||
public function noticeMessageIsPrintedWhenFirstCallbackIsInvoked(bool $oldDbExists, string $expectedMessage): void
|
public function noticeMessageIsPrintedWhenDownloadIsStarted(bool $oldDbExists, string $expectedMessage): void
|
||||||
{
|
{
|
||||||
$this->dbUpdater->expects($this->once())->method('checkDbUpdate')->withAnyParameters()->willReturnCallback(
|
$this->dbUpdater->expects($this->once())->method('checkDbUpdate')->withAnyParameters()->willReturnCallback(
|
||||||
function (callable $firstCallback) use ($oldDbExists): GeolocationResult {
|
function (GeolocationDownloadProgressHandlerInterface $handler) use ($oldDbExists): GeolocationResult {
|
||||||
$firstCallback($oldDbExists);
|
$handler->beforeDownload($oldDbExists);
|
||||||
return GeolocationResult::DB_IS_UP_TO_DATE;
|
return GeolocationResult::DB_IS_UP_TO_DATE;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -73,18 +74,24 @@ class UpdateGeoLiteDbTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[Test, DataProvider('provideDownloaded')]
|
#[Test, DataProvider('provideDownloaded')]
|
||||||
public function noticeMessageIsPrintedWhenSecondCallbackIsInvoked(
|
public function noticeMessageIsPrintedWhenDownloadIsFinished(
|
||||||
int $total,
|
int $total,
|
||||||
int $downloaded,
|
int $downloaded,
|
||||||
bool $oldDbExists,
|
bool $oldDbExists,
|
||||||
string|null $expectedMessage,
|
string|null $expectedMessage,
|
||||||
): void {
|
): void {
|
||||||
$this->dbUpdater->expects($this->once())->method('checkDbUpdate')->withAnyParameters()->willReturnCallback(
|
$this->dbUpdater->expects($this->once())->method('checkDbUpdate')->withAnyParameters()->willReturnCallback(
|
||||||
function ($_, callable $secondCallback) use ($total, $downloaded, $oldDbExists): GeolocationResult {
|
function (
|
||||||
|
GeolocationDownloadProgressHandlerInterface $handler,
|
||||||
|
) use (
|
||||||
|
$total,
|
||||||
|
$downloaded,
|
||||||
|
$oldDbExists,
|
||||||
|
): GeolocationResult {
|
||||||
// Invoke several times to ensure the log is printed only once
|
// Invoke several times to ensure the log is printed only once
|
||||||
$secondCallback($total, $downloaded, $oldDbExists);
|
$handler->handleProgress($total, $downloaded, $oldDbExists);
|
||||||
$secondCallback($total, $downloaded, $oldDbExists);
|
$handler->handleProgress($total, $downloaded, $oldDbExists);
|
||||||
$secondCallback($total, $downloaded, $oldDbExists);
|
$handler->handleProgress($total, $downloaded, $oldDbExists);
|
||||||
|
|
||||||
return GeolocationResult::DB_UPDATED;
|
return GeolocationResult::DB_UPDATED;
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user