diff --git a/config/services.yaml b/config/services.yaml index e0344395..fcd807fa 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -1,26 +1,34 @@ services: # Commands + db_tools.command.anonymization.run: + class: MakinaCorpus\DbToolsBundle\Command\Anonymization\AnonymizeCommand + arguments: + - '@db_tools.anonymization.anonymizator.factory' + - '%doctrine.default_connection%' + tags: ['console.command'] db_tools.command.anonymization.list: - class: MakinaCorpus\DbToolsBundle\Command\AnonymizerListCommand + class: MakinaCorpus\DbToolsBundle\Command\Anonymization\AnonymizerListCommand arguments: - '@db_tools.anonymization.anonymizer.registry' tags: ['console.command'] - db_tools.command.anonymization.check: - class: MakinaCorpus\DbToolsBundle\Command\AnonymizationCheckCommand + db_tools.command.clean: + class: MakinaCorpus\DbToolsBundle\Command\Anonymization\CleanCommand arguments: - '@db_tools.anonymization.anonymizator.factory' + - '%doctrine.default_connection%' tags: ['console.command'] - db_tools.command.anonymization.run: - class: MakinaCorpus\DbToolsBundle\Command\AnonymizeCommand + db_tools.command.anonymization.check: + class: MakinaCorpus\DbToolsBundle\Command\Anonymization\ConfigCheckCommand arguments: - '@db_tools.anonymization.anonymizator.factory' - - '%doctrine.default_connection%' tags: ['console.command'] - db_tools.command.clean: - class: MakinaCorpus\DbToolsBundle\Command\CleanCommand + db_tools.command.backup: + class: MakinaCorpus\DbToolsBundle\Command\BackupCommand arguments: - - '@db_tools.anonymization.anonymizator.factory' - '%doctrine.default_connection%' + - '%db_tools.excluded_tables%' + - '@db_tools.backupper.factory.registry' + - '@db_tools.storage' tags: ['console.command'] db_tools.command.check: class: MakinaCorpus\DbToolsBundle\Command\CheckCommand @@ -29,14 +37,15 @@ services: - '@db_tools.backupper.factory.registry' - '@db_tools.restorer.factory.registry' tags: ['console.command'] - db_tools.command.backup: - class: MakinaCorpus\DbToolsBundle\Command\BackupCommand + db_tools.command.gdprify: + class: MakinaCorpus\DbToolsBundle\Command\GdprifyCommand arguments: - '%doctrine.default_connection%' - - '%db_tools.excluded_tables%' + - '@db_tools.restorer.factory.registry' - '@db_tools.backupper.factory.registry' - - '@db_tools.storage' + - '@db_tools.anonymization.anonymizator.factory' tags: ['console.command'] + db_tools.command.restore: class: MakinaCorpus\DbToolsBundle\Command\RestoreCommand arguments: @@ -50,14 +59,6 @@ services: - '%doctrine.default_connection%' - '@db_tools.stats_provider.factory.registry' tags: ['console.command'] - db_tools.command.gdprify: - class: MakinaCorpus\DbToolsBundle\Command\GdprifyCommand - arguments: - - '%doctrine.default_connection%' - - '@db_tools.restorer.factory.registry' - - '@db_tools.backupper.factory.registry' - - '@db_tools.anonymization.anonymizator.factory' - tags: ['console.command'] # Utilities db_tools.storage: diff --git a/dev.sh b/dev.sh index 17a58785..7c46a824 100755 --- a/dev.sh +++ b/dev.sh @@ -52,6 +52,7 @@ do_test() { -e DBAL_ROOT_PASSWORD=password \ -e DBAL_ROOT_USER="root" \ -e DBAL_USER=root \ + -e DATABASE_URL=mysql://root:password@mysql57:3306/test_db?serverVersion=5.7 \ phpunit vendor/bin/phpunit $@ section_title "Running tests with MySQL 8" @@ -64,6 +65,7 @@ do_test() { -e DBAL_ROOT_PASSWORD=password \ -e DBAL_ROOT_USER=root \ -e DBAL_USER=root \ + -e DATABASE_URL=mysql://root:password@mysql80:3306/test_db?serverVersion=8 \ phpunit vendor/bin/phpunit $@ section_title "Running tests with MariaDB 11" @@ -76,6 +78,7 @@ do_test() { -e DBAL_ROOT_PASSWORD="password" \ -e DBAL_ROOT_USER="root" \ -e DBAL_USER=root \ + -e DATABASE_URL=mysql://root:password@mariadb11:3306/test_db?serverVersion=11.1.3-MariaDB \ phpunit vendor/bin/phpunit $@ section_title "Running tests with PostgreSQL 10" @@ -88,6 +91,7 @@ do_test() { -e DBAL_ROOT_PASSWORD=password \ -e DBAL_ROOT_USER=postgres \ -e DBAL_USER=postgres \ + -e DATABASE_URL="postgresql://postgres:password@postgresql10:5432/test_db?serverVersion=10&charset=utf8" \ phpunit vendor/bin/phpunit $@ section_title "Running tests with PostgreSQL 16" @@ -100,6 +104,7 @@ do_test() { -e DBAL_ROOT_PASSWORD=password \ -e DBAL_ROOT_USER=postgres \ -e DBAL_USER=postgres \ + -e DATABASE_URL="postgresql://postgres:password@postgresql16:5432/test_db?serverVersion=16&charset=utf8" \ phpunit vendor/bin/phpunit $@ } diff --git a/docker-compose.yaml b/docker-compose.yaml index 37a86bbb..9d41d805 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -27,7 +27,7 @@ services: networks: - db-tools-test mariadb11: - image: mariadb:11 + image: mariadb:11.1.3 restart: 'no' environment: MYSQL_DATABASE: test_db diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c4b69677..cf03352a 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -7,6 +7,7 @@ + diff --git a/src/Command/AnonymizeCommand.php b/src/Command/Anonymization/AnonymizeCommand.php similarity index 98% rename from src/Command/AnonymizeCommand.php rename to src/Command/Anonymization/AnonymizeCommand.php index c6718bff..85eec02d 100644 --- a/src/Command/AnonymizeCommand.php +++ b/src/Command/Anonymization/AnonymizeCommand.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace MakinaCorpus\DbToolsBundle\Command; +namespace MakinaCorpus\DbToolsBundle\Command\Anonymization; use MakinaCorpus\DbToolsBundle\Anonymization\AnonymizatorFactory; use Symfony\Component\Console\Attribute\AsCommand; diff --git a/src/Command/AnonymizerListCommand.php b/src/Command/Anonymization/AnonymizerListCommand.php similarity index 94% rename from src/Command/AnonymizerListCommand.php rename to src/Command/Anonymization/AnonymizerListCommand.php index 4ef2c2ec..7e2270f4 100644 --- a/src/Command/AnonymizerListCommand.php +++ b/src/Command/Anonymization/AnonymizerListCommand.php @@ -2,9 +2,8 @@ declare(strict_types=1); -namespace MakinaCorpus\DbToolsBundle\Command; +namespace MakinaCorpus\DbToolsBundle\Command\Anonymization; -use MakinaCorpus\DbToolsBundle\Anonymization\Anonymizer\AbstractAnonymizer; use MakinaCorpus\DbToolsBundle\Anonymization\Anonymizer\AnonymizerRegistry; use MakinaCorpus\DbToolsBundle\Attribute\AsAnonymizer; use Symfony\Component\Console\Attribute\AsCommand; diff --git a/src/Command/CleanCommand.php b/src/Command/Anonymization/CleanCommand.php similarity index 98% rename from src/Command/CleanCommand.php rename to src/Command/Anonymization/CleanCommand.php index 5c970b0c..2db54118 100644 --- a/src/Command/CleanCommand.php +++ b/src/Command/Anonymization/CleanCommand.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace MakinaCorpus\DbToolsBundle\Command; +namespace MakinaCorpus\DbToolsBundle\Command\Anonymization; use MakinaCorpus\DbToolsBundle\Anonymization\AnonymizatorFactory; use Symfony\Component\Console\Attribute\AsCommand; diff --git a/src/Command/AnonymizationCheckCommand.php b/src/Command/Anonymization/ConfigCheckCommand.php similarity index 90% rename from src/Command/AnonymizationCheckCommand.php rename to src/Command/Anonymization/ConfigCheckCommand.php index effb4dcc..1f3f38ae 100644 --- a/src/Command/AnonymizationCheckCommand.php +++ b/src/Command/Anonymization/ConfigCheckCommand.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace MakinaCorpus\DbToolsBundle\Command; +namespace MakinaCorpus\DbToolsBundle\Command\Anonymization; use MakinaCorpus\DbToolsBundle\Anonymization\AnonymizatorFactory; use MakinaCorpus\DbToolsBundle\Anonymization\Config\AnonymizerConfig; @@ -13,8 +13,8 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; -#[AsCommand(name: 'db-tools:anonymization:check', description: 'Check and dump anonymization configuration.')] -class AnonymizationCheckCommand extends Command +#[AsCommand(name: 'db-tools:anonymization:config-check', description: 'Check and dump anonymization configuration.')] +class ConfigCheckCommand extends Command { public function __construct( private AnonymizatorFactory $anonymizatorFactory, diff --git a/src/DependencyInjection/DbToolsExtension.php b/src/DependencyInjection/DbToolsExtension.php index 09d5176a..683156c6 100644 --- a/src/DependencyInjection/DbToolsExtension.php +++ b/src/DependencyInjection/DbToolsExtension.php @@ -47,7 +47,7 @@ public function load(array $configs, ContainerBuilder $container) if (\is_dir($defaultDirectory)) { $anonymizerPaths[] = '%kernel.project_dir%/src/Anonymizer'; } - $anonymizerPaths[] = \realpath(\dirname(__DIR__)) . '/Anonymizer'; + $anonymizerPaths[] = \realpath(\dirname(__DIR__)) . '/Anonymization/Anonymizer'; $container->setParameter('db_tools.anonymization.anonymizer.paths', $anonymizerPaths); } diff --git a/tests/Functional/Command/Anonymization/AnonymizeCommandTest.php b/tests/Functional/Command/Anonymization/AnonymizeCommandTest.php new file mode 100644 index 00000000..0508c196 --- /dev/null +++ b/tests/Functional/Command/Anonymization/AnonymizeCommandTest.php @@ -0,0 +1,32 @@ +find('db-tools:anonymization:run'); + $commandTester = new CommandTester($command); + $commandTester->execute( + [ + '--force' => true + ], + [ + 'interactive' => false, + 'capture_stderr_separately' => true + ] + ); + + $commandTester->assertCommandIsSuccessful(); + } +} diff --git a/tests/Functional/Command/Anonymization/AnonymizerListCommandTest.php b/tests/Functional/Command/Anonymization/AnonymizerListCommandTest.php new file mode 100644 index 00000000..573fb8e6 --- /dev/null +++ b/tests/Functional/Command/Anonymization/AnonymizerListCommandTest.php @@ -0,0 +1,29 @@ +find('db-tools:anonymization:list'); + $commandTester = new CommandTester($command); + $commandTester->execute( + [], + [ + 'capture_stderr_separately' => true + ] + ); + + $commandTester->assertCommandIsSuccessful(); + } +} diff --git a/tests/Functional/Command/Anonymization/CleanCommandTest.php b/tests/Functional/Command/Anonymization/CleanCommandTest.php new file mode 100644 index 00000000..492e36ea --- /dev/null +++ b/tests/Functional/Command/Anonymization/CleanCommandTest.php @@ -0,0 +1,32 @@ +find('db-tools:anonymization:clean'); + $commandTester = new CommandTester($command); + $commandTester->execute( + [ + '--force' => true + ], + [ + 'interactive' => false, + 'capture_stderr_separately' => true + ] + ); + + $commandTester->assertCommandIsSuccessful(); + } +} diff --git a/tests/Functional/Command/Anonymization/ConfigCheckCommandTest.php b/tests/Functional/Command/Anonymization/ConfigCheckCommandTest.php new file mode 100644 index 00000000..8c0392a2 --- /dev/null +++ b/tests/Functional/Command/Anonymization/ConfigCheckCommandTest.php @@ -0,0 +1,30 @@ +find('db-tools:anonymization:config-check'); + $commandTester = new CommandTester($command); + $commandTester->execute( + [], + [ + 'interactive' => false, + 'capture_stderr_separately' => true + ] + ); + + $commandTester->assertCommandIsSuccessful(); + } +} diff --git a/tests/Functional/Command/BackupCommandTest.php b/tests/Functional/Command/BackupCommandTest.php new file mode 100644 index 00000000..0ec41d1c --- /dev/null +++ b/tests/Functional/Command/BackupCommandTest.php @@ -0,0 +1,24 @@ +find('db-tools:backup'); + $commandTester = new CommandTester($command); + $commandTester->execute([]); + + $commandTester->assertCommandIsSuccessful(); + } +} diff --git a/tests/Functional/Command/CheckCommandTest.php b/tests/Functional/Command/CheckCommandTest.php new file mode 100644 index 00000000..e21a11cb --- /dev/null +++ b/tests/Functional/Command/CheckCommandTest.php @@ -0,0 +1,24 @@ +find('db-tools:check'); + $commandTester = new CommandTester($command); + $commandTester->execute([]); + + $commandTester->assertCommandIsSuccessful(); + } +} diff --git a/tests/Functional/Command/GdprifyCommandTest.php b/tests/Functional/Command/GdprifyCommandTest.php new file mode 100644 index 00000000..6ec3e039 --- /dev/null +++ b/tests/Functional/Command/GdprifyCommandTest.php @@ -0,0 +1,26 @@ +markTestSkipped("Hard to test for know."); + + $kernel = self::bootKernel(); + $application = new Application($kernel); + + $command = $application->find('db-tools:gdprify'); + $commandTester = new CommandTester($command); + $commandTester->execute([]); + + $commandTester->assertCommandIsSuccessful(); + } +} diff --git a/tests/Functional/Command/RestoreCommandTest.php b/tests/Functional/Command/RestoreCommandTest.php new file mode 100644 index 00000000..e03b1187 --- /dev/null +++ b/tests/Functional/Command/RestoreCommandTest.php @@ -0,0 +1,26 @@ +markTestSkipped("Hard to test for know."); + + $kernel = self::bootKernel(); + $application = new Application($kernel); + + $command = $application->find('db-tools:restore'); + $commandTester = new CommandTester($command); + $commandTester->execute([]); + + $commandTester->assertCommandIsSuccessful(); + } +} diff --git a/tests/Functional/Command/StatsCommandTest.php b/tests/Functional/Command/StatsCommandTest.php new file mode 100644 index 00000000..13d8dbca --- /dev/null +++ b/tests/Functional/Command/StatsCommandTest.php @@ -0,0 +1,24 @@ +find('db-tools:stats'); + $commandTester = new CommandTester($command); + $commandTester->execute([]); + + $commandTester->assertCommandIsSuccessful(); + } +} diff --git a/tests/TestKernel.php b/tests/TestKernel.php new file mode 100644 index 00000000..ca583ae8 --- /dev/null +++ b/tests/TestKernel.php @@ -0,0 +1,68 @@ +testRootDir = sys_get_temp_dir().'/'.uniqid('db_tools_', true); + + parent::__construct($environment, $debug); + } + + public function registerBundles(): iterable + { + return [ + new FrameworkBundle(), + new DoctrineBundle(), + new DbToolsBundle(), + ]; + } + + protected function configureContainer(ContainerBuilder $containerBuilder, LoaderInterface $loader) + { + $containerBuilder->loadFromExtension('framework', [ + 'secret' => 123, + 'php_errors' => [ + 'log' => true, + ], + ]); + $containerBuilder->loadFromExtension('doctrine', [ + 'dbal' => [ + 'url' => '%env(resolve:DATABASE_URL)%', + ], + ]); + } + + public function getProjectDir(): string + { + return $this->getRootDir(); + } + + public function getRootDir(): string + { + return $this->testRootDir; + } + + /** + * @return void + */ + public function process(ContainerBuilder $container) + { + + } +}