Skip to content

Commit 47af29e

Browse files
authored
Merge pull request #1381 from agustingomes/GH-1379/improve-deprecation-expectation-check
GH-1379: Improve Deprecation thrown check + logic
2 parents 78484f9 + f726a5f commit 47af29e

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Doctrine\Migrations\Exception\NoMigrationsToExecute;
99
use Doctrine\Migrations\Exception\UnknownMigrationVersion;
1010
use Doctrine\Migrations\Metadata\ExecutedMigrationsList;
11+
use Doctrine\Migrations\Tools\Console\ConsoleInputMigratorConfigurationFactory;
1112
use Symfony\Component\Console\Attribute\AsCommand;
1213
use Symfony\Component\Console\Formatter\OutputFormatter;
1314
use Symfony\Component\Console\Input\InputArgument;
@@ -78,7 +79,7 @@ protected function configure(): void
7879
null,
7980
InputOption::VALUE_OPTIONAL,
8081
'Wrap the entire migration in a transaction.',
81-
'notprovided',
82+
ConsoleInputMigratorConfigurationFactory::ABSENT_CONFIG_VALUE,
8283
)
8384
->setHelp(<<<'EOT'
8485
The <info>%command.name%</info> command executes a migration to a specified version or the latest available version:

lib/Doctrine/Migrations/Tools/Console/ConsoleInputMigratorConfigurationFactory.php

+8-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
class ConsoleInputMigratorConfigurationFactory implements MigratorConfigurationFactory
1313
{
14+
public const ABSENT_CONFIG_VALUE = 'notprovided';
15+
1416
public function __construct(private readonly Configuration $configuration)
1517
{
1618
}
@@ -36,7 +38,7 @@ private function determineAllOrNothingValueFrom(InputInterface $input): bool|nul
3638
$allOrNothingOption = $input->getOption('all-or-nothing');
3739
}
3840

39-
if ($wasOptionExplicitlyPassed && $allOrNothingOption !== null) {
41+
if ($wasOptionExplicitlyPassed && ($allOrNothingOption !== null && $allOrNothingOption !== self::ABSENT_CONFIG_VALUE)) {
4042
Deprecation::trigger(
4143
'doctrine/migrations',
4244
'https://github.com/doctrine/migrations/issues/1304',
@@ -49,10 +51,10 @@ private function determineAllOrNothingValueFrom(InputInterface $input): bool|nul
4951
);
5052
}
5153

52-
if ($allOrNothingOption === 'notprovided') {
53-
return null;
54-
}
55-
56-
return (bool) ($allOrNothingOption ?? false);
54+
return match ($allOrNothingOption) {
55+
self::ABSENT_CONFIG_VALUE => null,
56+
null => false,
57+
default => (bool) $allOrNothingOption,
58+
};
5759
}
5860
}

tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrateCommandTest.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -358,11 +358,10 @@ public function testExecuteMigrateAllOrNothing(bool $default, array $input, bool
358358
return ['A'];
359359
});
360360

361-
if ($expectDeprecation) {
362-
$this->expectDeprecationWithIdentifier(
363-
'https://github.com/doctrine/migrations/issues/1304',
364-
);
365-
}
361+
match ($expectDeprecation) {
362+
true => $this->expectDeprecationWithIdentifier('https://github.com/doctrine/migrations/issues/1304'),
363+
false => $this->expectNoDeprecationWithIdentifier('https://github.com/doctrine/migrations/issues/1304'),
364+
};
366365

367366
$this->migrateCommandTester->execute(
368367
$input,
@@ -388,8 +387,8 @@ public static function allOrNothing(): Generator
388387
yield [true, ['--all-or-nothing' => 0], false];
389388
yield [true, ['--all-or-nothing' => '0'], false];
390389

391-
yield [true, [], true];
392-
yield [false, [], false];
390+
yield [true, [], true, false];
391+
yield [false, [], false, false];
393392
}
394393

395394
public function testExecuteMigrateCancelExecutedUnavailableMigrations(): void

0 commit comments

Comments
 (0)