From eeb16a3eda1ba448e5923e79ced4577fef7c6eec Mon Sep 17 00:00:00 2001 From: Agustin Gomes Date: Fri, 23 Aug 2024 22:18:58 +0200 Subject: [PATCH] GH-1443: fix `--all-or-nothing` default behavior As result of some past changes to improve the way the option was inferred, several attempts to build a mechanism to handle the absence of value of this option were built via the following commits: 4da00c540672d687b8efa7b5f0c2b50107845379 533595134247c0c9f2e16c9a17fd1776a30303a4 5038099da818718703586804cc5bf890aec9086f 799f16d458a93aaadaec29012d8b8b425131fa1d f726a5fdfeb9f61db594b436b62dbeeb5e925308 This commit leverages all the iterative improvements introduced along the way, and setting the correct value when the option is correctly specified. This should bring the behavior inline with what is currently documented, while additionally adding a documentation deprecation informing users that passing a value to that option won't be allowed in 4.x --- docs/en/reference/configuration.rst | 7 ++----- .../Console/ConsoleInputMigratorConfigurationFactory.php | 5 ++--- .../Tests/Tools/Console/Command/ExecuteCommandTest.php | 4 ++-- .../Tests/Tools/Console/Command/MigrateCommandTest.php | 2 +- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/docs/en/reference/configuration.rst b/docs/en/reference/configuration.rst index 7b92c7520..6432a1c03 100644 --- a/docs/en/reference/configuration.rst +++ b/docs/en/reference/configuration.rst @@ -249,12 +249,9 @@ You can also set this option from the command line with the ``migrate`` command $ ./vendor/bin/doctrine-migrations migrate --all-or-nothing -If you have it enabled at the configuration level and want to change it for an individual migration you can -pass a value of ``0`` or ``1`` to ``--all-or-nothing``. - -.. code-block:: sh +.. note:: - $ ./vendor/bin/doctrine-migrations migrate --all-or-nothing=0 + Passing options to --all-or-nothing is deprecated from 3.7.x, and will not be allowed in 4.x Connection Configuration ------------------------ diff --git a/lib/Doctrine/Migrations/Tools/Console/ConsoleInputMigratorConfigurationFactory.php b/lib/Doctrine/Migrations/Tools/Console/ConsoleInputMigratorConfigurationFactory.php index fffc450ba..0cf8ccfcb 100644 --- a/lib/Doctrine/Migrations/Tools/Console/ConsoleInputMigratorConfigurationFactory.php +++ b/lib/Doctrine/Migrations/Tools/Console/ConsoleInputMigratorConfigurationFactory.php @@ -45,15 +45,14 @@ private function determineAllOrNothingValueFrom(InputInterface $input): bool|nul <<<'DEPRECATION' Context: Passing values to option `--all-or-nothing` Problem: Passing values is deprecated - Solution: If you need to disable the behavior, omit the option, - otherwise, pass the option without a value + Solution: how we should deal with this option being `true` in config but user want to disable it in command line for 4.x? DEPRECATION, ); } return match ($allOrNothingOption) { self::ABSENT_CONFIG_VALUE => null, - null => false, + null => true, default => (bool) $allOrNothingOption, }; } diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/ExecuteCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/ExecuteCommandTest.php index e0216358a..03a1c8318 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/ExecuteCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/ExecuteCommandTest.php @@ -172,7 +172,7 @@ public function testExecuteCancel(): void self::assertSame(1, $this->executeCommandTester->getStatusCode()); } - public function testExecuteAllOrNothingDefaultsToFalse(): void + public function testExecuteAllOrNothingDefaultsToTrue(): void { $this->executeCommandTester->setInputs(['yes']); @@ -180,7 +180,7 @@ public function testExecuteAllOrNothingDefaultsToFalse(): void ->expects(self::once()) ->method('migrate') ->willReturnCallback(static function (MigrationPlanList $planList, MigratorConfiguration $configuration): array { - self::assertFalse($configuration->isAllOrNothing()); + self::assertTrue($configuration->isAllOrNothing()); return ['A']; }); diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrateCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrateCommandTest.php index dd3876f71..32778a81d 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrateCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrateCommandTest.php @@ -381,7 +381,7 @@ public static function allOrNothing(): Generator 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], false, false]; + yield [false, ['--all-or-nothing' => null], true, false]; yield [true, ['--all-or-nothing' => false], false]; yield [true, ['--all-or-nothing' => 0], false];