From c01110e7392eb855b7f8b1c2d3bafca1a84bc8f8 Mon Sep 17 00:00:00 2001 From: Ryan Catlin Date: Tue, 16 Feb 2016 17:46:32 -0500 Subject: [PATCH 1/3] Configuration getVersion registers migrations if empty --- lib/Doctrine/DBAL/Migrations/Configuration/Configuration.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/Doctrine/DBAL/Migrations/Configuration/Configuration.php b/lib/Doctrine/DBAL/Migrations/Configuration/Configuration.php index 9900dfbf9e..402a48e815 100644 --- a/lib/Doctrine/DBAL/Migrations/Configuration/Configuration.php +++ b/lib/Doctrine/DBAL/Migrations/Configuration/Configuration.php @@ -454,6 +454,10 @@ public function getMigrations() */ public function getVersion($version) { + if (empty($this->migrations)) { + $this->registerMigrationsFromDirectory($this->getMigrationsDirectory()); + } + if (!isset($this->migrations[$version])) { throw MigrationException::unknownMigrationVersion($version); } From ef87b55acda8977e2915b994b0a3aebcf3d42918 Mon Sep 17 00:00:00 2001 From: Ryan Catlin Date: Wed, 17 Feb 2016 10:32:59 -0500 Subject: [PATCH 2/3] Added Tests for Configuration getVersion method --- .../Migrations/Tests/ConfigurationTest.php | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/Doctrine/DBAL/Migrations/Tests/ConfigurationTest.php b/tests/Doctrine/DBAL/Migrations/Tests/ConfigurationTest.php index 6a5fdff007..8a868846f5 100644 --- a/tests/Doctrine/DBAL/Migrations/Tests/ConfigurationTest.php +++ b/tests/Doctrine/DBAL/Migrations/Tests/ConfigurationTest.php @@ -3,6 +3,8 @@ namespace Doctrine\DBAL\Migrations\Tests; use Doctrine\DBAL\Migrations\Configuration\Configuration; +use Doctrine\DBAL\Migrations\MigrationException; +use Doctrine\DBAL\Migrations\Tests\Stub\Configuration\AutoloadVersions\Version1Test; class ConfigurationTest extends MigrationTestCase { @@ -190,6 +192,31 @@ public function testFormatVersion($version, $return) $this->assertEquals($return, $config->formatVersion($version)); } + /** + * @dataProvider getVersionProvider + * + * @param $version + */ + public function testGetVersion($version) + { + $config = $this->getSqliteConfiguration(); + $config->setMigrationsNamespace('Doctrine\DBAL\Migrations\Tests\Stub\Configuration\AutoloadVersions'); + $config->setMigrationsDirectory(__DIR__ . '/Stub/Configuration/AutoloadVersions'); + + $result = $config->getVersion($version); + + $this->assertNotNull($result); + } + + public function testGetVersionNotFound() + { + $this->setExpectedException(MigrationException::class); + + $config = $this->getSqliteConfiguration(); + + $config->getVersion('foo'); + } + /** * @dataProvider versionProvider */ @@ -212,4 +239,18 @@ public function versionProvider() ['20150202162811', '2015-02-02 16:28:11'] ]; } + + /** + * @return array + */ + public function getVersionProvider() + { + return [ + ['1Test'], + ['2Test'], + ['3Test'], + ['4Test'], + ['5Test'], + ]; + } } From e8b5f5d791cdd7e6947197ab040a73272ec7321c Mon Sep 17 00:00:00 2001 From: Ryan Catlin Date: Wed, 17 Feb 2016 10:35:42 -0500 Subject: [PATCH 3/3] Removed unused use statement; clarify versions are autoload versions --- tests/Doctrine/DBAL/Migrations/Tests/ConfigurationTest.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/Doctrine/DBAL/Migrations/Tests/ConfigurationTest.php b/tests/Doctrine/DBAL/Migrations/Tests/ConfigurationTest.php index 8a868846f5..75d4ce7842 100644 --- a/tests/Doctrine/DBAL/Migrations/Tests/ConfigurationTest.php +++ b/tests/Doctrine/DBAL/Migrations/Tests/ConfigurationTest.php @@ -4,7 +4,6 @@ use Doctrine\DBAL\Migrations\Configuration\Configuration; use Doctrine\DBAL\Migrations\MigrationException; -use Doctrine\DBAL\Migrations\Tests\Stub\Configuration\AutoloadVersions\Version1Test; class ConfigurationTest extends MigrationTestCase { @@ -193,7 +192,7 @@ public function testFormatVersion($version, $return) } /** - * @dataProvider getVersionProvider + * @dataProvider autoloadVersionProvider * * @param $version */ @@ -243,7 +242,7 @@ public function versionProvider() /** * @return array */ - public function getVersionProvider() + public function autoloadVersionProvider() { return [ ['1Test'],