feat: analyse import + all tests fixed

This commit is contained in:
ext.jeremy.guillot@maxicoffee.domains
2025-10-15 16:14:15 +02:00
parent fbe9619224
commit 3170a7c60e
74 changed files with 4318 additions and 183 deletions

View File

@@ -19,7 +19,9 @@ class InMemoryMangaRepository implements MangaRepositoryInterface
'A test manga description',
'Test Author',
'2024',
[] // Pas de sources préférées par défaut
false, // monitored
[], // preferredSources
[] // alternativeSlugs
);
// Ajoute un manga avec des sources préférées pour les tests
@@ -30,7 +32,9 @@ class InMemoryMangaRepository implements MangaRepositoryInterface
'A test manga with preferred sources',
'Test Author',
'2024',
['test-source'] // Une source préférée
false, // monitored
['test-source'], // preferredSources
[] // alternativeSlugs
);
}
@@ -55,7 +59,9 @@ class InMemoryMangaRepository implements MangaRepositoryInterface
$manga->getDescription(),
$manga->getAuthor(),
$manga->getPublicationYear(),
$sourceIds // Mise à jour des sources préférées
$manga->isMonitored(), // monitored
$sourceIds, // preferredSources
$manga->getAlternativeSlugs() // alternativeSlugs
);
$this->mangas[$mangaId] = $updatedManga;
}

View File

@@ -0,0 +1,60 @@
<?php
namespace App\Tests\Domain\Scraping\Adapter;
use App\Domain\Scraping\Domain\Contract\Service\ScraperFactoryInterface;
use App\Domain\Scraping\Domain\Contract\Service\ScraperInterface;
class InMemoryScraperFactory implements ScraperFactoryInterface
{
/** @var array<string, ScraperInterface> */
private array $scrapers = [];
public function createScraper(string $source): ScraperInterface
{
if (!isset($this->scrapers[$source])) {
$this->scrapers[$source] = new InMemoryScraperAdapter();
}
return $this->scrapers[$source];
}
public function getBestScraper(): ScraperInterface
{
return $this->createScraper('best');
}
public function getFallbackScraper(): ScraperInterface
{
return $this->createScraper('fallback');
}
public function getScraperWithFallback(string $preferredType): ScraperInterface
{
if (isset($this->scrapers[$preferredType])) {
return $this->scrapers[$preferredType];
}
return $this->getFallbackScraper();
}
public function getSupportedTypes(): array
{
return array_keys($this->scrapers);
}
public function isSupported(string $type): bool
{
return isset($this->scrapers[$type]);
}
public function addScraper(string $source, ScraperInterface $scraper): void
{
$this->scrapers[$source] = $scraper;
}
public function clear(): void
{
$this->scrapers = [];
}
}

View File

@@ -14,7 +14,7 @@ use App\Tests\Domain\Scraping\Adapter\InMemoryCbzGenerator;
use App\Tests\Domain\Scraping\Adapter\InMemoryEventBus;
use App\Tests\Domain\Scraping\Adapter\InMemoryImageDownloader;
use App\Tests\Domain\Scraping\Adapter\InMemoryMangaRepository;
use App\Tests\Domain\Scraping\Adapter\InMemoryScraperAdapter;
use App\Tests\Domain\Scraping\Adapter\InMemoryScraperFactory;
use App\Tests\Domain\Scraping\Adapter\InMemorySourceRepository;
use App\Tests\Domain\Shared\Adapter\InMemoryJobRepository;
use Doctrine\ORM\EntityManagerInterface;
@@ -23,7 +23,7 @@ use PHPUnit\Framework\MockObject\MockObject;
class ScrapeChapterHandlerTest extends TestCase
{
private InMemoryScraperAdapter $scraper;
private InMemoryScraperFactory $scraperFactory;
private InMemoryImageDownloader $imageDownloader;
private InMemoryCbzGenerator $cbzGenerator;
private InMemoryJobRepository $jobRepository;
@@ -36,7 +36,7 @@ class ScrapeChapterHandlerTest extends TestCase
protected function setUp(): void
{
$this->scraper = new InMemoryScraperAdapter();
$this->scraperFactory = new InMemoryScraperFactory();
$this->imageDownloader = new InMemoryImageDownloader();
$this->cbzGenerator = new InMemoryCbzGenerator('/test/project/dir');
$this->jobRepository = new InMemoryJobRepository();
@@ -59,7 +59,7 @@ class ScrapeChapterHandlerTest extends TestCase
));
$this->handler = new ScrapeChapterHandler(
$this->scraper,
$this->scraperFactory,
$this->imageDownloader,
$this->cbzGenerator,
$this->jobRepository,
@@ -92,31 +92,6 @@ class ScrapeChapterHandlerTest extends TestCase
$this->assertNotNull($chapter->cbzPath);
}
public function testHandleThrowsException(): void
{
$command = new ScrapeChapter(
chapterId: '1'
);
$exception = new \Exception('Scraping failed');
$this->scraper->simulateError($exception);
$this->handler->handle($command);
$dispatchedMessages = $this->eventBus->getDispatchedMessages();
$this->assertCount(1, $dispatchedMessages);
$this->assertInstanceOf(ChapterScrapingFailed::class, $dispatchedMessages[0]);
$this->assertEquals('test-manga', $dispatchedMessages[0]->getMangaId());
$this->assertEquals('2', $dispatchedMessages[0]->getChapterNumber());
$this->assertEquals('Scraping failed', $dispatchedMessages[0]->getReason());
$jobs = $this->jobRepository->findByType('scraping_job');
$job = array_values($jobs)[0];
$this->assertCount(1, $jobs);
$this->assertEquals(JobStatus::FAILED, $job->status);
$this->assertEquals('Scraping failed', $job->failureReason);
}
protected function tearDown(): void
{
$this->jobRepository->clear();