44 lines
992 B
PHP
44 lines
992 B
PHP
<?php
|
|
|
|
namespace App\Tests\Domain\Scraping\Adapter;
|
|
|
|
use App\Domain\Scraping\Domain\Contract\Repository\MangaRepositoryInterface;
|
|
use App\Domain\Scraping\Domain\Model\Manga;
|
|
|
|
class InMemoryMangaRepository implements MangaRepositoryInterface
|
|
{
|
|
private array $mangas = [];
|
|
|
|
public function __construct()
|
|
{
|
|
// Ajoute un manga par défaut pour les tests
|
|
$this->mangas['test-manga'] = new Manga(
|
|
'test-manga',
|
|
'Test Manga',
|
|
'test-manga',
|
|
'2024',
|
|
'Test Author',
|
|
'A test manga description'
|
|
);
|
|
}
|
|
|
|
public function getById(string $id): Manga
|
|
{
|
|
if (!isset($this->mangas[$id])) {
|
|
throw new \RuntimeException('Manga not found');
|
|
}
|
|
|
|
return $this->mangas[$id];
|
|
}
|
|
|
|
public function save(Manga $manga): void
|
|
{
|
|
$this->mangas[$manga->getId()] = $manga;
|
|
}
|
|
|
|
public function clear(): void
|
|
{
|
|
$this->mangas = [];
|
|
}
|
|
}
|