impl find method in fake text repo

This commit is contained in:
Yisroel Baum 2026-02-20 11:59:56 +02:00
parent cd9e96f7b1
commit ba65f8fa42
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9

View file

@ -8,10 +8,38 @@ use App\Text\TextRepository;
class FakeTextRepository implements TextRepository
{
/**
* @var Text[]
*/
private array $existingTexts = [];
public function create(CreateTextDto $dto): Text
{
return new Text(
$id = $this->nextId();
$text = new Text(
id: $id,
name: $dto->name,
);
$this->existingTexts[$id] = $text;
return $text;
}
public function find(int $id): ?Text
{
$text = $this->existingTexts[$id];
if ($text === null) {
return null;
}
return new Text(
id: $id,
name: $text->getName(),
);
}
private function nextId(): int
{
return count($this->existingTexts);
}
}