Rabbi_Gerzi/backend/tests/Fakes/FakeSetRepository.php
2026-05-25 08:24:31 +03:00

49 lines
929 B
PHP

<?php
namespace Tests\Fakes;
use App\Set\Set as DomainSet;
use App\Set\SetRepository;
class FakeSetRepository implements SetRepository
{
/**
* @var DomainSet[]
*/
private array $setsById = [];
public function store(DomainSet $set): void
{
$this->setsById[$set->getId()] = $set;
}
public function find(int $id): ?DomainSet
{
if (! isset($this->setsById[$id])) {
return null;
}
return $this->cloneSet($this->setsById[$id]);
}
/**
* @return DomainSet[]
*/
public function getAll(): array
{
$sets = [];
foreach ($this->setsById as $set) {
$sets[] = $this->cloneSet($set);
}
return $sets;
}
private function cloneSet(DomainSet $set): DomainSet
{
return new DomainSet(
id: $set->getId(),
name: $set->getName(),
);
}
}