diff --git a/tests/Fakes/FakeTextRepository.php b/tests/Fakes/FakeTextRepository.php index 0324cf5..7a625a1 100644 --- a/tests/Fakes/FakeTextRepository.php +++ b/tests/Fakes/FakeTextRepository.php @@ -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); } }