From 3d88ef74dd03bdf2fbecbddb35083f55732debb5 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 c24abf97..19427d37 100644 --- a/tests/DoctrineTest/Doctrine_UnitTestCase.php +++ b/tests/DoctrineTest/Doctrine_UnitTestCase.php @@ -217,22 +217,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')); @@ -310,17 +317,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 68948708..2642f3ad 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 {