Fix GeolocationDbUpdater test

This commit is contained in:
Alejandro Celaya
2024-12-16 19:50:06 +01:00
parent e715a0fb6f
commit 509ef668e6
4 changed files with 161 additions and 69 deletions

View File

@@ -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;
}
/**