update fake text repository for user

include the user when rebuilding Text instances in find and
getAll, preserving the rule that lookup methods return new
instances rather than stored references.
This commit is contained in:
Yisroel Baum 2026-05-02 21:27:45 +03:00
parent 4635fef3c7
commit 6668240126
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9

View file

@ -19,6 +19,7 @@ class FakeTextRepository implements TextRepository
$text = new Text(
id: $id,
name: $dto->name,
user: $dto->user,
);
$this->existingTexts[$id] = $text;
@ -27,19 +28,15 @@ class FakeTextRepository implements TextRepository
public function find(int $id): ?Text
{
$text = array_find(
$this->existingTexts,
function (Text $text) use ($id) {
return $text->getId() === $id;
}
);
if ($text === null) {
if (!isset($this->existingTexts[$id])) {
return null;
}
$text = $this->existingTexts[$id];
return new Text(
id: $id,
id: $text->getId(),
name: $text->getName(),
user: $text->getUser(),
);
}
@ -58,9 +55,10 @@ class FakeTextRepository implements TextRepository
return new Text(
id: $text->getId(),
name: $text->getName(),
user: $text->getUser(),
);
},
$this->existingTexts
array_values($this->existingTexts)
);
}
}