test set elements
This commit is contained in:
parent
104909bcf5
commit
db35a97910
6 changed files with 409 additions and 0 deletions
57
backend/tests/Fakes/FakeSetRepository.php
Normal file
57
backend/tests/Fakes/FakeSetRepository.php
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Fakes;
|
||||
|
||||
use App\Set\CreateSetDto;
|
||||
use App\Set\Set as DomainSet;
|
||||
use App\Set\SetRepository;
|
||||
|
||||
class FakeSetRepository implements SetRepository
|
||||
{
|
||||
/**
|
||||
* @var DomainSet[]
|
||||
*/
|
||||
private array $setsById = [];
|
||||
|
||||
public function create(CreateSetDto $dto): DomainSet
|
||||
{
|
||||
$id = count($this->setsById) + 1;
|
||||
$set = new DomainSet(
|
||||
id: $id,
|
||||
name: $dto->name,
|
||||
);
|
||||
$this->setsById[$id] = $set;
|
||||
|
||||
return $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(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue