feat: Renommage de GetManga à GetMangaById + ajout de axios
This commit is contained in:
parent
666636e5bf
commit
504c62c155
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tests\Domain\Manga\Application\QueryHandler;
|
||||
|
||||
use App\Domain\Manga\Application\Query\GetMangaById;
|
||||
use App\Domain\Manga\Application\QueryHandler\GetMangaByIdHandler;
|
||||
use App\Domain\Manga\Domain\Exception\MangaNotFoundException;
|
||||
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\InMemoryMangaRepository;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class GetMangaByIdHandlerTest extends TestCase
|
||||
{
|
||||
private InMemoryMangaRepository $repository;
|
||||
private GetMangaByIdHandler $handler;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->repository = new InMemoryMangaRepository();
|
||||
$this->handler = new GetMangaByIdHandler($this->repository);
|
||||
}
|
||||
|
||||
public function testHandleThrowsExceptionWhenMangaNotFound(): void
|
||||
{
|
||||
$this->expectException(MangaNotFoundException::class);
|
||||
|
||||
$query = new GetMangaById('non-existent-id');
|
||||
$this->handler->handle($query);
|
||||
}
|
||||
|
||||
public function testHandleReturnsMangaResponse(): void
|
||||
{
|
||||
// Arrange
|
||||
$manga = new Manga(
|
||||
new MangaId('123'),
|
||||
new MangaTitle('One Piece'),
|
||||
new MangaSlug('one-piece'),
|
||||
'Description test',
|
||||
'Eiichiro Oda',
|
||||
1997,
|
||||
['action', 'adventure'],
|
||||
'ongoing',
|
||||
new ExternalId('external-123'),
|
||||
'http://example.com/image.jpg',
|
||||
4.5
|
||||
);
|
||||
$this->repository->save($manga);
|
||||
|
||||
// Act
|
||||
$query = new GetMangaById('123');
|
||||
$response = $this->handler->handle($query);
|
||||
|
||||
// Assert
|
||||
$this->assertEquals('123', $response->id);
|
||||
$this->assertEquals('One Piece', $response->title);
|
||||
$this->assertEquals('one-piece', $response->slug);
|
||||
$this->assertEquals('Description test', $response->description);
|
||||
$this->assertEquals('Eiichiro Oda', $response->author);
|
||||
$this->assertEquals(1997, $response->publicationYear);
|
||||
$this->assertEquals(['action', 'adventure'], $response->genres);
|
||||
$this->assertEquals('ongoing', $response->status);
|
||||
$this->assertEquals('external-123', $response->externalId);
|
||||
$this->assertEquals('http://example.com/image.jpg', $response->imageUrl);
|
||||
$this->assertEquals(4.5, $response->rating);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->repository->clear();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user