diff --git a/Command/DoctrineCommand.php b/Command/DoctrineCommand.php index 5a9a6be..088f3e5 100644 --- a/Command/DoctrineCommand.php +++ b/Command/DoctrineCommand.php @@ -4,8 +4,8 @@ namespace Doctrine\Bundle\MigrationsBundle\Command; use Doctrine\Bundle\DoctrineBundle\Command\DoctrineCommand as BaseCommand; -use Doctrine\DBAL\Migrations\Configuration\AbstractFileConfiguration; -use Doctrine\DBAL\Migrations\Configuration\Configuration; +use Doctrine\Migrations\Configuration\AbstractFileConfiguration; +use Doctrine\Migrations\Configuration\Configuration; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; @@ -53,7 +53,11 @@ public static function configureMigrations(ContainerInterface $container, Config } // Migrations is not register from configuration loader if (!($configuration instanceof AbstractFileConfiguration)) { - $configuration->registerMigrationsFromDirectory($configuration->getMigrationsDirectory()); + $migrationsDirectory = $configuration->getMigrationsDirectory(); + + if ($migrationsDirectory !== null) { + $configuration->registerMigrationsFromDirectory($migrationsDirectory); + } } if (method_exists($configuration, 'getCustomTemplate') && !$configuration->getCustomTemplate()) { diff --git a/Command/MigrationsDiffDoctrineCommand.php b/Command/MigrationsDiffDoctrineCommand.php index 92f742c..28a4f6c 100644 --- a/Command/MigrationsDiffDoctrineCommand.php +++ b/Command/MigrationsDiffDoctrineCommand.php @@ -3,7 +3,7 @@ namespace Doctrine\Bundle\MigrationsBundle\Command; -use Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand; +use Doctrine\Migrations\Tools\Console\Command\DiffCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -17,7 +17,7 @@ */ class MigrationsDiffDoctrineCommand extends DiffCommand { - protected function configure() + protected function configure() : void { parent::configure(); @@ -29,13 +29,13 @@ protected function configure() ; } - public function execute(InputInterface $input, OutputInterface $output) + public function initialize(InputInterface $input, OutputInterface $output) : void { Helper\DoctrineCommandHelper::setApplicationHelper($this->getApplication(), $input); $configuration = $this->getMigrationConfiguration($input, $output); DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration); - return parent::execute($input, $output); + parent::initialize($input, $output); } } diff --git a/Command/MigrationsExecuteDoctrineCommand.php b/Command/MigrationsExecuteDoctrineCommand.php index 67c2968..c72f2a6 100644 --- a/Command/MigrationsExecuteDoctrineCommand.php +++ b/Command/MigrationsExecuteDoctrineCommand.php @@ -7,7 +7,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputOption; -use Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand; +use Doctrine\Migrations\Tools\Console\Command\ExecuteCommand; /** * Command for executing single migrations up or down manually. @@ -17,7 +17,7 @@ */ class MigrationsExecuteDoctrineCommand extends ExecuteCommand { - protected function configure() + protected function configure() : void { parent::configure(); @@ -29,18 +29,23 @@ protected function configure() ; } - public function execute(InputInterface $input, OutputInterface $output) + public function initialize(InputInterface $input, OutputInterface $output) : void + { + Helper\DoctrineCommandHelper::setApplicationHelper($this->getApplication(), $input); + + $configuration = $this->getMigrationConfiguration($input, $output); + DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration); + + parent::initialize($input, $output); + } + + public function execute(InputInterface $input, OutputInterface $output) : ?int { // EM and DB options cannot be set at same time if (null !== $input->getOption('em') && null !== $input->getOption('db')) { throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.'); } - Helper\DoctrineCommandHelper::setApplicationHelper($this->getApplication(), $input); - - $configuration = $this->getMigrationConfiguration($input, $output); - DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration); - return parent::execute($input, $output); } } diff --git a/Command/MigrationsGenerateDoctrineCommand.php b/Command/MigrationsGenerateDoctrineCommand.php index fbe4706..a29d38f 100644 --- a/Command/MigrationsGenerateDoctrineCommand.php +++ b/Command/MigrationsGenerateDoctrineCommand.php @@ -7,7 +7,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputOption; -use Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand; +use Doctrine\Migrations\Tools\Console\Command\GenerateCommand; /** * Command for generating new blank migration classes @@ -17,7 +17,7 @@ */ class MigrationsGenerateDoctrineCommand extends GenerateCommand { - protected function configure() + protected function configure() : void { parent::configure(); @@ -29,18 +29,23 @@ protected function configure() ; } - public function execute(InputInterface $input, OutputInterface $output) + public function initialize(InputInterface $input, OutputInterface $output) : void + { + Helper\DoctrineCommandHelper::setApplicationHelper($this->getApplication(), $input); + + $configuration = $this->getMigrationConfiguration($input, $output); + DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration); + + parent::initialize($input, $output); + } + + public function execute(InputInterface $input, OutputInterface $output) : ?int { // EM and DB options cannot be set at same time if (null !== $input->getOption('em') && null !== $input->getOption('db')) { throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.'); } - Helper\DoctrineCommandHelper::setApplicationHelper($this->getApplication(), $input); - - $configuration = $this->getMigrationConfiguration($input, $output); - DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration); - return parent::execute($input, $output); } } diff --git a/Command/MigrationsLatestDoctrineCommand.php b/Command/MigrationsLatestDoctrineCommand.php index b5d32b0..1a64fa3 100644 --- a/Command/MigrationsLatestDoctrineCommand.php +++ b/Command/MigrationsLatestDoctrineCommand.php @@ -7,7 +7,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputOption; -use Doctrine\DBAL\Migrations\Tools\Console\Command\LatestCommand; +use Doctrine\Migrations\Tools\Console\Command\LatestCommand; /** * Command for outputting the latest version number. @@ -17,7 +17,7 @@ */ class MigrationsLatestDoctrineCommand extends LatestCommand { - protected function configure() + protected function configure() : void { parent::configure(); @@ -29,18 +29,23 @@ protected function configure() ; } - public function execute(InputInterface $input, OutputInterface $output) + public function initialize(InputInterface $input, OutputInterface $output) : void + { + Helper\DoctrineCommandHelper::setApplicationHelper($this->getApplication(), $input); + + $configuration = $this->getMigrationConfiguration($input, $output); + DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration); + + parent::initialize($input, $output); + } + + public function execute(InputInterface $input, OutputInterface $output) : ?int { // EM and DB options cannot be set at same time if (null !== $input->getOption('em') && null !== $input->getOption('db')) { throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.'); } - Helper\DoctrineCommandHelper::setApplicationHelper($this->getApplication(), $input); - - $configuration = $this->getMigrationConfiguration($input, $output); - DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration); - return parent::execute($input, $output); } } diff --git a/Command/MigrationsMigrateDoctrineCommand.php b/Command/MigrationsMigrateDoctrineCommand.php index 6db083e..de2363c 100644 --- a/Command/MigrationsMigrateDoctrineCommand.php +++ b/Command/MigrationsMigrateDoctrineCommand.php @@ -7,7 +7,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputOption; -use Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand; +use Doctrine\Migrations\Tools\Console\Command\MigrateCommand; /** * Command for executing a migration to a specified version or the latest available version. @@ -17,7 +17,7 @@ */ class MigrationsMigrateDoctrineCommand extends MigrateCommand { - protected function configure() + protected function configure() : void { parent::configure(); @@ -29,18 +29,23 @@ protected function configure() ; } - public function execute(InputInterface $input, OutputInterface $output) + public function initialize(InputInterface $input, OutputInterface $output) : void { - // EM and DB options cannot be set at same time - if (null !== $input->getOption('em') && null !== $input->getOption('db')) { - throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.'); - } - Helper\DoctrineCommandHelper::setApplicationHelper($this->getApplication(), $input); $configuration = $this->getMigrationConfiguration($input, $output); DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration); + parent::initialize($input, $output); + } + + public function execute(InputInterface $input, OutputInterface $output) : ?int + { + // EM and DB options cannot be set at same time + if (null !== $input->getOption('em') && null !== $input->getOption('db')) { + throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.'); + } + return parent::execute($input, $output); } } diff --git a/Command/MigrationsStatusDoctrineCommand.php b/Command/MigrationsStatusDoctrineCommand.php index 204b2e9..f5a11d6 100644 --- a/Command/MigrationsStatusDoctrineCommand.php +++ b/Command/MigrationsStatusDoctrineCommand.php @@ -7,7 +7,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputOption; -use Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand; +use Doctrine\Migrations\Tools\Console\Command\StatusCommand; /** * Command to view the status of a set of migrations. @@ -17,7 +17,7 @@ */ class MigrationsStatusDoctrineCommand extends StatusCommand { - protected function configure() + protected function configure() : void { parent::configure(); @@ -29,18 +29,23 @@ protected function configure() ; } - public function execute(InputInterface $input, OutputInterface $output) + public function initialize(InputInterface $input, OutputInterface $output) : void + { + Helper\DoctrineCommandHelper::setApplicationHelper($this->getApplication(), $input); + + $configuration = $this->getMigrationConfiguration($input, $output); + DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration); + + parent::initialize($input, $output); + } + + public function execute(InputInterface $input, OutputInterface $output) : ?int { // EM and DB options cannot be set at same time if (null !== $input->getOption('em') && null !== $input->getOption('db')) { throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.'); } - Helper\DoctrineCommandHelper::setApplicationHelper($this->getApplication(), $input); - - $configuration = $this->getMigrationConfiguration($input, $output); - DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration); - return parent::execute($input, $output); } } diff --git a/Command/MigrationsVersionDoctrineCommand.php b/Command/MigrationsVersionDoctrineCommand.php index 354c7ed..ce9d4fd 100644 --- a/Command/MigrationsVersionDoctrineCommand.php +++ b/Command/MigrationsVersionDoctrineCommand.php @@ -7,7 +7,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputOption; -use Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand; +use Doctrine\Migrations\Tools\Console\Command\VersionCommand; /** * Command for manually adding and deleting migration versions from the version table. @@ -17,7 +17,7 @@ */ class MigrationsVersionDoctrineCommand extends VersionCommand { - protected function configure() + protected function configure() : void { parent::configure(); @@ -29,18 +29,23 @@ protected function configure() ; } - public function execute(InputInterface $input, OutputInterface $output) + public function initialize(InputInterface $input, OutputInterface $output) : void { - // EM and DB options cannot be set at same time - if (null !== $input->getOption('em') && null !== $input->getOption('db')) { - throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.'); - } - Helper\DoctrineCommandHelper::setApplicationHelper($this->getApplication(), $input); $configuration = $this->getMigrationConfiguration($input, $output); DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration); + parent::initialize($input, $output); + } + + public function execute(InputInterface $input, OutputInterface $output) : ?int + { + // EM and DB options cannot be set at same time + if (null !== $input->getOption('em') && null !== $input->getOption('db')) { + throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.'); + } + return parent::execute($input, $output); } } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 017342b..9f3704e 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -51,7 +51,7 @@ public function getConfigTreeBuilder() ->validate() ->ifString() ->then(function ($v) { - return constant('Doctrine\DBAL\Migrations\Configuration\Configuration::VERSIONS_ORGANIZATION_'.strtoupper($v)); + return constant('Doctrine\Migrations\Configuration\Configuration::VERSIONS_ORGANIZATION_'.strtoupper($v)); }) ->end() ->end() @@ -71,7 +71,7 @@ private function getOrganizeMigrationsModes() { $constPrefix = 'VERSIONS_ORGANIZATION_'; $prefixLen = strlen($constPrefix); - $refClass = new \ReflectionClass('Doctrine\DBAL\Migrations\Configuration\Configuration'); + $refClass = new \ReflectionClass('Doctrine\Migrations\Configuration\Configuration'); $constsArray = $refClass->getConstants(); $namesArray = array(); diff --git a/Resources/doc/index.rst b/Resources/doc/index.rst index d67e7b8..95b9d2d 100644 --- a/Resources/doc/index.rst +++ b/Resources/doc/index.rst @@ -20,7 +20,7 @@ First, install the bundle with composer: .. code-block:: bash - $ composer require doctrine/doctrine-migrations-bundle "^1.0" + $ composer require doctrine/doctrine-migrations-bundle "^2.0" If everything worked, the ``DoctrineMigrationsBundle`` can now be found at ``vendor/doctrine/doctrine-migrations-bundle``. @@ -116,17 +116,17 @@ like the following:: namespace Application\Migrations; - use Doctrine\DBAL\Migrations\AbstractMigration, - Doctrine\DBAL\Schema\Schema; + use Doctrine\DBAL\Schema\Schema; + use Doctrine\Migrations\AbstractMigration; class Version20100621140655 extends AbstractMigration { - public function up(Schema $schema) + public function up(Schema $schema) : void { } - public function down(Schema $schema) + public function down(Schema $schema) : void { } diff --git a/Tests/Command/DoctrineCommandTest.php b/Tests/Command/DoctrineCommandTest.php index 89fb12c..df160e6 100644 --- a/Tests/Command/DoctrineCommandTest.php +++ b/Tests/Command/DoctrineCommandTest.php @@ -3,7 +3,7 @@ namespace Doctrine\Bundle\MigrationsBundle\Tests\DependencyInjection; use Doctrine\Bundle\MigrationsBundle\Command\DoctrineCommand; -use Doctrine\DBAL\Migrations\Configuration\Configuration; +use Doctrine\Migrations\Configuration\Configuration; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; use PHPUnit\Framework\TestCase; @@ -12,13 +12,33 @@ class DoctrineCommandTest extends TestCase { public function testConfigureMigrations() { - $configurationMock = $this->getMockBuilder('Doctrine\DBAL\Migrations\Configuration\Configuration') + $configurationMock = $this->getMockBuilder('Doctrine\Migrations\Configuration\Configuration') ->disableOriginalConstructor() ->getMock(); $configurationMock->method('getMigrations') ->willReturn(array()); + $configurationMock->expects($this->once()) + ->method('setMigrationsDirectory') + ->with(__DIR__.'/../../'); + + $configurationMock->expects($this->once()) + ->method('setMigrationsNamespace') + ->with('test'); + + $configurationMock->expects($this->once()) + ->method('setName') + ->with('test'); + + $configurationMock->expects($this->once()) + ->method('setMigrationsTableName') + ->with('test'); + + $configurationMock->expects($this->once()) + ->method('setMigrationsAreOrganizedByYear') + ->with(true); + DoctrineCommand::configureMigrations($this->getContainer(), $configurationMock); } diff --git a/Tests/DependencyInjection/DoctrineMigrationsExtensionTest.php b/Tests/DependencyInjection/DoctrineMigrationsExtensionTest.php index 87b7928..8003177 100644 --- a/Tests/DependencyInjection/DoctrineMigrationsExtensionTest.php +++ b/Tests/DependencyInjection/DoctrineMigrationsExtensionTest.php @@ -3,7 +3,7 @@ namespace Doctrine\Bundle\MigrationsBundle\Tests\DependencyInjection; use Doctrine\Bundle\MigrationsBundle\DependencyInjection\DoctrineMigrationsExtension; -use Doctrine\DBAL\Migrations\Configuration\Configuration; +use Doctrine\Migrations\Configuration\Configuration; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; use PHPUnit\Framework\TestCase; diff --git a/composer.json b/composer.json index 63918f5..2cad2e6 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "php": ">=5.4.0", "symfony/framework-bundle": "~2.7|~3.3|~4.0", "doctrine/doctrine-bundle": "~1.0", - "doctrine/migrations": "^1.1" + "doctrine/migrations": "^2.0@dev" }, "require-dev": { "phpunit/phpunit": "^4.8.36|^5.7|^6.4" @@ -33,7 +33,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.3-dev" + "dev-master": "2.0-dev" } } }