diff --git a/src/Console/Command/DumpCommand.php b/src/Console/Command/DumpCommand.php index 89d46c3f..c6b1f344 100644 --- a/src/Console/Command/DumpCommand.php +++ b/src/Console/Command/DumpCommand.php @@ -57,7 +57,8 @@ public function configure(): void ->addOption('port', null, InputOption::VALUE_REQUIRED, 'Database port' . $configHint) ->addOption('user', null, InputOption::VALUE_REQUIRED, 'Database user' . $configHint) ->addOption('password', null, InputOption::VALUE_REQUIRED, 'Database password' . $configHint) - ->addOption('database', null, InputOption::VALUE_REQUIRED, 'Database name' . $configHint); + ->addOption('database', null, InputOption::VALUE_REQUIRED, 'Database name' . $configHint) + ->addOption('dry-run', null, InputOption::VALUE_NONE, 'The command will validate the configuration file, but won\'t actually perform the dump'); // phpcs:enable Generic.Files.LineLength.TooLong } @@ -94,7 +95,7 @@ public function execute(InputInterface $input, OutputInterface $output): int $this->dumpInfo->setOutput($output); } - $this->dumper->dump($config); + $this->dumper->dump($config, $input->getOption('dry-run')); } catch (Exception $e) { if ($output->isVerbose()) { throw $e; diff --git a/src/Dumper/DumperInterface.php b/src/Dumper/DumperInterface.php index b07f0bbe..ec162025 100644 --- a/src/Dumper/DumperInterface.php +++ b/src/Dumper/DumperInterface.php @@ -11,5 +11,5 @@ interface DumperInterface /** * Create a dump according to the configuration. */ - public function dump(ConfigInterface $config): void; + public function dump(ConfigInterface $config, bool $dryRun = false): void; } diff --git a/src/Dumper/MysqlDumper.php b/src/Dumper/MysqlDumper.php index 3c216ede..0f92b47c 100644 --- a/src/Dumper/MysqlDumper.php +++ b/src/Dumper/MysqlDumper.php @@ -24,7 +24,7 @@ public function __construct( /** * @inheritdoc */ - public function dump(ConfigInterface $config): void + public function dump(ConfigInterface $config, bool $dryRun = false): void { $database = $this->databaseFactory->create($config); @@ -57,9 +57,11 @@ public function dump(ConfigInterface $config): void // Close the Doctrine connection before proceeding to the dump creation (MySQLDump-PHP uses its own connection) $database->getConnection()->close(); - // Create the dump - $output = $config->getDumpOutput(); - $dumper->start($output); + if (!$dryRun) { + // Create the dump + $dumper->start($config->getDumpOutput()); + } + $this->eventDispatcher->dispatch(new DumpFinishedEvent($config)); }