From 171633199ff679f4279f82d0bcb636d465a94a4b Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Sat, 13 Apr 2024 17:39:53 +0200 Subject: [PATCH] fixup! fix: Database Migration does set current version in DB #98 --- tests/DoctrineTest/Doctrine_UnitTestCase.php | 33 ++++++++++---------- tests/MigrationTestCase.php | 22 +++++++++---- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/tests/DoctrineTest/Doctrine_UnitTestCase.php b/tests/DoctrineTest/Doctrine_UnitTestCase.php index c9b891c0e..17c7b8455 100644 --- a/tests/DoctrineTest/Doctrine_UnitTestCase.php +++ b/tests/DoctrineTest/Doctrine_UnitTestCase.php @@ -216,22 +216,29 @@ public function init() } } } + public function prepareTables() { - foreach($this->tables as $name) { + $this->resetTablesOnConnection($this->tables, $this->connection); + + $this->objTable = $this->connection->getTable('User'); + } + + protected function resetTablesOnConnection(array $tables, Doctrine_Connection $connection) + { + foreach($tables as $name) { $name = ucwords($name); - $table = $this->connection->getTable($name); + $table = $connection->getTable($name); $query = 'DROP TABLE ' . $table->getTableName(); + try { - $this->conn->exec($query); + $connection->exec($query); } catch(Doctrine_Connection_Exception $e) { - } } - $this->conn->export->exportClasses($this->tables); - - $this->objTable = $this->connection->getTable('User'); + $connection->export->exportClasses($tables); } + public function prepareData() { $groups = new Doctrine_Collection($this->connection->getTable('Group')); @@ -309,17 +316,11 @@ public function getDeclaration($type) return $this->dataDict->getPortableDeclaration(array('type' => $type, 'name' => 'colname', 'length' => 1, 'fixed' => true)); } - protected function openAndBindMysqlConnection() + protected function openMysqlAdditionalConnection() { - $this->dbh = new PDO(getenv('MYSQL_DSN')); - - $this->conn = $this->connection = $this->openAdditionalConnection($this->dbh); + $dbh = new PDO(getenv('MYSQL_DSN')); - $this->exc = new Doctrine_Connection_Mysql_Exception(); - - $this->unitOfWork = $this->connection->unitOfWork; - $this->connection->setListener(new Doctrine_EventListener()); - $this->query = new Doctrine_Query($this->connection); + return $this->openAdditionalConnection($dbh); } protected function openAdditionalConnection($adapter = null, $name = null) diff --git a/tests/MigrationTestCase.php b/tests/MigrationTestCase.php index 31641d7dd..e96106ba6 100644 --- a/tests/MigrationTestCase.php +++ b/tests/MigrationTestCase.php @@ -128,11 +128,16 @@ public function testMigrationClassNameInflected() public function test_afterSuccessfullMigration_willSetMigratedVersionAsCurrentVersionInMysqlDB() { - $this->openAndBindMysqlConnection(); + $tables = array( + 'MigrationPhonenumber', + 'MigrationUser', + 'MigrationProfile', + ); - parent::prepareTables(); + $connection = $this->openMysqlAdditionalConnection(); + $this->resetTablesOnConnection($tables, $connection); - $migration = new Doctrine_Migration('migration_classes'); + $migration = new Doctrine_Migration('migration_classes', $connection); $migration->setCurrentVersion(3); $migration->migrate(4); @@ -141,11 +146,16 @@ public function test_afterSuccessfullMigration_willSetMigratedVersionAsCurrentVe public function test_afterFailedMigration_willKeepCurrentVersionInMysqlDB() { - $this->openAndBindMysqlConnection(); + $tables = array( + 'MigrationPhonenumber', + 'MigrationUser', + 'MigrationProfile', + ); - parent::prepareTables(); + $connection = $this->openMysqlAdditionalConnection(); + $this->resetTablesOnConnection($tables, $connection); - $migration = new Doctrine_Migration('migration_classes'); + $migration = new Doctrine_Migration('migration_classes', $connection); $migration->setCurrentVersion(0); try {