mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-10 01:03:13 +08:00
Fix GeolocationDbUpdater test
This commit is contained in:
@@ -6,14 +6,15 @@ namespace Shlinkio\Shlink\Core\Geolocation\Entity;
|
||||
|
||||
use Cake\Chronos\Chronos;
|
||||
use Shlinkio\Shlink\Common\Entity\AbstractEntity;
|
||||
use Shlinkio\Shlink\Core\Exception\RuntimeException;
|
||||
|
||||
use function stat;
|
||||
|
||||
class GeolocationDbUpdate extends AbstractEntity
|
||||
{
|
||||
private function __construct(
|
||||
public readonly string $reason,
|
||||
private readonly string $filesystemId,
|
||||
private readonly string $reason,
|
||||
private GeolocationDbUpdateStatus $status = GeolocationDbUpdateStatus::IN_PROGRESS,
|
||||
private readonly Chronos $dateCreated = new Chronos(),
|
||||
private Chronos $dateUpdated = new Chronos(),
|
||||
@@ -21,32 +22,34 @@ class GeolocationDbUpdate extends AbstractEntity
|
||||
) {
|
||||
}
|
||||
|
||||
public static function withReason(string $reason, string|null $filesystemId = null): self
|
||||
public static function withReason(string $reason): self
|
||||
{
|
||||
return new self($reason, $filesystemId ?? self::currentFilesystemId());
|
||||
return new self($reason, self::currentFilesystemId());
|
||||
}
|
||||
|
||||
public static function currentFilesystemId(): string
|
||||
{
|
||||
$system = stat(__FILE__);
|
||||
if (! $system) {
|
||||
// TODO Throw error
|
||||
throw new RuntimeException('It was not possible to resolve filesystem ID via stat function');
|
||||
}
|
||||
|
||||
return (string) $system['dev'];
|
||||
}
|
||||
|
||||
public function finishSuccessfully(): void
|
||||
public function finishSuccessfully(): self
|
||||
{
|
||||
$this->dateUpdated = Chronos::now();
|
||||
$this->status = GeolocationDbUpdateStatus::SUCCESS;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function finishWithError(string $error): void
|
||||
public function finishWithError(string $error): self
|
||||
{
|
||||
$this->error = $error;
|
||||
$this->dateUpdated = Chronos::now();
|
||||
$this->status = GeolocationDbUpdateStatus::ERROR;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -95,9 +95,9 @@ readonly class GeolocationDbUpdater implements GeolocationDbUpdaterInterface
|
||||
// - Most recent attempt is older than 30 days (and implicitly, successful)
|
||||
$reasonMatch = match (true) {
|
||||
$mostRecentDownload === null => [false, 'No download attempts tracked for this instance'],
|
||||
$this->dbUpdater->databaseFileExists() => [false, 'Geolocation db file does not exist'],
|
||||
! $this->dbUpdater->databaseFileExists() => [false, 'Geolocation db file does not exist'],
|
||||
$lastAttemptIsError => [true, 'Max consecutive errors not reached'],
|
||||
$mostRecentDownload->isOlderThan(days: 30) => [true, 'Last successful attempt'],
|
||||
$mostRecentDownload->isOlderThan(days: 30) => [true, 'Last successful attempt is old enough'],
|
||||
default => null,
|
||||
};
|
||||
if ($reasonMatch !== null) {
|
||||
|
||||
Reference in New Issue
Block a user