Goal-Calibration/tests/Fakes/FakeTextRepository.php

45 lines
836 B
PHP

<?php
namespace Tests\Fakes;
use App\Text\CreateTextDto;
use App\Text\Text;
use App\Text\TextRepository;
class FakeTextRepository implements TextRepository
{
/**
* @var Text[]
*/
private array $existingTexts = [];
public function create(CreateTextDto $dto): 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);
}
}