Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug and better tests #14

Merged
merged 2 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Command/GenerateManifestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}
Expand Down Expand Up @@ -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'], '/')) {
Expand Down
50 changes: 26 additions & 24 deletions tests/Functional/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,64 +8,66 @@
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();
}

#[Test]
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
$commandTester->execute([]);

// 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
$commandTester->execute([]);

// 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()));
}
}