diff --git a/tests/DoctrineTest/Doctrine_UnitTestCase.php b/tests/DoctrineTest/Doctrine_UnitTestCase.php index c9b891c0..17c7b845 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 31641d7d..e96106ba 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 {