diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php index 13394258c..24a48df83 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php @@ -75,7 +75,8 @@ protected function configure(): void 'all-or-nothing', null, InputOption::VALUE_OPTIONAL, - 'Wrap the entire migration in a transaction.' + 'Wrap the entire migration in a transaction.', + 'notprovided' ) ->setHelp(<<%command.name% command executes a migration to a specified version or the latest available version: diff --git a/lib/Doctrine/Migrations/Tools/Console/ConsoleInputMigratorConfigurationFactory.php b/lib/Doctrine/Migrations/Tools/Console/ConsoleInputMigratorConfigurationFactory.php index 04ee777b3..853b28913 100644 --- a/lib/Doctrine/Migrations/Tools/Console/ConsoleInputMigratorConfigurationFactory.php +++ b/lib/Doctrine/Migrations/Tools/Console/ConsoleInputMigratorConfigurationFactory.php @@ -21,12 +21,26 @@ public function getMigratorConfiguration(InputInterface $input): MigratorConfigu { $timeAllQueries = $input->hasOption('query-time') ? (bool) $input->getOption('query-time') : false; $dryRun = $input->hasOption('dry-run') ? (bool) $input->getOption('dry-run') : false; - $allOrNothing = $input->hasOption('all-or-nothing') ? $input->getOption('all-or-nothing') : null; - $allOrNothing = (bool) ($allOrNothing ?? $this->configuration->isAllOrNothing()); + $allOrNothing = $this->determineAllOrNothingValueFrom($input) ?? $this->configuration->isAllOrNothing(); return (new MigratorConfiguration()) ->setDryRun($dryRun) ->setTimeAllQueries($timeAllQueries) ->setAllOrNothing($allOrNothing); } + + private function determineAllOrNothingValueFrom(InputInterface $input): ?bool + { + $allOrNothingOption = null; + + if ($input->hasOption('all-or-nothing')) { + $allOrNothingOption = $input->getOption('all-or-nothing'); + } + + if ($allOrNothingOption === 'notprovided') { + return null; + } + + return (bool) ($allOrNothingOption ?? true); + } } diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrateCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrateCommandTest.php index 71aa4344d..3838137ae 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrateCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrateCommandTest.php @@ -362,7 +362,7 @@ public function testExecuteMigrateDown(): void } /** - * @psalm-param array $input + * @psalm-param array $input * * @dataProvider allOrNothing */ @@ -390,13 +390,22 @@ public function testExecuteMigrateAllOrNothing(bool $default, array $input, bool } /** - * @psalm-return Generator, bool}> + * @psalm-return Generator, bool}> */ public function allOrNothing(): Generator { yield [false, ['--all-or-nothing' => false], false]; + yield [false, ['--all-or-nothing' => 0], false]; + yield [false, ['--all-or-nothing' => '0'], false]; + yield [false, ['--all-or-nothing' => true], true]; + yield [false, ['--all-or-nothing' => 1], true]; + yield [false, ['--all-or-nothing' => '1'], true]; + yield [false, ['--all-or-nothing' => null], true]; + yield [true, ['--all-or-nothing' => false], false]; + yield [true, ['--all-or-nothing' => 0], false]; + yield [true, ['--all-or-nothing' => '0'], false]; yield [true, [], true]; yield [false, [], false];