Skip to content

Commit

Permalink
Prevent the use of 0 as migration name as it is used internally and c…
Browse files Browse the repository at this point in the history
…onflict
  • Loading branch information
mikeSimonson committed Oct 17, 2015
1 parent bac31ab commit 5df49c5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/Doctrine/DBAL/Migrations/Finder/AbstractFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,14 @@ protected function loadMigrations($files, $namespace)
foreach ($files as $file) {
static::requireOnce($file);
$className = basename($file, '.php');
$version = substr($className, 7);
$version = (string) substr($className, 7);
if ($version === '0') {
throw new \InvalidArgumentException(sprintf(
'Cannot load a migrations with the name "%s" because it is a reserved number by doctrine migraitons' . PHP_EOL .
'It\'s used to revert all migrations including the first one.',
$version
));
}
$migrations[$version] = sprintf('%s\\%s', $namespace, $className);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ class RecursiveRegexFinderTest extends MigrationTestCase
{
private $finder;

/**
* @expectedException InvalidArgumentException
*/
public function testVersionNameCausesErrorWhen0()
{
$this->finder->findMigrations(__DIR__.'/_regression/NoVersionNamed0');
}

/**
* @expectedException InvalidArgumentException
*/
Expand Down
Empty file.

0 comments on commit 5df49c5

Please sign in to comment.