From 533595134247c0c9f2e16c9a17fd1776a30303a4 Mon Sep 17 00:00:00 2001 From: e-jevdokimovs Date: Tue, 17 Jan 2023 13:59:21 +0200 Subject: [PATCH] Fixed `all-or-nothing` console input value determination. This fixes a bug that was introduced in #1296 where the configuration value of allOrNothing got set to true if the command didn't have an all-or-nothing option. Now the value is set from input options only if the command that is being executed has an `all-or-nothing` option. --- ...nsoleInputMigratorConfigurationFactory.php | 8 +++---- .../Console/Command/ExecuteCommandTest.php | 22 +++++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/Migrations/Tools/Console/ConsoleInputMigratorConfigurationFactory.php b/lib/Doctrine/Migrations/Tools/Console/ConsoleInputMigratorConfigurationFactory.php index 853b28913..3c6da4a99 100644 --- a/lib/Doctrine/Migrations/Tools/Console/ConsoleInputMigratorConfigurationFactory.php +++ b/lib/Doctrine/Migrations/Tools/Console/ConsoleInputMigratorConfigurationFactory.php @@ -31,12 +31,12 @@ public function getMigratorConfiguration(InputInterface $input): MigratorConfigu private function determineAllOrNothingValueFrom(InputInterface $input): ?bool { - $allOrNothingOption = null; - - if ($input->hasOption('all-or-nothing')) { - $allOrNothingOption = $input->getOption('all-or-nothing'); + if (! $input->hasOption('all-or-nothing')) { + return null; } + $allOrNothingOption = $input->getOption('all-or-nothing'); + if ($allOrNothingOption === 'notprovided') { return null; } diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/ExecuteCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/ExecuteCommandTest.php index d4106af29..a4431dab8 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/ExecuteCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/ExecuteCommandTest.php @@ -177,6 +177,28 @@ public function testExecuteCancel(): void self::assertSame(1, $this->executeCommandTester->getStatusCode()); } + public function testExecuteAllOrNothingDefaultsToFalse(): void + { + $this->executeCommandTester->setInputs(['yes']); + + $this->migrator + ->expects(self::once()) + ->method('migrate') + ->willReturnCallback(static function (MigrationPlanList $planList, MigratorConfiguration $configuration): array { + self::assertFalse($configuration->isAllOrNothing()); + + return ['A']; + }); + + $this->executeCommandTester->execute([ + 'versions' => ['1'], + '--down' => true, + ]); + + self::assertSame(0, $this->executeCommandTester->getStatusCode()); + self::assertStringContainsString('[notice] Executing 1 up', trim($this->executeCommandTester->getDisplay(true))); + } + protected function setUp(): void { $connection = $this->getSqliteConnection();