impl find method in fake text repo
This commit is contained in:
parent
cd9e96f7b1
commit
ba65f8fa42
1 changed files with 29 additions and 1 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue