Skip to content

Commit

Permalink
Returns empty array when processing 0 of 0 instead of exception.
Browse files Browse the repository at this point in the history
This is consistent with other application behaviour.

Processing "0 of 1" and "1 of 1" migrations throws no exception,
but simply passes on an array(). "0 of 0" would turn out an exception
code which makes the script return an exit code to the system.
  • Loading branch information
Brian Graham committed Jan 2, 2014
1 parent 5d83a66 commit 1cbb305
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 20 deletions.
6 changes: 1 addition & 5 deletions lib/Doctrine/DBAL/Migrations/Migration.php
Expand Up @@ -131,7 +131,7 @@ public function migrate($to = null, $dryRun = false)
$direction = $from > $to ? 'down' : 'up';
$migrationsToExecute = $this->configuration->getMigrationsToExecute($direction, $to);

if ($from === $to && empty($migrationsToExecute) && $migrations) {
if ($from === $to && empty($migrationsToExecute) && empty($migrations)) {
return array();
}

Expand All @@ -141,10 +141,6 @@ public function migrate($to = null, $dryRun = false)
$this->outputWriter->write(sprintf('Executing dry run of migration <info>%s</info> to <comment>%s</comment> from <comment>%s</comment>', $direction, $to, $from));
}

if (empty($migrationsToExecute)) {
throw MigrationException::noMigrationsToExecute();
}

$sql = array();
$time = 0;
foreach ($migrationsToExecute as $version) {
Expand Down
5 changes: 0 additions & 5 deletions lib/Doctrine/DBAL/Migrations/MigrationException.php
Expand Up @@ -39,11 +39,6 @@ public static function migrationsDirectoryRequired()
return new self('Migrations directory must be configured in order to use Doctrine migrations.', 3);
}

public static function noMigrationsToExecute()
{
return new self('Could not find any migrations to execute.', 4);
}

public static function unknownMigrationVersion($version)
{
return new self(sprintf('Could not find migration version %s', $version), 5);
Expand Down
11 changes: 11 additions & 0 deletions tests/Doctrine/DBAL/Migrations/Tests/Functional/FunctionalTest.php
Expand Up @@ -26,6 +26,15 @@ public function setUp()
$this->config->setMigrationsDirectory('.');
}

public function testMigrateWithoutMigrationsReturnsEmpty()
{
$migration = new \Doctrine\DBAL\Migrations\Migration($this->config);

$sql = $migration->migrate();

$this->assertEquals(array(), $sql);;
}

public function testMigrateUp()
{
$version = new \Doctrine\DBAL\Migrations\Version($this->config, 1, 'Doctrine\DBAL\Migrations\Tests\Functional\MigrationMigrateUp');
Expand Down Expand Up @@ -244,12 +253,14 @@ public function testMigrateToCurrentVersionReturnsEmpty()
$this->config->registerMigration(2, 'Doctrine\DBAL\Migrations\Tests\Functional\MigrationMigrateFurther');

$migration = new \Doctrine\DBAL\Migrations\Migration($this->config);

$migration->migrate();

$sql = $migration->migrate();

$this->assertEquals(array(), $sql);;
}

}

class MigrateAddSqlTest extends \Doctrine\DBAL\Migrations\AbstractMigration
Expand Down
10 changes: 0 additions & 10 deletions tests/Doctrine/DBAL/Migrations/Tests/MigrationTest.php
Expand Up @@ -23,14 +23,4 @@ public function testMigrateToUnknownVersionThrowsException()
$this->setExpectedException('Doctrine\DBAL\Migrations\MigrationException', 'Could not find migration version 1234');
$migration->migrate('1234');
}

/**
* @expectedException \Doctrine\DBAL\Migrations\MigrationException
*/
public function testMigrateWithNoMigrationsThrowsException()
{
$migration = new Migration($this->config);

$sql = $migration->migrate();
}
}

0 comments on commit 1cbb305

Please sign in to comment.