From 4ce762caa4d84977d2ca9910540c72a191c41933 Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Sat, 13 Apr 2024 18:07:48 +0200 Subject: [PATCH] fixup! fix: Database Migration does set current version in DB #98 --- tests/MigrationTestCase.php | 69 +++------------------------ tests/models/MigrationPhonenumber.php | 10 ++++ tests/models/MigrationProfile.php | 9 ++++ tests/models/MigrationUser.php | 10 ++++ tests/run.php | 1 + 5 files changed, 37 insertions(+), 62 deletions(-) create mode 100644 tests/models/MigrationPhonenumber.php create mode 100644 tests/models/MigrationProfile.php create mode 100644 tests/models/MigrationUser.php diff --git a/tests/MigrationTestCase.php b/tests/MigrationTestCase.php index 14ca53ed2..7b718ba54 100644 --- a/tests/MigrationTestCase.php +++ b/tests/MigrationTestCase.php @@ -32,13 +32,13 @@ */ class Doctrine_Migration_TestCase extends Doctrine_UnitTestCase { - const TABLES = array( - 'MigrationPhonenumber', - 'MigrationUser', - 'MigrationProfile', - ); - - protected $tables = self::TABLES; + public function prepareTables() + { + $this->tables[] = 'MigrationPhonenumber'; + $this->tables[] = 'MigrationUser'; + $this->tables[] = 'MigrationProfile'; + parent::prepareTables(); + } public function testMigration() { @@ -127,59 +127,4 @@ public function testMigrationClassNameInflected() $this->assertTrue($code); } } - - public function test_afterSuccessfullMigration_willSetMigratedVersionAsCurrentVersionInMysqlDB() - { - $connection = $this->openMysqlAdditionalConnection(); - $this->resetTablesOnConnection(self::TABLES, $connection); - - $migration = new Doctrine_Migration('migration_classes', $connection); - $migration->setCurrentVersion(3); - - $migration->migrate(4); - $this->assertEqual(4, $migration->getCurrentVersion()); - } - - public function test_afterFailedMigration_willKeepCurrentVersionInMysqlDB() - { - $connection = $this->openMysqlAdditionalConnection(); - $this->resetTablesOnConnection(self::TABLES, $connection); - - $migration = new Doctrine_Migration('migration_classes', $connection); - $migration->setCurrentVersion(0); - - try { - $migration->migrate(1); - - $this->fail('migration must fail'); - } catch (Doctrine_Migration_Exception $e) { - $this->assertEqual(0, $migration->getCurrentVersion()); - } - } -} - -class MigrationPhonenumber extends Doctrine_Record -{ - public function setTableDefinition() - { - $this->hasColumn('user_id', 'integer'); - $this->hasColumn('phonenumber', 'string', 255); - } -} - -class MigrationUser extends Doctrine_Record -{ - public function setTableDefinition() - { - $this->hasColumn('username', 'string', 255); - $this->hasColumn('password', 'string', 255); - } -} - -class MigrationProfile extends Doctrine_Record -{ - public function setTableDefinition() - { - $this->hasColumn('name', 'string', 255); - } } diff --git a/tests/models/MigrationPhonenumber.php b/tests/models/MigrationPhonenumber.php new file mode 100644 index 000000000..af55ef786 --- /dev/null +++ b/tests/models/MigrationPhonenumber.php @@ -0,0 +1,10 @@ +hasColumn('user_id', 'integer'); + $this->hasColumn('phonenumber', 'string', 255); + } +} diff --git a/tests/models/MigrationProfile.php b/tests/models/MigrationProfile.php new file mode 100644 index 000000000..8302b6751 --- /dev/null +++ b/tests/models/MigrationProfile.php @@ -0,0 +1,9 @@ +hasColumn('name', 'string', 255); + } +} diff --git a/tests/models/MigrationUser.php b/tests/models/MigrationUser.php new file mode 100644 index 000000000..7c366179f --- /dev/null +++ b/tests/models/MigrationUser.php @@ -0,0 +1,10 @@ +hasColumn('username', 'string', 255); + $this->hasColumn('password', 'string', 255); + } +} diff --git a/tests/run.php b/tests/run.php index d1dd2c7ee..b458896b6 100644 --- a/tests/run.php +++ b/tests/run.php @@ -279,6 +279,7 @@ // Migration Tests $migration = new GroupTest('Migration Tests', 'migration'); $migration->addTestCase(new Doctrine_Migration_TestCase()); +$migration->addTestCase(new Doctrine_Migration_Mysql_TestCase()); $migration->addTestCase(new Doctrine_Migration_Base_TestCase()); $migration->addTestCase(new Doctrine_Migration_Diff_TestCase()); $test->addTestCase($migration);