From 5df49c5ad5dc2265401a54a3b9e6ecb3e7cda8d0 Mon Sep 17 00:00:00 2001 From: mike Date: Sat, 17 Oct 2015 10:15:37 +0200 Subject: [PATCH] Prevent the use of 0 as migration name as it is used internally and conflict --- lib/Doctrine/DBAL/Migrations/Finder/AbstractFinder.php | 9 ++++++++- .../Migrations/Tests/Finder/RecursiveRegexFinderTest.php | 8 ++++++++ .../Finder/_regression/NoVersionNamed0/Version0.php | 0 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/Doctrine/DBAL/Migrations/Tests/Finder/_regression/NoVersionNamed0/Version0.php diff --git a/lib/Doctrine/DBAL/Migrations/Finder/AbstractFinder.php b/lib/Doctrine/DBAL/Migrations/Finder/AbstractFinder.php index 4cf80c1726..3208d706db 100644 --- a/lib/Doctrine/DBAL/Migrations/Finder/AbstractFinder.php +++ b/lib/Doctrine/DBAL/Migrations/Finder/AbstractFinder.php @@ -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); } diff --git a/tests/Doctrine/DBAL/Migrations/Tests/Finder/RecursiveRegexFinderTest.php b/tests/Doctrine/DBAL/Migrations/Tests/Finder/RecursiveRegexFinderTest.php index a13eed0eae..d1cc63e673 100644 --- a/tests/Doctrine/DBAL/Migrations/Tests/Finder/RecursiveRegexFinderTest.php +++ b/tests/Doctrine/DBAL/Migrations/Tests/Finder/RecursiveRegexFinderTest.php @@ -26,6 +26,14 @@ class RecursiveRegexFinderTest extends MigrationTestCase { private $finder; + /** + * @expectedException InvalidArgumentException + */ + public function testVersionNameCausesErrorWhen0() + { + $this->finder->findMigrations(__DIR__.'/_regression/NoVersionNamed0'); + } + /** * @expectedException InvalidArgumentException */ diff --git a/tests/Doctrine/DBAL/Migrations/Tests/Finder/_regression/NoVersionNamed0/Version0.php b/tests/Doctrine/DBAL/Migrations/Tests/Finder/_regression/NoVersionNamed0/Version0.php new file mode 100644 index 0000000000..e69de29bb2