1
0
mirror of synced 2025-01-31 04:21:44 +03:00
This commit is contained in:
Jonathan.Wage 2007-10-15 20:39:44 +00:00
parent 071febe96c
commit 54c3b98d73
3 changed files with 46 additions and 12 deletions

View File

@ -145,7 +145,7 @@ class Doctrine_Migration
$e = explode('_', $fileName); $e = explode('_', $fileName);
$classMigrationNum = (int) $e[0]; $classMigrationNum = (int) $e[0];
$loadedClasses[$classMigrationNum] = $fileName; $loadedClasses[$classMigrationNum] = array('className' => $name, 'fileName' => $fileName);
} }
$this->migrationClasses = $loadedClasses; $this->migrationClasses = $loadedClasses;
@ -228,7 +228,7 @@ class Doctrine_Migration
$this->loadMigrationClasses(); $this->loadMigrationClasses();
$versions = array(); $versions = array();
foreach ($this->migrationClasses as $classMigrationNum => $fileName) { foreach (array_keys($this->migrationClasses) as $classMigrationNum) {
$versions[$classMigrationNum] = $classMigrationNum; $versions[$classMigrationNum] = $classMigrationNum;
} }
@ -252,8 +252,10 @@ class Doctrine_Migration
*/ */
protected function getMigrationClass($num) protected function getMigrationClass($num)
{ {
foreach ($this->migrationClasses as $classMigrationNum => $fileName) { foreach ($this->migrationClasses as $classMigrationNum => $info) {
if ($classMigrationNum === $num) { $className = $info['className'];
if ($classMigrationNum == $num) {
return new $className(); return new $className();
} }
} }

View File

@ -55,6 +55,38 @@ class Doctrine_Manager_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual(Doctrine::classify(Doctrine::tableize($name)), $name); $this->assertEqual(Doctrine::classify(Doctrine::tableize($name)), $name);
}
public function testDsnParser()
{
$mysql = 'mysql://user:pass@localhost/dbname';
// This is what is specified in the manul
// I think it should be this for parse_url() to work
// sqlite://full/unix/path/to/file.db
// It expects only // since it thinks it is parsing a url
// The problem after that is that the dns is not valid when being passed to PDO
$sqlite = 'sqlite:////full/unix/path/to/file.db';
$sqlitewin = 'sqlite:///c:/full/windows/path/to/file.db';
$manager = Doctrine_Manager::getInstance();
try {
$manager->parseDsn($mysql);
} catch (Exception $e) {
$this->fail();
}
try {
$manager->parseDsn($sqlite);
} catch (Exception $e) {
$this->fail();
}
try {
$manager->parseDsn($sqlitewin);
} catch (Exception $e) {
$this->fail();
}
} }
public function prepareData() { } public function prepareData() { }
public function prepareTables() { } public function prepareTables() { }

View File

@ -34,16 +34,16 @@ class Doctrine_Migration_TestCase extends Doctrine_UnitTestCase
{ {
public function testMigration() public function testMigration()
{ {
// Upgrade one at a time // New migration for the 'migration_classes' directory
$migration = new Doctrine_Migration('migration_classes'); $migration = new Doctrine_Migration('migration_classes');
$migration->migrate(0, 1);
$migration->migrate(1, 2);
// Then revert back to version 1 // migrate to version 2
$migration->migrate(2, 1); $migration->migrate(2);
$migration->migrate(1, 0);
// Check to make sure the current version is 0 // now migrate back to original version
$migration->migrate(0);
// Make sure the current version is 0
$this->assertEqual($migration->getCurrentVersion(), 0); $this->assertEqual($migration->getCurrentVersion(), 0);
} }
} }