Skip to content

Commit

Permalink
Updating DoctrineMigrationsBundle for Doctrine Migrations 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jwage committed Jun 4, 2018
1 parent 04109e6 commit 74c6db7
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 40 deletions.
10 changes: 7 additions & 3 deletions Command/DoctrineCommand.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down
6 changes: 3 additions & 3 deletions Command/MigrationsDiffDoctrineCommand.php
Expand Up @@ -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;
Expand All @@ -17,7 +17,7 @@
*/
class MigrationsDiffDoctrineCommand extends DiffCommand
{
protected function configure()
protected function configure() : void
{
parent::configure();

Expand All @@ -29,7 +29,7 @@ protected function configure()
;
}

public function execute(InputInterface $input, OutputInterface $output)
public function execute(InputInterface $input, OutputInterface $output) : ?int
{
Helper\DoctrineCommandHelper::setApplicationHelper($this->getApplication(), $input);

Expand Down
8 changes: 4 additions & 4 deletions Command/MigrationsExecuteDoctrineCommand.php
Expand Up @@ -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.
Expand All @@ -17,7 +17,7 @@
*/
class MigrationsExecuteDoctrineCommand extends ExecuteCommand
{
protected function configure()
protected function configure() : void
{
parent::configure();

Expand All @@ -29,7 +29,7 @@ protected function configure()
;
}

public function execute(InputInterface $input, OutputInterface $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')) {
Expand All @@ -40,7 +40,7 @@ public function execute(InputInterface $input, OutputInterface $output)

$configuration = $this->getMigrationConfiguration($input, $output);
DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);

return parent::execute($input, $output);
}
}
8 changes: 4 additions & 4 deletions Command/MigrationsGenerateDoctrineCommand.php
Expand Up @@ -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
Expand All @@ -17,7 +17,7 @@
*/
class MigrationsGenerateDoctrineCommand extends GenerateCommand
{
protected function configure()
protected function configure() : void
{
parent::configure();

Expand All @@ -29,7 +29,7 @@ protected function configure()
;
}

public function execute(InputInterface $input, OutputInterface $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')) {
Expand All @@ -40,7 +40,7 @@ public function execute(InputInterface $input, OutputInterface $output)

$configuration = $this->getMigrationConfiguration($input, $output);
DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);

return parent::execute($input, $output);
}
}
8 changes: 4 additions & 4 deletions Command/MigrationsLatestDoctrineCommand.php
Expand Up @@ -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.
Expand All @@ -17,7 +17,7 @@
*/
class MigrationsLatestDoctrineCommand extends LatestCommand
{
protected function configure()
protected function configure() : void
{
parent::configure();

Expand All @@ -29,7 +29,7 @@ protected function configure()
;
}

public function execute(InputInterface $input, OutputInterface $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')) {
Expand All @@ -40,7 +40,7 @@ public function execute(InputInterface $input, OutputInterface $output)

$configuration = $this->getMigrationConfiguration($input, $output);
DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);

return parent::execute($input, $output);
}
}
6 changes: 3 additions & 3 deletions Command/MigrationsMigrateDoctrineCommand.php
Expand Up @@ -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.
Expand All @@ -17,7 +17,7 @@
*/
class MigrationsMigrateDoctrineCommand extends MigrateCommand
{
protected function configure()
protected function configure() : void
{
parent::configure();

Expand All @@ -29,7 +29,7 @@ protected function configure()
;
}

public function execute(InputInterface $input, OutputInterface $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')) {
Expand Down
8 changes: 4 additions & 4 deletions Command/MigrationsStatusDoctrineCommand.php
Expand Up @@ -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.
Expand All @@ -17,7 +17,7 @@
*/
class MigrationsStatusDoctrineCommand extends StatusCommand
{
protected function configure()
protected function configure() : void
{
parent::configure();

Expand All @@ -29,7 +29,7 @@ protected function configure()
;
}

public function execute(InputInterface $input, OutputInterface $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')) {
Expand All @@ -40,7 +40,7 @@ public function execute(InputInterface $input, OutputInterface $output)

$configuration = $this->getMigrationConfiguration($input, $output);
DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);

return parent::execute($input, $output);
}
}
6 changes: 3 additions & 3 deletions Command/MigrationsVersionDoctrineCommand.php
Expand Up @@ -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.
Expand All @@ -17,7 +17,7 @@
*/
class MigrationsVersionDoctrineCommand extends VersionCommand
{
protected function configure()
protected function configure() : void
{
parent::configure();

Expand All @@ -29,7 +29,7 @@ protected function configure()
;
}

public function execute(InputInterface $input, OutputInterface $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')) {
Expand Down
4 changes: 2 additions & 2 deletions DependencyInjection/Configuration.php
Expand Up @@ -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()
Expand All @@ -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();

Expand Down
10 changes: 5 additions & 5 deletions Resources/doc/index.rst
Expand Up @@ -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``.
Expand Down Expand Up @@ -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
{

}
Expand Down
24 changes: 22 additions & 2 deletions Tests/Command/DoctrineCommandTest.php
Expand Up @@ -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;
Expand All @@ -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);
}

Expand Down
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -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"
Expand All @@ -33,7 +33,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.3-dev"
"dev-master": "2.0-dev"
}
}
}

0 comments on commit 74c6db7

Please sign in to comment.