From 060327be76e20ad2bd66193ce81506fff8574aac Mon Sep 17 00:00:00 2001 From: Florent Morselli Date: Fri, 22 Dec 2023 15:48:48 +0100 Subject: [PATCH] Fix bug and better tests (#14) Tests and Manifest Generation fixed --- src/Command/GenerateManifestCommand.php | 5 ++- tests/Functional/CommandTest.php | 50 +++++++++++++------------ 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/Command/GenerateManifestCommand.php b/src/Command/GenerateManifestCommand.php index dadcef0..54beb15 100644 --- a/src/Command/GenerateManifestCommand.php +++ b/src/Command/GenerateManifestCommand.php @@ -113,7 +113,7 @@ private function storeFile(string $data, string $prefixUrl, string $storageFolde $this->filesystem->remove($tempFilename); return [ - 'src' => sprintf('%s%s', $prefixUrl, $filename), + 'src' => sprintf('%s/%s', $prefixUrl, $filename), 'type' => $mime, ]; } @@ -370,6 +370,9 @@ private function processProgressBar(ProgressBar $progressBar, string $type, stri private function processActions(SymfonyStyle $io, array $manifest): array|int { + if ($this->config['file_handlers'] === []) { + return $manifest; + } $io->info('Processing file handlers'); foreach ($manifest['file_handlers'] as $id => $handler) { if (str_starts_with((string) $handler['action'], '/')) { diff --git a/tests/Functional/CommandTest.php b/tests/Functional/CommandTest.php index 4d6873b..211fe62 100644 --- a/tests/Functional/CommandTest.php +++ b/tests/Functional/CommandTest.php @@ -8,17 +8,25 @@ use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\Console\Tester\CommandTester; +use Symfony\Component\Filesystem\Filesystem; /** * @internal */ final class CommandTest extends KernelTestCase { - protected function tearDown(): void + private static Application $application; + + protected function setUp(): void { - $filesystem = self::getContainer()->get('filesystem'); - $filesystem->remove(sprintf('%s/samples', self::$kernel->getCacheDir())); + self::cleanupFolder(); + self::$application = new Application(self::$kernel); + parent::setUp(); + } + protected function tearDown(): void + { + self::cleanupFolder(); parent::tearDown(); } @@ -26,12 +34,7 @@ protected function tearDown(): void public static function theCommandCanGenerateTheManifestAndIcons(): void { // Given - $kernel = self::bootKernel(); - $application = new Application($kernel); - $filesystem = self::getContainer()->get('filesystem'); - $filesystem->remove(sprintf('%s/samples', $kernel->getCacheDir())); - - $command = $application->find('pwa:build'); + $command = self::$application->find('pwa:build'); $commandTester = new CommandTester($command); // When @@ -39,24 +42,18 @@ public static function theCommandCanGenerateTheManifestAndIcons(): void // Then $commandTester->assertCommandIsSuccessful(); - $output = $commandTester->getDisplay(); - static::assertStringContainsString('PWA Manifest Generator', $output); - static::assertFileExists(sprintf('%s/samples/manifest/my-pwa.json', $kernel->getCacheDir())); - static::assertDirectoryExists(sprintf('%s/samples/icons', $kernel->getCacheDir())); - static::assertDirectoryExists(sprintf('%s/samples/screenshots', $kernel->getCacheDir())); - static::assertDirectoryExists(sprintf('%s/samples/shortcut_icons', $kernel->getCacheDir())); + static::assertStringContainsString('PWA Manifest Generator', $commandTester->getDisplay()); + static::assertFileExists(sprintf('%s/samples/manifest/my-pwa.json', self::$kernel->getCacheDir())); + static::assertDirectoryExists(sprintf('%s/samples/icons', self::$kernel->getCacheDir())); + static::assertDirectoryExists(sprintf('%s/samples/screenshots', self::$kernel->getCacheDir())); + static::assertDirectoryExists(sprintf('%s/samples/shortcut_icons', self::$kernel->getCacheDir())); } #[Test] public static function theCommandCanCreateTheServiceWorker(): void { // Given - $kernel = self::bootKernel(); - $application = new Application($kernel); - $filesystem = self::getContainer()->get('filesystem'); - $filesystem->remove(sprintf('%s/samples', $kernel->getCacheDir())); - - $command = $application->find('pwa:sw'); + $command = self::$application->find('pwa:sw'); $commandTester = new CommandTester($command); // When @@ -64,8 +61,13 @@ public static function theCommandCanCreateTheServiceWorker(): void // Then $commandTester->assertCommandIsSuccessful(); - $output = $commandTester->getDisplay(); - static::assertStringContainsString('Workbox Service Worker', $output); - static::assertFileExists(sprintf('%s/samples/sw/my-sw.js', $kernel->getCacheDir())); + static::assertStringContainsString('Workbox Service Worker', $commandTester->getDisplay()); + static::assertFileExists(sprintf('%s/samples/sw/my-sw.js', self::$kernel->getCacheDir())); + } + + private static function cleanupFolder(): void + { + $filesystem = self::getContainer()->get(Filesystem::class); + $filesystem->remove(sprintf('%s/samples', self::$kernel->getCacheDir())); } }