refactor(scraping): job PENDING dès le POST HTTP, handler sans Doctrine
- ScrapingJob: mangaId/chapterNumber/sourceId optionnels (nullable) pour permettre la création en PENDING sans lookup DB dans le StateProcessor - ScrapeChapter: ajoute jobId (pré-généré par le StateProcessor) - ScrapeChapterStateProcessor: crée et persiste le job PENDING avant dispatch; injecte JobRepositoryInterface uniquement - ScrapeChapterHandler: supprime EntityManagerInterface, beginTransaction/ commit/rollback; charge le job existant via jobId, complete() sur succès seulement, fail() si toutes les sources échouent - ScrapeChapterHandlerTest: pré-crée le job, passe jobId dans la commande, supprime le mock EntityManagerInterface - ScrapeChapterTest: accès aux messages via static InMemoryMessageBus, vérifie la présence du jobId dans la commande dispatchée
This commit is contained in:
parent
ec4a8be934
commit
fa035bfbfa
@@ -7,6 +7,7 @@ use App\Domain\Scraping\Application\CommandHandler\ScrapeChapterHandler;
|
||||
use App\Domain\Scraping\Domain\Event\ChapterScrapingFailed;
|
||||
use App\Domain\Scraping\Domain\Event\ChapterScrapingStarted;
|
||||
use App\Domain\Scraping\Domain\Model\Chapter;
|
||||
use App\Domain\Scraping\Domain\Model\ScrapingJob;
|
||||
use App\Domain\Shared\Domain\Event\ChapterScraped;
|
||||
use App\Tests\Domain\Scraping\Adapter\InMemoryChapterRepository;
|
||||
use App\Tests\Domain\Scraping\Adapter\InMemoryEventBus;
|
||||
@@ -16,8 +17,6 @@ use App\Tests\Domain\Scraping\Adapter\InMemoryMangaRepository;
|
||||
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;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ScrapeChapterHandlerTest extends TestCase
|
||||
@@ -30,7 +29,6 @@ class ScrapeChapterHandlerTest extends TestCase
|
||||
private InMemoryMangaRepository $mangaRepository;
|
||||
private InMemorySourceRepository $sourceRepository;
|
||||
private InMemoryEventBus $eventBus;
|
||||
private EntityManagerInterface|MockObject $entityManager;
|
||||
private ScrapeChapterHandler $handler;
|
||||
|
||||
protected function setUp(): void
|
||||
@@ -43,11 +41,6 @@ class ScrapeChapterHandlerTest extends TestCase
|
||||
$this->mangaRepository = new InMemoryMangaRepository();
|
||||
$this->sourceRepository = new InMemorySourceRepository();
|
||||
$this->eventBus = new InMemoryEventBus();
|
||||
$this->entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
|
||||
$this->entityManager->method('beginTransaction')->willReturn(null);
|
||||
$this->entityManager->method('commit')->willReturn(null);
|
||||
$this->entityManager->method('rollback')->willReturn(null);
|
||||
|
||||
$this->chapterRepository->save(new Chapter(
|
||||
id: '1',
|
||||
@@ -65,21 +58,21 @@ class ScrapeChapterHandlerTest extends TestCase
|
||||
$this->mangaRepository,
|
||||
$this->sourceRepository,
|
||||
$this->eventBus,
|
||||
$this->entityManager
|
||||
);
|
||||
}
|
||||
|
||||
public function testHandleSuccessfully(): void
|
||||
{
|
||||
$command = new ScrapeChapter(
|
||||
chapterId: '1'
|
||||
);
|
||||
$jobId = 'test-job-id';
|
||||
$job = new ScrapingJob($jobId, 'test-manga', 2);
|
||||
$this->jobRepository->save($job);
|
||||
|
||||
$command = new ScrapeChapter(chapterId: '1', jobId: $jobId);
|
||||
$this->handler->handle($command);
|
||||
|
||||
$job = $this->jobRepository->findByType('scraping_job');
|
||||
$this->assertCount(1, $job);
|
||||
$job = array_values($job)[0];
|
||||
$jobs = $this->jobRepository->findByType('scraping_job');
|
||||
$this->assertCount(1, $jobs);
|
||||
$job = array_values($jobs)[0];
|
||||
|
||||
$dispatchedMessages = $this->eventBus->getDispatchedMessages();
|
||||
$this->assertCount(2, $dispatchedMessages);
|
||||
|
||||
Reference in New Issue
Block a user