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:
parent
4635fef3c7
commit
6668240126
1 changed files with 7 additions and 9 deletions
|
|
@ -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)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue