From ba65f8fa4220e774aa18568695a52d23a8e1ff8a Mon Sep 17 00:00:00 2001 From: Yisroel Baum Date: Fri, 20 Feb 2026 11:59:56 +0200 Subject: [PATCH] impl find method in fake text repo --- tests/Fakes/FakeTextRepository.php | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) 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); } }