Skip to content

Commit

Permalink
Merge pull request #1381 from agustingomes/GH-1379/improve-deprecatio…
Browse files Browse the repository at this point in the history
…n-expectation-check

GH-1379: Improve Deprecation thrown check + logic
  • Loading branch information
greg0ire authored Dec 5, 2023
2 parents 78484f9 + f726a5f commit 47af29e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 <info>%command.name%</info> command executes a migration to a specified version or the latest available version:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

class ConsoleInputMigratorConfigurationFactory implements MigratorConfigurationFactory
{
public const ABSENT_CONFIG_VALUE = 'notprovided';

public function __construct(private readonly Configuration $configuration)
{
}
Expand All @@ -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',
Expand All @@ -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,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,10 @@ public function testExecuteMigrateAllOrNothing(bool $default, array $input, bool
return ['A'];
});

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

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

yield [true, [], true];
yield [false, [], false];
yield [true, [], true, false];
yield [false, [], false, false];
}

public function testExecuteMigrateCancelExecutedUnavailableMigrations(): void
Expand Down

0 comments on commit 47af29e

Please sign in to comment.