38 lines
952 B
PHP
38 lines
952 B
PHP
<?php
|
|
|
|
namespace App\Tests\Domain\Scraping\Adapter;
|
|
|
|
use App\Domain\Scraping\Domain\Contract\Repository\ChapterRepositoryInterface;
|
|
use App\Domain\Scraping\Domain\Model\Chapter;
|
|
|
|
class InMemoryChapterRepository implements ChapterRepositoryInterface
|
|
{
|
|
private array $chapters = [];
|
|
|
|
public function getById(string $id): ?Chapter
|
|
{
|
|
return $this->chapters[$id] ?? null;
|
|
}
|
|
|
|
public function getByMangaIdAndChapterNumber(string $mangaId, int $chapterNumber): Chapter
|
|
{
|
|
foreach ($this->chapters as $chapter) {
|
|
if ($chapter->mangaId === $mangaId && $chapter->chapterNumber === $chapterNumber) {
|
|
return $chapter;
|
|
}
|
|
}
|
|
|
|
throw new \RuntimeException('Chapter not found');
|
|
}
|
|
|
|
public function save(Chapter $chapter): void
|
|
{
|
|
$this->chapters[$chapter->id] = $chapter;
|
|
}
|
|
|
|
public function clear(): void
|
|
{
|
|
$this->chapters = [];
|
|
}
|
|
}
|