Skip to content

Commit

Permalink
Tests and Manifest Generation fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Spomky committed Dec 22, 2023
1 parent 1ce6e46 commit 8238d76
Showing 1 changed file with 26 additions and 24 deletions.
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()));
}
}

0 comments on commit 8238d76

Please sign in to comment.