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:
ext.jeremy.guillot@maxicoffee.domains
2026-03-09 17:54:35 +01:00
parent dae215dd3d
commit c50f1638ee
27 changed files with 410 additions and 419 deletions

View File

@@ -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();

View File

@@ -11,7 +11,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;
@@ -19,18 +18,15 @@ use PHPUnit\Framework\TestCase;
class ImportVolumeHandlerTest extends TestCase
{
private InMemoryMangaRepository $mangaRepository;
private InMemoryChapterRepository $chapterRepository;
private InMemoryPathManager $pathManager;
private ImportVolumeHandler $handler;
protected function setUp(): void
{
$this->mangaRepository = new InMemoryMangaRepository();
$this->chapterRepository = new InMemoryChapterRepository();
$this->pathManager = new InMemoryPathManager();
$this->handler = new ImportVolumeHandler(
$this->mangaRepository,
$this->chapterRepository,
$this->pathManager
);
}
@@ -63,7 +59,7 @@ class ImportVolumeHandlerTest extends TestCase
true,
null
);
$this->chapterRepository->save($chapter);
$this->mangaRepository->saveChapter($chapter);
}
$cbzBinary = $this->createValidCbzBinary();
@@ -77,12 +73,12 @@ class ImportVolumeHandlerTest extends TestCase
$this->handler->handle($command);
// Assert
$chapters = $this->chapterRepository->findByMangaIdAndVolume($mangaId, $volumeNumber);
$chapters = $this->mangaRepository->findChaptersByMangaIdAndVolume($mangaId, $volumeNumber);
$this->assertCount(3, $chapters);
foreach ($chapters as $chapter) {
$this->assertTrue($chapter->isAvailable());
$this->assertStringContainsString('_vol' . $volumeNumber . '.cbz', $chapter->getCbzPath());
$this->assertNotNull($chapter->getPagesDirectory());
}
}
@@ -153,7 +149,7 @@ class ImportVolumeHandlerTest extends TestCase
$cbzBinary = $this->createValidCbzBinary();
$command = new ImportVolume(
mangaId: $mangaId,
volumeNumber: 999, // Non-existent volume
volumeNumber: 999,
fileBinary: $cbzBinary
);
@@ -165,9 +161,6 @@ class ImportVolumeHandlerTest 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_');
@@ -187,7 +180,3 @@ class ImportVolumeHandlerTest extends TestCase
return $binaryContent;
}
}