diff --git a/docs/en/reference/configuration.rst b/docs/en/reference/configuration.rst index d451c1ac3..7b92c7520 100644 --- a/docs/en/reference/configuration.rst +++ b/docs/en/reference/configuration.rst @@ -348,17 +348,21 @@ Now update your ``cli-config.php`` in the root of your project to look like the require 'vendor/autoload.php'; use Doctrine\ORM\EntityManager; - use Doctrine\ORM\Tools\Setup; + use Doctrine\ORM\ORMSetup; use Doctrine\Migrations\Configuration\EntityManager\ExistingEntityManager; use Doctrine\Migrations\DependencyFactory; + use Doctrine\Migrations\Configuration\Migration\PhpFile; + use Doctrine\DBAL\DriverManager; $config = new PhpFile('migrations.php'); // Or use one of the Doctrine\Migrations\Configuration\Configuration\* loaders $paths = [__DIR__.'/lib/MyProject/Entities']; $isDevMode = true; - $ORMconfig = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode); - $entityManager = EntityManager::create(['driver' => 'pdo_sqlite', 'memory' => true], $ORMconfig); + $ORMConfig = ORMSetup::createAttributeMetadataConfiguration($paths, $isDevMode); + $connection = DriverManager::getConnection(['driver' => 'pdo_sqlite', 'memory' => true]); + + $entityManager = new EntityManager($connection, $ORMConfig); return DependencyFactory::fromEntityManager($config, new ExistingEntityManager($entityManager)); 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, + }; } } diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrateCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrateCommandTest.php index d0dd54da3..dd3876f71 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrateCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrateCommandTest.php @@ -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, @@ -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