From 642914a45a75e66fb8dd6aec4c2b579619ca1683 Mon Sep 17 00:00:00 2001 From: Agustin Gomes Date: Thu, 30 Nov 2023 12:50:24 +0100 Subject: [PATCH] GH-1379: Improve Deprecation thrown check + logic Unfortunately as part of the previous improvement to determine whether a deprecation is thrown, validating that the deprecation was not thrown ended up not being added explicitly. In addition, adds the explicit expectation of not throwing the deprecation whenever the `--all-or-nothing` is not indicated, which was the root cause originating the issue. --- .../Tools/Console/Command/MigrateCommand.php | 3 ++- .../ConsoleInputMigratorConfigurationFactory.php | 14 ++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php index 76576724f..2084b6f6e 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php @@ -8,6 +8,7 @@ use Doctrine\Migrations\Exception\NoMigrationsToExecute; use Doctrine\Migrations\Exception\UnknownMigrationVersion; use Doctrine\Migrations\Metadata\ExecutedMigrationsList; +use Doctrine\Migrations\Tools\Console\ConsoleInputMigratorConfigurationFactory; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Formatter\OutputFormatter; use Symfony\Component\Console\Input\InputArgument; @@ -78,7 +79,7 @@ protected function configure(): void null, InputOption::VALUE_OPTIONAL, 'Wrap the entire migration in a transaction.', - 'notprovided', + ConsoleInputMigratorConfigurationFactory::ABSENT_CONFIG_VALUE, ) ->setHelp(<<<'EOT' The %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 d3673a2e2..fffc450ba 100644 --- a/lib/Doctrine/Migrations/Tools/Console/ConsoleInputMigratorConfigurationFactory.php +++ b/lib/Doctrine/Migrations/Tools/Console/ConsoleInputMigratorConfigurationFactory.php @@ -11,6 +11,8 @@ class ConsoleInputMigratorConfigurationFactory implements MigratorConfigurationFactory { + public const ABSENT_CONFIG_VALUE = 'notprovided'; + public function __construct(private readonly Configuration $configuration) { } @@ -36,7 +38,7 @@ private function determineAllOrNothingValueFrom(InputInterface $input): bool|nul $allOrNothingOption = $input->getOption('all-or-nothing'); } - if ($wasOptionExplicitlyPassed && $allOrNothingOption !== null) { + if ($wasOptionExplicitlyPassed && ($allOrNothingOption !== null && $allOrNothingOption !== self::ABSENT_CONFIG_VALUE)) { Deprecation::trigger( 'doctrine/migrations', 'https://github.com/doctrine/migrations/issues/1304', @@ -49,10 +51,10 @@ private function determineAllOrNothingValueFrom(InputInterface $input): bool|nul ); } - if ($allOrNothingOption === 'notprovided') { - return null; - } - - return (bool) ($allOrNothingOption ?? false); + return match ($allOrNothingOption) { + self::ABSENT_CONFIG_VALUE => null, + null => false, + default => (bool) $allOrNothingOption, + }; } }