provider = new InMemoryMangaProvider(); $this->repository = new InMemoryMangaRepository(); $this->handler = new CreateMangaFromMangadexHandler( $this->provider, $this->repository ); } public function testHandleSuccess(): void { // Arrange $externalId = 'manga-123'; $manga = new Manga( new MangaId('123'), new MangaTitle('Test Manga'), new MangaSlug('test-manga'), 'Description', 'Author', 2020, ['action'], 'ongoing', new ExternalId($externalId), 'http://example.com/cover.jpg', 4.5 ); $this->provider = new InMemoryMangaProvider([$manga]); $this->handler = new CreateMangaFromMangadexHandler( $this->provider, $this->repository ); // Act $command = new CreateMangaFromMangadex($externalId); $this->handler->handle($command); // Assert $savedManga = $this->repository->findById('123'); $this->assertNotNull($savedManga); $this->assertEquals($externalId, $savedManga->getExternalId()->getValue()); $this->assertEquals('Test Manga', $savedManga->getTitle()->getValue()); } public function testHandleThrowsExceptionWhenMangaNotFound(): void { // Arrange $command = new CreateMangaFromMangadex('non-existent-manga'); // Assert $this->expectException(MangaNotFoundException::class); $this->expectExceptionMessage('Manga not found on Mangadex'); // Act $this->handler->handle($command); } }