test sets list endpoint

This commit is contained in:
Yisroel Baum 2026-08-03 20:24:01 +03:00
parent 5b9df7d02a
commit 61ab8c09dc
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
3 changed files with 191 additions and 0 deletions

View file

@ -0,0 +1,49 @@
<?php
namespace Tests\Fakes;
use App\Set\CreateSetDto;
use App\Set\Set;
use App\Set\SetRepository;
class FakeSetRepository implements SetRepository
{
/**
* @var array<int, Set>
*/
private array $sets = [];
public function create(CreateSetDto $dto): Set
{
$id = count($this->sets) + 1;
$set = new Set(
id: $id,
name: $dto->name,
creator: $dto->creator,
);
$this->sets[$id] = $set;
return $this->copy($set);
}
public function all(): array
{
$sets = array_values($this->sets);
usort($sets, function (Set $first, Set $second): int {
return $first->getName() <=> $second->getName();
});
return array_map(function (Set $set): Set {
return $this->copy($set);
}, $sets);
}
private function copy(Set $set): Set
{
return new Set(
id: $set->getId(),
name: $set->getName(),
creator: $set->getCreator(),
);
}
}