diff --git a/dev.sh b/dev.sh index 8325fcc9..792b4b5b 100755 --- a/dev.sh +++ b/dev.sh @@ -43,6 +43,12 @@ do_checks() { docker compose -p db_tools_bundle_test exec phpunit composer checks } +# Launch PHPUnit tests without any database vendor +do_unittest() { + section_title "PHPUnit unit tests" + docker compose -p db_tools_bundle_test exec phpunit vendor/bin/phpunit +} + do_test_mysql57() { section_title "Running tests with MySQL 5.7" docker compose -p db_tools_bundle_test exec \ @@ -204,7 +210,7 @@ do_notice() { printf "\n - build, up and down a complete docker stack with all database vendors" printf "\n and versions that the DbToolsBundle supports" printf "\n - run Code Style Fixer (with PHP CS Fixer) and launch Static Analysis (with PHPStan)" - printf "\n - run PHPunit tests for all database vendors" + printf "\n - run PHPUnit tests for all database vendors" printf "\n\n--\n" printf "\nLaunch the script with one of these available actions:" printf "\n" @@ -212,9 +218,11 @@ do_notice() { printf "\n - ${GREEN}up${NC}: Start docker containers" printf "\n - ${GREEN}down${NC}: Stop docker containers" printf "\n - ${GREEN}checks${NC}: Launch composer checks (for Static analysis & Code style fixer)" - printf "\n - ${GREEN}test_all${NC}: Run PHPunit tests for all database vendors." - printf "\n PHPUnit options can be used as usual: ${GREEN}./dev.sh test_all --filter AnonymizatorFactoryTest${NC}" - printf "\n - ${GREEN}test${NC}: Run PHPunit tests for a specific database vendors or version" + printf "\n - ${GREEN}test_all${NC}: Run PHPUnit tests for all database vendors." + printf "\n PHPUnit options can be used as usual:" + printf "\n ${GREEN}./dev.sh test_all --filter AnonymizatorFactoryTest${NC}" + printf "\n - ${GREEN}test${NC}: Run PHPUnit tests for a specific database vendors or version" + printf "\n - ${GREEN}unittest${NC}: Run PHPUnit tests without any database vendor" printf "\n - ${GREEN}notice${NC}: Display this help" printf "\n\n" } @@ -225,6 +233,6 @@ action=${1-} if [[ -n $@ ]];then shift;fi case $action in - build|up|down|checks|test_all|test|notice) do_$action "$@";; + build|up|down|checks|test_all|unittest|test|notice) do_$action "$@";; *) do_notice;; esac \ No newline at end of file diff --git a/src/Backupper/BackupperFactoryRegistry.php b/src/Backupper/BackupperFactoryRegistry.php index 76bbc5d0..26cb73a7 100644 --- a/src/Backupper/BackupperFactoryRegistry.php +++ b/src/Backupper/BackupperFactoryRegistry.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Connection; use Doctrine\Persistence\ManagerRegistry; +use MakinaCorpus\DbToolsBundle\Error\NotImplementedException; class BackupperFactoryRegistry { @@ -33,25 +34,17 @@ public function create(?string $connectionName = null): BackupperInterface $connection = $this->doctrineRegistry->getConnection($connectionName); $driver = $connection->getParams()['driver']; - if (!\array_key_exists($driver, $this->backupperBinaries)) { - throw new \InvalidArgumentException(\sprintf( - "There is no backupper binary provided for DBAL driver '%s'", - $driver - )); - } - - foreach($this->backupperFactories as $backupperFactory) { - if ($backupperFactory->isSupported($driver)) { - return $backupperFactory->create( - $this->backupperBinaries[$driver], - $connection - ); + if (\array_key_exists($driver, $this->backupperBinaries)) { + foreach ($this->backupperFactories as $backupperFactory) { + if ($backupperFactory->isSupported($driver)) { + return $backupperFactory->create( + $this->backupperBinaries[$driver], + $connection + ); + } } } - throw new \InvalidArgumentException(\sprintf( - "No backupper found for connection '%s'", - $connectionName - )); + throw new NotImplementedException(\sprintf("Backup is not implemented or configured for driver '%s' while using connection '%s'", $driver, $connectionName)); } } diff --git a/src/Command/BackupCommand.php b/src/Command/BackupCommand.php index 4303f00c..334eb5f7 100644 --- a/src/Command/BackupCommand.php +++ b/src/Command/BackupCommand.php @@ -4,9 +4,10 @@ namespace MakinaCorpus\DbToolsBundle\Command; +use MakinaCorpus\DbToolsBundle\DbToolsStorage; use MakinaCorpus\DbToolsBundle\Backupper\BackupperFactoryRegistry; use MakinaCorpus\DbToolsBundle\Backupper\BackupperInterface; -use MakinaCorpus\DbToolsBundle\DbToolsStorage; +use MakinaCorpus\DbToolsBundle\Error\NotImplementedException; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; @@ -64,6 +65,7 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { $this->io = new SymfonyStyle($input, $output); + if ($input->getOption('connection')) { $this->connectionName = $input->getOption('connection'); } @@ -72,10 +74,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->excludedTables[$this->connectionName] = \explode(',', $excludedTables); } - $created = $this->doBackup(); + try { + $created = $this->doBackup(); + + if (!$input->getOption('no-cleanup')) { + $this->cleanupBackups($created); + } + } catch (NotImplementedException $e) { + $this->io->error($e->getMessage()); - if (!$input->getOption('no-cleanup')) { - $this->cleanupBackups($created); + return NotImplementedException::CONSOLE_EXIT_STATUS; } return Command::SUCCESS; diff --git a/src/Command/CheckCommand.php b/src/Command/CheckCommand.php index 10b0bdc8..27af0c4e 100644 --- a/src/Command/CheckCommand.php +++ b/src/Command/CheckCommand.php @@ -5,6 +5,7 @@ namespace MakinaCorpus\DbToolsBundle\Command; use MakinaCorpus\DbToolsBundle\Backupper\BackupperFactoryRegistry; +use MakinaCorpus\DbToolsBundle\Error\NotImplementedException; use MakinaCorpus\DbToolsBundle\Restorer\RestorerFactoryRegistry; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; @@ -45,13 +46,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int $connection = $input->getArgument('connection') ?? $this->defaultConnectionName; - $backupper = $this->backupperFactoryRegistry->create($connection); - $response = $backupper->checkBinary(); - $io->success("Backupper binary ok : " . $response); + try { + $backupper = $this->backupperFactoryRegistry->create($connection); + $response = $backupper->checkBinary(); + $io->success("Backupper binary ok : " . $response); - $restorer = $this->restorerFactoryRegistry->create($connection); - $response = $restorer->checkBinary(); - $io->success("Restorer binary ok : " . $response); + $restorer = $this->restorerFactoryRegistry->create($connection); + $response = $restorer->checkBinary(); + $io->success("Restorer binary ok : " . $response); + } catch (NotImplementedException $e) { + $io->error($e->getMessage()); + + return NotImplementedException::CONSOLE_EXIT_STATUS; + } return Command::SUCCESS; } diff --git a/src/Command/GdprifyCommand.php b/src/Command/GdprifyCommand.php index 1e57e6d3..234f2011 100644 --- a/src/Command/GdprifyCommand.php +++ b/src/Command/GdprifyCommand.php @@ -6,6 +6,7 @@ use MakinaCorpus\DbToolsBundle\Anonymization\AnonymizatorFactory; use MakinaCorpus\DbToolsBundle\Backupper\BackupperFactoryRegistry; +use MakinaCorpus\DbToolsBundle\Error\NotImplementedException; use MakinaCorpus\DbToolsBundle\Restorer\RestorerFactoryRegistry; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; @@ -108,9 +109,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->connectionName = $input->getOption('connection') ?? $this->connectionName; - $this->doRestore(); - $this->doAnonymize(); - $this->doBackup(); + try { + $this->doRestore(); + $this->doAnonymize(); + $this->doBackup(); + } catch (NotImplementedException $e) { + $this->io->error($e->getMessage()); + + return NotImplementedException::CONSOLE_EXIT_STATUS; + } return Command::SUCCESS; } diff --git a/src/Command/RestoreCommand.php b/src/Command/RestoreCommand.php index 7ffedd8c..749ed60e 100644 --- a/src/Command/RestoreCommand.php +++ b/src/Command/RestoreCommand.php @@ -4,8 +4,9 @@ namespace MakinaCorpus\DbToolsBundle\Command; -use MakinaCorpus\DbToolsBundle\Restorer\RestorerFactoryRegistry; use MakinaCorpus\DbToolsBundle\DbToolsStorage; +use MakinaCorpus\DbToolsBundle\Error\NotImplementedException; +use MakinaCorpus\DbToolsBundle\Restorer\RestorerFactoryRegistry; use MakinaCorpus\DbToolsBundle\Restorer\RestorerInterface; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; @@ -81,19 +82,25 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->preventMistake($input); - $this->restorer = $this->restorerFactory->create($this->connectionName); + try { + $this->restorer = $this->restorerFactory->create($this->connectionName); - if (!$input->getOption('filename')) { - $this->chooseBackup(); - } else { - $this->backupFilename = $input->getOption('filename'); - } + if (!$input->getOption('filename')) { + $this->chooseBackup(); + } else { + $this->backupFilename = $input->getOption('filename'); + } - if (!$this->backupFilename) { - return Command::INVALID; - } + if (!$this->backupFilename) { + return Command::INVALID; + } - $this->doRestore(); + $this->doRestore(); + } catch (NotImplementedException $e) { + $this->io->error($e->getMessage()); + + return Command::FAILURE; + } return Command::SUCCESS; } diff --git a/src/Command/StatsCommand.php b/src/Command/StatsCommand.php index 17909a67..6f0131f9 100644 --- a/src/Command/StatsCommand.php +++ b/src/Command/StatsCommand.php @@ -4,6 +4,7 @@ namespace MakinaCorpus\DbToolsBundle\Command; +use MakinaCorpus\DbToolsBundle\Error\NotImplementedException; use MakinaCorpus\DbToolsBundle\Stats\StatValue; use MakinaCorpus\DbToolsBundle\Stats\StatValueList; use MakinaCorpus\DbToolsBundle\Stats\StatsProviderFactoryRegistry; @@ -191,23 +192,29 @@ protected function execute(InputInterface $input, OutputInterface $output): int $which = $input->getArgument('which'); - $collections = match ($which) { - 'table' => $this->statsProviderFactoryRegistry->get($connection)->getTableStats($tags), - 'index' => $this->statsProviderFactoryRegistry->get($connection)->getIndexStats($tags), - 'global' => $this->statsProviderFactoryRegistry->get($connection)->getGlobalStats($tags), - default => throw new InvalidArgumentException(\sprintf("'which' allowed values are: '%s'", \implode("', '", ['global', 'table', 'index']))), - }; + try { + $collections = match ($which) { + 'table' => $this->statsProviderFactoryRegistry->get($connection)->getTableStats($tags), + 'index' => $this->statsProviderFactoryRegistry->get($connection)->getIndexStats($tags), + 'global' => $this->statsProviderFactoryRegistry->get($connection)->getGlobalStats($tags), + default => throw new InvalidArgumentException(\sprintf("'which' allowed values are: '%s'", \implode("', '", ['global', 'table', 'index']))), + }; - $hasValues = false; + $hasValues = false; - if ($input->getOption('flat')) { - $hasValues = $this->displayFlat($collections, $output); - } else { - $hasValues = $this->displayTable($collections, $output); - } + if ($input->getOption('flat')) { + $hasValues = $this->displayFlat($collections, $output); + } else { + $hasValues = $this->displayTable($collections, $output); + } + + if (!$hasValues) { + $io->warning(\sprintf("Statistics for '%s' are not supported for the current '%s' connexion database driver.", $which, $connection)); + } + } catch (NotImplementedException $e) { + $io->error($e->getMessage()); - if (!$hasValues) { - $io->warning(\sprintf("Statistics for '%s' are not supported for the current '%s' connexion database driver.", $which, $connection)); + return NotImplementedException::CONSOLE_EXIT_STATUS; } return Command::SUCCESS; diff --git a/src/Error/NotImplementedException.php b/src/Error/NotImplementedException.php new file mode 100644 index 00000000..5d9f1d43 --- /dev/null +++ b/src/Error/NotImplementedException.php @@ -0,0 +1,15 @@ +doctrineRegistry->getConnection($connectionName); $driver = $connection->getParams()['driver']; - if (!\array_key_exists($driver, $this->restorerBinaries)) { - throw new \InvalidArgumentException(\sprintf( - "There is no restorer binary provided for DBAL driver '%s'", - $driver - )); - } - - foreach($this->restorerFactories as $restorerFactory) { - if ($restorerFactory->isSupported($driver)) { - return $restorerFactory->create( - $this->restorerBinaries[$driver], - $connection - ); + if (\array_key_exists($driver, $this->restorerBinaries)) { + foreach ($this->restorerFactories as $restorerFactory) { + if ($restorerFactory->isSupported($driver)) { + return $restorerFactory->create( + $this->restorerBinaries[$driver], + $connection + ); + } } } - throw new \InvalidArgumentException(\sprintf( - "No restorer found for connection '%s'", - $connectionName - )); + throw new NotImplementedException(\sprintf("Restore is not implemented or configured for driver '%s' while using connection '%s'", $driver, $connectionName)); } } diff --git a/src/Stats/StatsProviderFactoryRegistry.php b/src/Stats/StatsProviderFactoryRegistry.php index eefed73f..548868a3 100644 --- a/src/Stats/StatsProviderFactoryRegistry.php +++ b/src/Stats/StatsProviderFactoryRegistry.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Connection; use Doctrine\Persistence\ManagerRegistry; +use MakinaCorpus\DbToolsBundle\Error\NotImplementedException; class StatsProviderFactoryRegistry { @@ -37,6 +38,6 @@ public function get(?string $connectionName = null): StatsProvider } } - throw new \InvalidArgumentException(\sprintf("No stats provider found for connection '%s'", $connectionName)); + throw new NotImplementedException(\sprintf("Stat collection is not implemented for driver '%s' while using connection '%s'", $driver, $connectionName)); } } diff --git a/tests/Functional/Command/Anonymization/AnonymizeCommandTest.php b/tests/Functional/Command/Anonymization/AnonymizeCommandTest.php index 0508c196..cb6bb373 100644 --- a/tests/Functional/Command/Anonymization/AnonymizeCommandTest.php +++ b/tests/Functional/Command/Anonymization/AnonymizeCommandTest.php @@ -4,14 +4,16 @@ namespace MakinaCorpus\DbToolsBundle\Tests\Functional\Command\Anonymization; +use MakinaCorpus\DbToolsBundle\Tests\FunctionalKernelTestCase; use Symfony\Bundle\FrameworkBundle\Console\Application; -use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\Console\Tester\CommandTester; -class AnonymizeCommandTest extends KernelTestCase +class AnonymizeCommandTest extends FunctionalKernelTestCase { public function testExecute(): void { + self::skipIfNoDatabase(); + $kernel = self::bootKernel(); $application = new Application($kernel); @@ -27,6 +29,6 @@ public function testExecute(): void ] ); - $commandTester->assertCommandIsSuccessful(); + self::assertCommandIsSuccessful($commandTester); } } diff --git a/tests/Functional/Command/Anonymization/AnonymizerListCommandTest.php b/tests/Functional/Command/Anonymization/AnonymizerListCommandTest.php index 573fb8e6..5570d53f 100644 --- a/tests/Functional/Command/Anonymization/AnonymizerListCommandTest.php +++ b/tests/Functional/Command/Anonymization/AnonymizerListCommandTest.php @@ -4,14 +4,16 @@ namespace MakinaCorpus\DbToolsBundle\Tests\Functional\Command\Anonymization; +use MakinaCorpus\DbToolsBundle\Tests\FunctionalKernelTestCase; use Symfony\Bundle\FrameworkBundle\Console\Application; -use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\Console\Tester\CommandTester; -class AnonymizerListCommandTest extends KernelTestCase +class AnonymizerListCommandTest extends FunctionalKernelTestCase { public function testExecute(): void { + self::skipIfNoDatabase(); + $kernel = self::bootKernel(); $application = new Application($kernel); @@ -24,6 +26,6 @@ public function testExecute(): void ] ); - $commandTester->assertCommandIsSuccessful(); + self::assertCommandIsSuccessful($commandTester); } } diff --git a/tests/Functional/Command/Anonymization/CleanCommandTest.php b/tests/Functional/Command/Anonymization/CleanCommandTest.php index 492e36ea..8d106815 100644 --- a/tests/Functional/Command/Anonymization/CleanCommandTest.php +++ b/tests/Functional/Command/Anonymization/CleanCommandTest.php @@ -4,14 +4,16 @@ namespace MakinaCorpus\DbToolsBundle\Tests\Functional\Command\Anonymization; +use MakinaCorpus\DbToolsBundle\Tests\FunctionalKernelTestCase; use Symfony\Bundle\FrameworkBundle\Console\Application; -use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\Console\Tester\CommandTester; -class CleanCommandTest extends KernelTestCase +class CleanCommandTest extends FunctionalKernelTestCase { public function testExecute(): void { + self::skipIfNoDatabase(); + $kernel = self::bootKernel(); $application = new Application($kernel); @@ -27,6 +29,6 @@ public function testExecute(): void ] ); - $commandTester->assertCommandIsSuccessful(); + self::assertCommandIsSuccessful($commandTester); } } diff --git a/tests/Functional/Command/Anonymization/ConfigCheckCommandTest.php b/tests/Functional/Command/Anonymization/ConfigCheckCommandTest.php index 8c0392a2..3ef93ebd 100644 --- a/tests/Functional/Command/Anonymization/ConfigCheckCommandTest.php +++ b/tests/Functional/Command/Anonymization/ConfigCheckCommandTest.php @@ -4,14 +4,16 @@ namespace MakinaCorpus\DbToolsBundle\Tests\Functional\Command\Anonymization; +use MakinaCorpus\DbToolsBundle\Tests\FunctionalKernelTestCase; use Symfony\Bundle\FrameworkBundle\Console\Application; -use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\Console\Tester\CommandTester; -class ConfigCheckCommandTest extends KernelTestCase +class ConfigCheckCommandTest extends FunctionalKernelTestCase { public function testExecute(): void { + self::skipIfNoDatabase(); + $kernel = self::bootKernel(); $application = new Application($kernel); @@ -25,6 +27,6 @@ public function testExecute(): void ] ); - $commandTester->assertCommandIsSuccessful(); + self::assertCommandIsSuccessful($commandTester); } } diff --git a/tests/Functional/Command/BackupCommandTest.php b/tests/Functional/Command/BackupCommandTest.php index 0ec41d1c..7941d4d3 100644 --- a/tests/Functional/Command/BackupCommandTest.php +++ b/tests/Functional/Command/BackupCommandTest.php @@ -4,14 +4,16 @@ namespace MakinaCorpus\DbToolsBundle\Tests\Functional\Command; +use MakinaCorpus\DbToolsBundle\Tests\FunctionalKernelTestCase; use Symfony\Bundle\FrameworkBundle\Console\Application; -use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\Console\Tester\CommandTester; -class BackupCommandTest extends KernelTestCase +class BackupCommandTest extends FunctionalKernelTestCase { public function testExecute(): void { + self::skipIfNoDatabase(); + $kernel = self::bootKernel(); $application = new Application($kernel); @@ -19,6 +21,6 @@ public function testExecute(): void $commandTester = new CommandTester($command); $commandTester->execute([]); - $commandTester->assertCommandIsSuccessful(); + self::assertCommandIsSuccessful($commandTester); } } diff --git a/tests/Functional/Command/CheckCommandTest.php b/tests/Functional/Command/CheckCommandTest.php index e21a11cb..d4333d61 100644 --- a/tests/Functional/Command/CheckCommandTest.php +++ b/tests/Functional/Command/CheckCommandTest.php @@ -4,14 +4,16 @@ namespace MakinaCorpus\DbToolsBundle\Tests\Functional\Command; +use MakinaCorpus\DbToolsBundle\Tests\FunctionalKernelTestCase; use Symfony\Bundle\FrameworkBundle\Console\Application; -use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\Console\Tester\CommandTester; -class CheckCommandTest extends KernelTestCase +class CheckCommandTest extends FunctionalKernelTestCase { public function testExecute(): void { + self::skipIfNoDatabase(); + $kernel = self::bootKernel(); $application = new Application($kernel); @@ -19,6 +21,6 @@ public function testExecute(): void $commandTester = new CommandTester($command); $commandTester->execute([]); - $commandTester->assertCommandIsSuccessful(); + self::assertCommandIsSuccessful($commandTester); } } diff --git a/tests/Functional/Command/GdprifyCommandTest.php b/tests/Functional/Command/GdprifyCommandTest.php index 0bfa0d37..e71217ed 100644 --- a/tests/Functional/Command/GdprifyCommandTest.php +++ b/tests/Functional/Command/GdprifyCommandTest.php @@ -4,14 +4,16 @@ namespace MakinaCorpus\DbToolsBundle\Tests\Functional\Command; +use MakinaCorpus\DbToolsBundle\Tests\FunctionalKernelTestCase; use Symfony\Bundle\FrameworkBundle\Console\Application; -use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\Console\Tester\CommandTester; -class GdprifyCommandTest extends KernelTestCase +class GdprifyCommandTest extends FunctionalKernelTestCase { public function testExecute(): void { + self::skipIfNoDatabase(); + $this->markTestSkipped("Hard to test for know."); // @phpstan-ignore-next-line @@ -22,6 +24,6 @@ public function testExecute(): void $commandTester = new CommandTester($command); $commandTester->execute([]); - $commandTester->assertCommandIsSuccessful(); + self::assertCommandIsSuccessful($commandTester); } } diff --git a/tests/Functional/Command/RestoreCommandTest.php b/tests/Functional/Command/RestoreCommandTest.php index d317dac5..a311e10b 100644 --- a/tests/Functional/Command/RestoreCommandTest.php +++ b/tests/Functional/Command/RestoreCommandTest.php @@ -4,14 +4,16 @@ namespace MakinaCorpus\DbToolsBundle\Tests\Functional\Command; +use MakinaCorpus\DbToolsBundle\Tests\FunctionalKernelTestCase; use Symfony\Bundle\FrameworkBundle\Console\Application; -use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\Console\Tester\CommandTester; -class RestoreCommandTest extends KernelTestCase +class RestoreCommandTest extends FunctionalKernelTestCase { public function testExecute(): void { + self::skipIfNoDatabase(); + $this->markTestSkipped("Hard to test for know."); // @phpstan-ignore-next-line @@ -22,6 +24,6 @@ public function testExecute(): void $commandTester = new CommandTester($command); $commandTester->execute([]); - $commandTester->assertCommandIsSuccessful(); + self::assertCommandIsSuccessful($commandTester); } } diff --git a/tests/Functional/Command/StatsCommandTest.php b/tests/Functional/Command/StatsCommandTest.php index 13d8dbca..f48ff8c0 100644 --- a/tests/Functional/Command/StatsCommandTest.php +++ b/tests/Functional/Command/StatsCommandTest.php @@ -4,14 +4,16 @@ namespace MakinaCorpus\DbToolsBundle\Tests\Functional\Command; +use MakinaCorpus\DbToolsBundle\Tests\FunctionalKernelTestCase; use Symfony\Bundle\FrameworkBundle\Console\Application; -use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\Console\Tester\CommandTester; -class StatsCommandTest extends KernelTestCase +class StatsCommandTest extends FunctionalKernelTestCase { public function testExecute(): void { + self::skipIfNoDatabase(); + $kernel = self::bootKernel(); $application = new Application($kernel); @@ -19,6 +21,6 @@ public function testExecute(): void $commandTester = new CommandTester($command); $commandTester->execute([]); - $commandTester->assertCommandIsSuccessful(); + self::assertCommandIsSuccessful($commandTester); } } diff --git a/tests/FunctionalKernelTestCase.php b/tests/FunctionalKernelTestCase.php new file mode 100644 index 00000000..a90154d1 --- /dev/null +++ b/tests/FunctionalKernelTestCase.php @@ -0,0 +1,34 @@ +getStatusCode(); + } else { + $status = $actual; + } + + if (NotImplementedException::CONSOLE_EXIT_STATUS === $status) { + self::markTestIncomplete("Not implemented feature."); + } + + self::assertSame(0, $status); + } +}