- Commande CheckAllScrapersHealth + handler avec ports dédiés - Value Object ContentSourceHealthCheckData - Resource API Platform et State Processor - Adapters InMemory et tests unitaires + fonctionnels
42 lines
1.3 KiB
PHP
42 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Tests\Domain\Scraping\Adapter;
|
|
|
|
use App\Domain\Scraping\Domain\Contract\Repository\ContentSourceHealthRepositoryInterface;
|
|
|
|
class InMemoryContentSourceHealthRepository implements ContentSourceHealthRepositoryInterface
|
|
{
|
|
/** @var array<int, array{status: string, testedAt: ?\DateTimeImmutable, error: ?string}> */
|
|
private array $statuses = [];
|
|
|
|
public function markAsTesting(int $sourceId): void
|
|
{
|
|
$this->statuses[$sourceId] = ['status' => 'testing', 'testedAt' => null, 'error' => null];
|
|
}
|
|
|
|
public function markAsHealthy(int $sourceId, \DateTimeImmutable $testedAt): void
|
|
{
|
|
$this->statuses[$sourceId] = ['status' => 'ok', 'testedAt' => $testedAt, 'error' => null];
|
|
}
|
|
|
|
public function markAsUnhealthy(int $sourceId, \DateTimeImmutable $testedAt, string $error): void
|
|
{
|
|
$this->statuses[$sourceId] = ['status' => 'ko', 'testedAt' => $testedAt, 'error' => $error];
|
|
}
|
|
|
|
public function getStatus(int $sourceId): ?string
|
|
{
|
|
return $this->statuses[$sourceId]['status'] ?? null;
|
|
}
|
|
|
|
public function getError(int $sourceId): ?string
|
|
{
|
|
return $this->statuses[$sourceId]['error'] ?? null;
|
|
}
|
|
|
|
public function clear(): void
|
|
{
|
|
$this->statuses = [];
|
|
}
|
|
}
|