refactor(manga): merge ChapterRepositoryInterface into MangaRepositoryInterface + pagesDirectory
- Supprime ChapterRepositoryInterface du domaine Manga (et ses implémentations LegacyChapterRepository et InMemoryChapterRepository) - Déplace toutes les méthodes chapter vers MangaRepositoryInterface avec nommage explicite (findChapterById, findVisibleChapterById, updateChapter, deleteChapter, etc.) - Remplace cbzPath par pagesDirectory + pageCount dans le modèle Chapter (transition : toChapterDomain conserve un fallback cbzPath pour les données existantes, updateChapter synchronise les deux colonnes jusqu'à la Phase 4) - Ajoute la migration Doctrine (pages_directory, page_count sur la table chapter) - Met à jour tous les handlers, listeners, query handlers et state providers du domaine Manga pour injecter uniquement MangaRepositoryInterface - Adapte les tests unitaires et InMemoryMangaRepository avec les nouvelles méthodes Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
dae215dd3d
commit
c50f1638ee
@@ -12,7 +12,6 @@ use App\Domain\Manga\Domain\Model\ValueObject\ChapterId;
|
||||
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\InMemoryChapterRepository;
|
||||
use App\Tests\Domain\Manga\Adapter\InMemoryMangaRepository;
|
||||
use App\Tests\Domain\Manga\Adapter\InMemoryPathManager;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
@@ -20,18 +19,15 @@ use PHPUnit\Framework\TestCase;
|
||||
class ImportChapterHandlerTest extends TestCase
|
||||
{
|
||||
private InMemoryMangaRepository $mangaRepository;
|
||||
private InMemoryChapterRepository $chapterRepository;
|
||||
private InMemoryPathManager $pathManager;
|
||||
private ImportChapterHandler $handler;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->mangaRepository = new InMemoryMangaRepository();
|
||||
$this->chapterRepository = new InMemoryChapterRepository();
|
||||
$this->pathManager = new InMemoryPathManager();
|
||||
$this->handler = new ImportChapterHandler(
|
||||
$this->mangaRepository,
|
||||
$this->chapterRepository,
|
||||
$this->pathManager
|
||||
);
|
||||
}
|
||||
@@ -66,7 +62,7 @@ class ImportChapterHandlerTest extends TestCase
|
||||
$this->handler->handle($command);
|
||||
}
|
||||
|
||||
public function test_it_updates_existing_chapter_with_new_cbz(): void
|
||||
public function test_it_updates_existing_chapter_with_new_path(): void
|
||||
{
|
||||
// Arrange
|
||||
$mangaId = 'manga-123';
|
||||
@@ -82,7 +78,7 @@ class ImportChapterHandlerTest extends TestCase
|
||||
);
|
||||
$this->mangaRepository->save($manga);
|
||||
|
||||
// Create an existing chapter without CBZ
|
||||
// Create an existing chapter without pages
|
||||
$existingChapter = new Chapter(
|
||||
new ChapterId('chapter-123'),
|
||||
$mangaId,
|
||||
@@ -92,7 +88,7 @@ class ImportChapterHandlerTest extends TestCase
|
||||
true,
|
||||
null
|
||||
);
|
||||
$this->chapterRepository->save($existingChapter);
|
||||
$this->mangaRepository->saveChapter($existingChapter);
|
||||
|
||||
// Import the same chapter with CBZ
|
||||
$cbzBinary = $this->createValidCbzBinary();
|
||||
@@ -106,18 +102,16 @@ class ImportChapterHandlerTest extends TestCase
|
||||
$this->handler->handle($command);
|
||||
|
||||
// Assert
|
||||
$chapters = $this->chapterRepository->getAll();
|
||||
$this->assertCount(1, $chapters); // Still only one chapter
|
||||
|
||||
$updatedChapter = $chapters[0];
|
||||
$updatedChapter = $this->mangaRepository->findChapterById('chapter-123');
|
||||
$this->assertNotNull($updatedChapter);
|
||||
$this->assertEquals('chapter-123', $updatedChapter->getId());
|
||||
$this->assertEquals($mangaId, $updatedChapter->getMangaId());
|
||||
$this->assertEquals(1.5, $updatedChapter->getNumber());
|
||||
$this->assertEquals('Chapter 1.5', $updatedChapter->getTitle()); // Title preserved
|
||||
$this->assertEquals(1, $updatedChapter->getVolume()); // Volume preserved
|
||||
$this->assertEquals('Chapter 1.5', $updatedChapter->getTitle());
|
||||
$this->assertEquals(1, $updatedChapter->getVolume());
|
||||
$this->assertTrue($updatedChapter->isVisible());
|
||||
$this->assertTrue($updatedChapter->isAvailable()); // Now has CBZ
|
||||
$this->assertStringContainsString('_vol1_ch1.5.cbz', $updatedChapter->getCbzPath());
|
||||
$this->assertTrue($updatedChapter->isAvailable());
|
||||
$this->assertNotNull($updatedChapter->getPagesDirectory());
|
||||
}
|
||||
|
||||
public function test_it_throws_exception_when_manga_not_found(): void
|
||||
@@ -168,24 +162,16 @@ class ImportChapterHandlerTest extends TestCase
|
||||
$this->handler->handle($command);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a minimal valid CBZ (ZIP) binary for testing
|
||||
*/
|
||||
private function createValidCbzBinary(): string
|
||||
{
|
||||
$tmpFile = tempnam(sys_get_temp_dir(), 'cbz');
|
||||
|
||||
// Delete the empty file created by tempnam
|
||||
unlink($tmpFile);
|
||||
|
||||
$zip = new \ZipArchive();
|
||||
|
||||
// Create a new ZIP archive (avoid opening empty file)
|
||||
if ($zip->open($tmpFile, \ZipArchive::CREATE | \ZipArchive::OVERWRITE) !== true) {
|
||||
throw new \RuntimeException('Cannot create test CBZ file');
|
||||
}
|
||||
|
||||
// Add a dummy image file to the ZIP
|
||||
$zip->addFromString('image1.jpg', 'fake-image-data');
|
||||
$zip->close();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user