Skip to content

Commit

Permalink
fixup! fix: Database Migration does set current version in DB Friends…
Browse files Browse the repository at this point in the history
  • Loading branch information
alquerci committed Apr 13, 2024
1 parent 9e87cb2 commit 3617510
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 22 deletions.
33 changes: 17 additions & 16 deletions tests/DoctrineTest/Doctrine_UnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 16 additions & 6 deletions tests/MigrationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 {
Expand Down

0 comments on commit 3617510

Please sign in to comment.