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 May 24, 2024
1 parent bc0468e commit 4ce762c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 62 deletions.
69 changes: 7 additions & 62 deletions tests/MigrationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
*/
class Doctrine_Migration_TestCase extends Doctrine_UnitTestCase
{
const TABLES = array(
'MigrationPhonenumber',
'MigrationUser',
'MigrationProfile',
);

protected $tables = self::TABLES;
public function prepareTables()
{
$this->tables[] = 'MigrationPhonenumber';
$this->tables[] = 'MigrationUser';
$this->tables[] = 'MigrationProfile';
parent::prepareTables();
}

public function testMigration()
{
Expand Down Expand Up @@ -127,59 +127,4 @@ public function testMigrationClassNameInflected()
$this->assertTrue($code);
}
}

public function test_afterSuccessfullMigration_willSetMigratedVersionAsCurrentVersionInMysqlDB()
{
$connection = $this->openMysqlAdditionalConnection();
$this->resetTablesOnConnection(self::TABLES, $connection);

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

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

public function test_afterFailedMigration_willKeepCurrentVersionInMysqlDB()
{
$connection = $this->openMysqlAdditionalConnection();
$this->resetTablesOnConnection(self::TABLES, $connection);

$migration = new Doctrine_Migration('migration_classes', $connection);
$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
{
public function setTableDefinition()
{
$this->hasColumn('user_id', 'integer');
$this->hasColumn('phonenumber', 'string', 255);
}
}

class MigrationUser extends Doctrine_Record
{
public function setTableDefinition()
{
$this->hasColumn('username', 'string', 255);
$this->hasColumn('password', 'string', 255);
}
}

class MigrationProfile extends Doctrine_Record
{
public function setTableDefinition()
{
$this->hasColumn('name', 'string', 255);
}
}
10 changes: 10 additions & 0 deletions tests/models/MigrationPhonenumber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

class MigrationPhonenumber extends Doctrine_Record
{
public function setTableDefinition()
{
$this->hasColumn('user_id', 'integer');
$this->hasColumn('phonenumber', 'string', 255);
}
}
9 changes: 9 additions & 0 deletions tests/models/MigrationProfile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

class MigrationProfile extends Doctrine_Record
{
public function setTableDefinition()
{
$this->hasColumn('name', 'string', 255);
}
}
10 changes: 10 additions & 0 deletions tests/models/MigrationUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

class MigrationUser extends Doctrine_Record
{
public function setTableDefinition()
{
$this->hasColumn('username', 'string', 255);
$this->hasColumn('password', 'string', 255);
}
}
1 change: 1 addition & 0 deletions tests/run.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@
// Migration Tests
$migration = new GroupTest('Migration Tests', 'migration');
$migration->addTestCase(new Doctrine_Migration_TestCase());
$migration->addTestCase(new Doctrine_Migration_Mysql_TestCase());
$migration->addTestCase(new Doctrine_Migration_Base_TestCase());
$migration->addTestCase(new Doctrine_Migration_Diff_TestCase());
$test->addTestCase($migration);
Expand Down

0 comments on commit 4ce762c

Please sign in to comment.