diff --git a/tests/Migration/MysqlTestCase.php b/tests/Migration/MysqlTestCase.php new file mode 100644 index 000000000..fcd562094 --- /dev/null +++ b/tests/Migration/MysqlTestCase.php @@ -0,0 +1,82 @@ +. + */ + +/** + * Doctrine_Migration_Mysql_TestCase + * + * @package Doctrine + * @author Konsta Vesterinen + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @category Object Relational Mapping + * @link www.phpdoctrine.com + * @since 1.0 + * @version $Revision$ + */ +class Doctrine_Migration_Mysql_TestCase extends Doctrine_UnitTestCase +{ + + protected $serverExists = false; + + public function setUp() + { + parent::setUp(); + try { + $dsn = 'mysql://doctrine_tester:d0cTrynR0x!@localhost/doctrine_unit_test'; + $this->conn = $this->manager->openConnection($dsn,'unit_test',true); + $this->conn->connect(); + $this->serverExists = true; + } catch (Exception $e){ + $this->serverExists = false; + } + } + + + public function testMigration() + { + if($this->serverExists){ + // Clean up any left over tables from broken test runs. + try { + $this->conn->export->dropTable('migration_test'); + $this->conn->export->dropTable('migration_version'); + } catch(Exception $e) { + } + + // New migration for the 'migration_classes' directory + $migration = new Doctrine_Migration('mysql_migration_classes'); + + // Make sure the current version is 0 + $this->assertEqual($migration->getCurrentVersion(), 0); + + // migrate to version latest version + $migration->migrate($migration->getLatestVersion()); + // Make sure the current version is latest version + $this->assertEqual($migration->getCurrentVersion(), $migration->getLatestVersion()); + + // now migrate back to original version + $migration->migrate(0); + + // Make sure the current version is 0 + $this->assertEqual($migration->getCurrentVersion(), 0); + } else { + $this->fail('server does not exist.'); + } + } +} \ No newline at end of file diff --git a/tests/MigrationTestCase.php b/tests/MigrationTestCase.php index 0a47aae3a..eb9e6cc60 100644 --- a/tests/MigrationTestCase.php +++ b/tests/MigrationTestCase.php @@ -36,13 +36,18 @@ class Doctrine_Migration_TestCase extends Doctrine_UnitTestCase { // New migration for the 'migration_classes' directory $migration = new Doctrine_Migration('migration_classes'); - - // migrate to version 3 - $migration->migrate(2); + + // Make sure the current version is 0 + $this->assertEqual($migration->getCurrentVersion(), 0); + + // migrate to version latest version + $migration->migrate($migration->getLatestVersion()); + // Make sure the current version is latest version + $this->assertEqual($migration->getCurrentVersion(), $migration->getLatestVersion()); // now migrate back to original version $migration->migrate(0); - + // Make sure the current version is 0 $this->assertEqual($migration->getCurrentVersion(), 0); } diff --git a/tests/migration_classes/002_change_column.php b/tests/migration_classes/002_change_column.php deleted file mode 100644 index 19aa032d0..000000000 --- a/tests/migration_classes/002_change_column.php +++ /dev/null @@ -1,13 +0,0 @@ -createTable('migration_test', array('field1' => array('type' => 'string'))); + $this->addColumn('migration_test', 'field2', 'integer'); + } + + public function down() + { + $this->dropTable('migration_test'); + } +} \ No newline at end of file diff --git a/tests/mysql_migration_classes/002_mysql_change_column.php b/tests/mysql_migration_classes/002_mysql_change_column.php new file mode 100644 index 000000000..a1054227d --- /dev/null +++ b/tests/mysql_migration_classes/002_mysql_change_column.php @@ -0,0 +1,13 @@ +renameColumn('migration_test','field2','field3'); + } + + public function down() + { + $this->renameColumn('migration_test','field3','field2'); + } +} diff --git a/tests/run.php b/tests/run.php index 5386310d5..85e107861 100644 --- a/tests/run.php +++ b/tests/run.php @@ -253,9 +253,14 @@ $cache->addTestCase(new Doctrine_Cache_Apc_TestCase()); //$cache->addTestCase(new Doctrine_Cache_TestCase()); $test->addTestCase($cache); -$test->addTestCase(new Doctrine_Query_ApplyInheritance_TestCase()); -$test->addTestCase(new Doctrine_Migration_TestCase()); +// Migration Tests +$migration = new GroupTest('Migration tests','migration'); +$migration->addTestCase(new Doctrine_Migration_TestCase()); +$migration->addTestCase(new Doctrine_Migration_Mysql_TestCase()); +$test->addTestCase($migration); + +$test->addTestCase(new Doctrine_Query_ApplyInheritance_TestCase()); $test->addTestCase(new Doctrine_Import_Schema_TestCase()); $test->addTestCase(new Doctrine_Export_Schema_TestCase()); - + $test->run();