Files
Mangarr/tests/Domain/Manga/Application/CommandHandler/FetchMangaChaptersHandlerTest.php
ext.jeremy.guillot@maxicoffee.domains 879b8fa2dc feat: endpoint FetchMangaChapters et tests
2025-02-11 18:00:49 +01:00

78 lines
2.4 KiB
PHP

<?php
namespace App\Tests\Domain\Manga\Application\CommandHandler;
use App\Domain\Manga\Application\Command\FetchMangaChapters;
use App\Domain\Manga\Application\CommandHandler\FetchMangaChaptersHandler;
use App\Domain\Manga\Domain\Model\Manga;
use App\Domain\Manga\Domain\Model\ValueObject\ExternalId;
use App\Domain\Manga\Domain\Model\ValueObject\MangaId;
use App\Domain\Manga\Domain\Model\ValueObject\MangaSlug;
use App\Domain\Manga\Domain\Model\ValueObject\MangaTitle;
use App\Tests\Domain\Manga\Adapter\InMemoryMangadexClient;
use App\Tests\Domain\Manga\Adapter\InMemoryMangaRepository;
use PHPUnit\Framework\TestCase;
class FetchMangaChaptersHandlerTest extends TestCase
{
private InMemoryMangadexClient $mangadexClient;
private InMemoryMangaRepository $mangaRepository;
private FetchMangaChaptersHandler $handler;
protected function setUp(): void
{
$this->mangadexClient = new InMemoryMangadexClient();
$this->mangaRepository = new InMemoryMangaRepository();
$this->handler = new FetchMangaChaptersHandler(
$this->mangadexClient,
$this->mangaRepository
);
}
public function testHandleWithExistingManga(): void
{
$externalId = 'manga-123';
$manga = new Manga(
new MangaId('manga-id'),
new MangaTitle('Test Manga'),
new MangaSlug('test-manga'),
'Description',
'Author',
2024,
[],
'ongoing',
new ExternalId($externalId)
);
$this->mangaRepository->save($manga);
$this->mangadexClient->setMangaFeed($externalId, [
'data' => [
[
'id' => 'chapter-1',
'attributes' => [
'chapter' => '1',
'title' => 'Chapter 1',
'volume' => '1'
]
]
]
]);
$command = new FetchMangaChapters($externalId);
$this->handler->handle($command);
$this->assertCount(1, $this->mangaRepository->getSavedChapters());
}
public function testHandleWithNonExistingManga(): void
{
$externalId = 'non-existing-manga';
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Manga not found');
$command = new FetchMangaChapters($externalId);
$this->handler->handle($command);
}
}