test sets list endpoint
This commit is contained in:
parent
5b9df7d02a
commit
61ab8c09dc
3 changed files with 191 additions and 0 deletions
49
backend/tests/Fakes/FakeSetRepository.php
Normal file
49
backend/tests/Fakes/FakeSetRepository.php
Normal 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(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue