From 424d46104b9edbd892e3659720dea799df57d6e8 Mon Sep 17 00:00:00 2001 From: Yisroel Baum Date: Sat, 21 Feb 2026 21:09:08 +0200 Subject: [PATCH] fix test warning for undefined array key by using array_find --- app/Text/Text.php | 5 +++++ tests/Fakes/FakeTextRepository.php | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/Text/Text.php b/app/Text/Text.php index b5152d8..63f4403 100644 --- a/app/Text/Text.php +++ b/app/Text/Text.php @@ -9,6 +9,11 @@ class Text private string $name, ) {} + public function getId(): int + { + return $this->id; + } + public function getName(): string { return $this->name; diff --git a/tests/Fakes/FakeTextRepository.php b/tests/Fakes/FakeTextRepository.php index 7a625a1..86d3076 100644 --- a/tests/Fakes/FakeTextRepository.php +++ b/tests/Fakes/FakeTextRepository.php @@ -27,7 +27,12 @@ class FakeTextRepository implements TextRepository public function find(int $id): ?Text { - $text = $this->existingTexts[$id]; + $text = array_find( + $this->existingTexts, + function (Text $text) use ($id){ + return $text->getId() === $id; + } + ); if ($text === null) { return null; }