Skip to content

Commit

Permalink
fix: Database Migration does set current version in DB FriendsOfSymfo…
Browse files Browse the repository at this point in the history
  • Loading branch information
alquerci committed Dec 14, 2023
1 parent 0978095 commit a29305f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/Doctrine/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -559,4 +559,4 @@ protected function _createMigrationTable()
return false;
}
}
}
}
23 changes: 20 additions & 3 deletions tests/DoctrineTest/Doctrine_UnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,14 @@ public function init()

if (count($e) > 3) {
$driver = $e[2];
switch($e[2]) {

switch($driver) {
case 'Mysql':
case 'Mssql':
case 'Oracle':
case 'Pgsql':
case 'Sqlite':
$this->driverName = $e[2];
$this->driverName = $driver;
break;
}
}
Expand Down Expand Up @@ -226,7 +227,14 @@ public function prepareTables() {

}
}
$this->conn->export->exportClasses($this->tables);

foreach ($this->tables as $table) {
try {
$this->conn->export->exportClasses(array($table));
} catch (Doctrine_Export_Exception $e) {
}
}

$this->objTable = $this->connection->getTable('User');
}
public function prepareData()
Expand Down Expand Up @@ -306,6 +314,13 @@ public function getDeclaration($type)
return $this->dataDict->getPortableDeclaration(array('type' => $type, 'name' => 'colname', 'length' => 1, 'fixed' => true));
}

protected function openAndBindMysqlConnection()
{
$this->dbh = new PDO('mysql:host=localhost;dbname=test', 'root');

$this->conn = $this->connection = $this->openAdditionalConnection($this->dbh);
}

protected function openAdditionalConnection($adapter = null, $name = null)
{
$connection = $this->manager->openConnection($adapter, $name);
Expand All @@ -320,5 +335,7 @@ private function closeAdditionalConnections()
foreach ($this->additionalConnections as $connection) {
$this->manager->closeConnection($connection);
}

$this->conn = $this->connection = Doctrine_Manager::getInstance()->getCurrentConnection();
}
}
31 changes: 31 additions & 0 deletions tests/MigrationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,37 @@ public function testMigrationClassNameInflected()
$this->assertTrue($code);
}
}

public function test_afterSuccessfullMigration_willSetMigratedVersionAsCurrentVersionInMysqlDB()
{
$this->openAndBindMysqlConnection();

parent::prepareTables();

$migration = new Doctrine_Migration('migration_classes');
$migration->setCurrentVersion(3);

$migration->migrate(4);
$this->assertEqual(4, $migration->getCurrentVersion());
}

public function test_afterFailedMigration_willKeepCurrentVersionInMysqlDB()
{
$this->openAndBindMysqlConnection();

parent::prepareTables();

$migration = new Doctrine_Migration('migration_classes');
$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
Expand Down

0 comments on commit a29305f

Please sign in to comment.