diff --git a/lib/Doctrine/Migration.php b/lib/Doctrine/Migration.php index 0208ce54..615c792e 100644 --- a/lib/Doctrine/Migration.php +++ b/lib/Doctrine/Migration.php @@ -559,4 +559,4 @@ protected function _createMigrationTable() return false; } } -} \ No newline at end of file +} diff --git a/tests/DoctrineTest/Doctrine_UnitTestCase.php b/tests/DoctrineTest/Doctrine_UnitTestCase.php index 3fa7bcbc..5715cceb 100644 --- a/tests/DoctrineTest/Doctrine_UnitTestCase.php +++ b/tests/DoctrineTest/Doctrine_UnitTestCase.php @@ -142,13 +142,14 @@ public function init() if (count($e) > 3) { $driver = $e[2]; - switch($e[2]) { + + switch($driver) { case 'Mysql': case 'Mssql': case 'Oracle': case 'Pgsql': case 'Sqlite': - $this->driverName = $e[2]; + $this->driverName = $driver; break; } } @@ -227,7 +228,14 @@ public function prepareTables() { } } - $this->conn->export->exportClasses($this->tables); + + foreach ($this->tables as $table) { + try { + $this->conn->export->exportClasses(array($table)); + } catch (Doctrine_Export_Exception $e) { + } + } + $this->objTable = $this->connection->getTable('User'); } public function prepareData() @@ -307,6 +315,13 @@ public function getDeclaration($type) return $this->dataDict->getPortableDeclaration(array('type' => $type, 'name' => 'colname', 'length' => 1, 'fixed' => true)); } + protected function openAndBindMysqlConnection() + { + $this->dbh = new PDO(getenv('MYSQL_DSN')); + + $this->conn = $this->connection = $this->openAdditionalConnection($this->dbh); + } + protected function openAdditionalConnection($adapter = null, $name = null) { $connection = $this->manager->openConnection($adapter, $name); @@ -321,5 +336,7 @@ private function closeAdditionalConnections() foreach ($this->additionalConnections as $connection) { $this->manager->closeConnection($connection); } + + $this->conn = $this->connection = Doctrine_Manager::getInstance()->getCurrentConnection(); } } diff --git a/tests/MigrationTestCase.php b/tests/MigrationTestCase.php index 7b718ba5..d5d28646 100644 --- a/tests/MigrationTestCase.php +++ b/tests/MigrationTestCase.php @@ -127,4 +127,35 @@ public function testMigrationClassNameInflected() $this->assertTrue($code); } } + + public function test_afterSuccessfullMigration_willSetMigratedVersionAsCurrentVersionInMysqlDB() + { + $this->openAndBindMysqlConnection(); + + parent::prepareTables(); + + $migration = new Doctrine_Migration('migration_classes'); + $migration->setCurrentVersion(3); + + $migration->migrate(4); + $this->assertEqual(4, $migration->getCurrentVersion()); + } + + public function test_afterFailedMigration_willKeepCurrentVersionInMysqlDB() + { + $this->openAndBindMysqlConnection(); + + parent::prepareTables(); + + $migration = new Doctrine_Migration('migration_classes'); + $migration->setCurrentVersion(0); + + try { + $migration->migrate(1); + + $this->fail('migration must fail'); + } catch (Doctrine_Migration_Exception $e) { + $this->assertEqual(0, $migration->getCurrentVersion()); + } + } }