diff --git a/config/services.yaml b/config/services.yaml index d1ed16a9..fbd340c1 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -93,6 +93,8 @@ services: '$bookFolderNamingFormat': '%BOOK_FOLDER_NAMING_FORMAT%' '$bookFileNamingFormat': '%BOOK_FILE_NAMING_FORMAT%' + App\Service\BookFileSystemManagerInterface: '@App\Service\BookFileSystemManager' + App\Kobo\ParamConverter\SyncTokenParamConverter: tags: - { name: request.param_converter, priority: 100 } @@ -124,4 +126,13 @@ services: when@dev: services: - Symfony\Component\HttpKernel\Profiler\Profiler: '@profiler' \ No newline at end of file + Symfony\Component\HttpKernel\Profiler\Profiler: '@profiler' + +when@test: + services: + App\Tests\FileSystemManagerForTests: + autowire: true + bind: + $publicDirectory: '%kernel.project_dir%/tests/Resources' + App\Service\BookFileSystemManagerInterface: + alias: 'App\Tests\FileSystemManagerForTests' \ No newline at end of file diff --git a/src/Kobo/DownloadHelper.php b/src/Kobo/DownloadHelper.php index fa057a0c..71202fa2 100644 --- a/src/Kobo/DownloadHelper.php +++ b/src/Kobo/DownloadHelper.php @@ -9,7 +9,7 @@ use App\Kobo\Kepubify\KepubifyConversionFailed; use App\Kobo\Kepubify\KepubifyMessage; use App\Kobo\Response\MetadataResponseService; -use App\Service\BookFileSystemManager; +use App\Service\BookFileSystemManagerInterface; use Psr\Log\LoggerInterface; use Symfony\Component\HttpFoundation\BinaryFileResponse; use Symfony\Component\HttpFoundation\HeaderUtils; @@ -22,7 +22,7 @@ class DownloadHelper { public function __construct( - private readonly BookFileSystemManager $fileSystemManager, + private readonly BookFileSystemManagerInterface $fileSystemManager, private readonly CoverTransformer $coverTransformer, protected UrlGeneratorInterface $urlGenerator, protected LoggerInterface $logger, diff --git a/src/Service/BookFileSystemManager.php b/src/Service/BookFileSystemManager.php index 05f0fdf7..0f2373e7 100644 --- a/src/Service/BookFileSystemManager.php +++ b/src/Service/BookFileSystemManager.php @@ -13,7 +13,7 @@ use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\String\Slugger\SluggerInterface; -class BookFileSystemManager +class BookFileSystemManager implements BookFileSystemManagerInterface { public const ALLOWED_FILE_EXTENSIONS = [ '*.epub', '*.cbr', '*.cbz', '*.pdf', '*.mobi', diff --git a/src/Service/BookFileSystemManagerInterface.php b/src/Service/BookFileSystemManagerInterface.php new file mode 100644 index 00000000..5d0f5ec8 --- /dev/null +++ b/src/Service/BookFileSystemManagerInterface.php @@ -0,0 +1,28 @@ +injectFakeFileSystemManager(); $book = $this->findByIdAndKobo(BookFixture::ID, $this->getKoboDevice()); self::assertNotNull($book, 'The book is not linked to the Kobo'); @@ -37,7 +36,6 @@ public function testDownload(): void public function testDownloadKepubFailed(): void { $client = static::getClient(); - $this->injectFakeFileSystemManager(); // Disable Kepubify conversion $lastValue = $this->getKepubifyEnabler()->disable(); @@ -63,8 +61,6 @@ public function testDownloadKepubFailed(): void public function testDownloadKepub(): void { $client = static::getClient(); - $this->injectFakeFileSystemManager(); - $book = $this->findByIdAndKobo(BookFixture::ID, $this->getKoboDevice()); self::assertNotNull($book, 'The book is not linked to the Kobo'); diff --git a/tests/Controller/Kobo/KoboImageControllerTest.php b/tests/Controller/Kobo/KoboImageControllerTest.php index 18f33d11..c6168724 100644 --- a/tests/Controller/Kobo/KoboImageControllerTest.php +++ b/tests/Controller/Kobo/KoboImageControllerTest.php @@ -12,8 +12,6 @@ class KoboImageControllerTest extends AbstractKoboControllerTest public function testDownload(): void { $client = static::getClient(); - $this->injectFakeFileSystemManager(); - $book = $this->findByIdAndKobo(BookFixture::ID, $this->getKoboDevice()); self::assertNotNull($book, 'The book is not linked to the Kobo'); diff --git a/tests/Controller/Kobo/KoboSyncControllerTest.php b/tests/Controller/Kobo/KoboSyncControllerTest.php index 805ddf36..8f84684f 100644 --- a/tests/Controller/Kobo/KoboSyncControllerTest.php +++ b/tests/Controller/Kobo/KoboSyncControllerTest.php @@ -30,7 +30,7 @@ public function assertPreConditions(): void public function testSyncControllerWithForce() : void { $client = static::getClient(); - $this->injectFakeFileSystemManager(); + $this->getEntityManager()->getRepository(KoboSyncedBook::class)->deleteAllSyncedBooks(1); @@ -53,7 +53,7 @@ public function testSyncControllerWithForce() : void public function testSyncControllerWithoutForce() : void { $client = static::getClient(); - $this->injectFakeFileSystemManager(); + $client?->request('GET', '/kobo/'.$this->accessKey.'/v1/library/sync'); @@ -90,7 +90,6 @@ public function testSyncControllerWithRemote() : void } }]')); - $this->injectFakeFileSystemManager(); $client?->request('GET', '/kobo/'.$this->accessKey.'/v1/library/sync'); @@ -112,7 +111,6 @@ public function testSyncControllerMetadata() : void { $uuid = $this->getBook()->getUuid(); $client = static::getClient(); - $this->injectFakeFileSystemManager(); $this->getKepubifyEnabler()->disable(); $client?->request('GET', '/kobo/'.$this->accessKey.'/v1/library/'.$uuid."/metadata"); @@ -128,7 +126,6 @@ public function testSyncControllerMetadataWithConversion() : void { $uuid = $this->getBook()->getUuid(); $client = static::getClient(); - $this->injectFakeFileSystemManager(); self::assertTrue($this->getKepubifyEnabler()->isEnabled()); $client?->request('GET', '/kobo/'.$this->accessKey.'/v1/library/'.$uuid."/metadata"); diff --git a/tests/FileSystemManagerForTests.php b/tests/FileSystemManagerForTests.php new file mode 100644 index 00000000..18693bfd --- /dev/null +++ b/tests/FileSystemManagerForTests.php @@ -0,0 +1,26 @@ +getMockBuilder(BookFileSystemManager::class); - - $DEFAULT_BOOK_FOLDER_NAMING_FORMAT = '{authorFirst}/{author}/{title}/{serie}'; - $DEFAULT_BOOK_FILE_NAMING_FORMAT = '{serie}-{title}'; - - $mock = $mockBuilder->setConstructorArgs([ - self::getContainer()->get(Security::class), - realpath($resources), - $DEFAULT_BOOK_FOLDER_NAMING_FORMAT, - $DEFAULT_BOOK_FILE_NAMING_FORMAT, - $this->createMock(SluggerInterface::class), - new NullLogger(), - ]) - ->onlyMethods(['getBooksDirectory', 'getCoverDirectory']) - ->enableProxyingToOriginalMethods() - ->getMock(); - $mock->expects(self::any())->method('getBooksDirectory')->willReturn($fixtureBookPath); - $mock->expects(self::any())->method('getCoverDirectory')->willReturn($fixtureBookPath); - - self::assertSame(realpath($resources).'/books/'.BookFixture::BOOK_ODYSSEY_FILENAME, $mock->getBookFilename($this->getBook()), "Faking Filesystem failed"); - self::getContainer()->set(BookFileSystemManager::class, $mock); - } + {} } \ No newline at end of file diff --git a/tests/Service/BookProgressionServiceTest.php b/tests/Service/BookProgressionServiceTest.php index b07ce6f2..1fa9cb5e 100644 --- a/tests/Service/BookProgressionServiceTest.php +++ b/tests/Service/BookProgressionServiceTest.php @@ -10,18 +10,15 @@ use App\Repository\BookRepository; use App\Repository\UserRepository; use App\Service\BookProgressionService; -use App\Tests\InjectFakeFileSystemTrait; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; class BookProgressionServiceTest extends KernelTestCase { - use InjectFakeFileSystemTrait; protected function setUp(): void { parent::setUp(); self::bootKernel(); - $this->injectFakeFileSystemManager(); } public function testPageNumber(): void{