new test setup refactorings
This commit is contained in:
parent
45235a15d8
commit
0061bc827b
@ -1277,7 +1277,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
|
||||
* @return boolean whether or not the export operation was successful
|
||||
* false if table already existed in the database
|
||||
*/
|
||||
public function exportTable(Doctrine_Table $table)
|
||||
public function exportTable(Doctrine_ClassMetadata $metadata)
|
||||
{
|
||||
/**
|
||||
TODO: maybe there should be portability option for the following check
|
||||
@ -1287,10 +1287,10 @@ class Doctrine_Export extends Doctrine_Connection_Module
|
||||
*/
|
||||
|
||||
try {
|
||||
$data = $table->getExportableFormat();
|
||||
$data = $metadata->getExportableFormat();
|
||||
|
||||
$this->conn->export->createTable($data['tableName'], $data['columns'], $data['options']);
|
||||
} catch(Doctrine_Connection_Exception $e) {
|
||||
} catch (Doctrine_Connection_Exception $e) {
|
||||
// we only want to silence table already exists errors
|
||||
if ($e->getPortableCode() !== Doctrine::ERR_ALREADY_EXISTS) {
|
||||
throw $e;
|
||||
|
@ -17,7 +17,7 @@ class Orm_Component_AllTests
|
||||
|
||||
public static function suite()
|
||||
{
|
||||
$suite = new Doctrine_TestSuite('Doctrine Dbal Component');
|
||||
$suite = new Doctrine_TestSuite('Doctrine Orm Component');
|
||||
|
||||
$suite->addTestSuite('Orm_Component_TestTest');
|
||||
|
||||
|
@ -3,6 +3,11 @@ require_once 'lib/DoctrineTestInit.php';
|
||||
|
||||
class Orm_Component_TestTest extends Doctrine_OrmTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
$this->loadFixture('forum', 'someusers');
|
||||
}
|
||||
|
||||
public function testTest()
|
||||
{
|
||||
$this->assertEquals(0, 0);
|
||||
|
5
tests/fixtures/cms/data/CmsUser.yml
vendored
5
tests/fixtures/cms/data/CmsUser.yml
vendored
@ -1,5 +0,0 @@
|
||||
---
|
||||
CmsUser:
|
||||
CmsUser_1:
|
||||
username: jwage
|
||||
password: changeme
|
16
tests/fixtures/dbal/dummy.php
vendored
Normal file
16
tests/fixtures/dbal/dummy.php
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
$fixture = array(
|
||||
'tableName' => 'dummy',
|
||||
'rows' => array(
|
||||
array(
|
||||
'column1' => 'value1',
|
||||
'column2' => 'value2',
|
||||
'column3' => 'value3'
|
||||
),
|
||||
array(
|
||||
'column1' => 'value4',
|
||||
'column2' => 'value5',
|
||||
'column3' => 'value6'
|
||||
)
|
||||
)
|
||||
);
|
14
tests/fixtures/orm/forum/someusers.php
vendored
Normal file
14
tests/fixtures/orm/forum/someusers.php
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
$fixture = array(
|
||||
'model' => 'ForumUser',
|
||||
'rows' => array(
|
||||
array(
|
||||
'id' => 1,
|
||||
'username' => 'romanb'
|
||||
),
|
||||
array(
|
||||
'id' => 2,
|
||||
'username' => 'jwage'
|
||||
)
|
||||
)
|
||||
);
|
@ -2,7 +2,7 @@
|
||||
/**
|
||||
* Base testcase class for all dbal testcases.
|
||||
*/
|
||||
class Doctrine_DbalTestCase extends PHPUnit_Framework_TestCase
|
||||
class Doctrine_DbalTestCase extends Doctrine_TestCase
|
||||
{
|
||||
|
||||
}
|
@ -21,9 +21,5 @@ class Doctrine_DbalTestSuite extends Doctrine_TestSuite
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
Doctrine_Manager::getInstance()->getConnection('sqlite_memory')->close();
|
||||
$this->sharedFixture = NULL;
|
||||
}
|
||||
|
||||
{}
|
||||
}
|
@ -2,10 +2,63 @@
|
||||
/**
|
||||
* Base testcase class for all orm testcases.
|
||||
*
|
||||
* Provides the testcases with fixture support and other orm related capabilities.
|
||||
*/
|
||||
class Doctrine_OrmTestCase extends Doctrine_TestCase
|
||||
{
|
||||
private $_loadedFixtures = array();
|
||||
private static $_fixtures = array();
|
||||
private static $_exportedTables = array();
|
||||
|
||||
protected function loadFixture($package, $name)
|
||||
{
|
||||
$uniqueName = $package . '/' . $name;
|
||||
|
||||
if ( ! isset(self::$_fixtures[$uniqueName])) {
|
||||
// load fixture file
|
||||
$fixtureFile = 'fixtures' . DIRECTORY_SEPARATOR . 'orm' . DIRECTORY_SEPARATOR
|
||||
. $package . DIRECTORY_SEPARATOR . $name . '.php';
|
||||
require $fixtureFile;
|
||||
self::$_fixtures[$uniqueName] = $fixture;
|
||||
|
||||
// load model file
|
||||
$modelFile = 'models' . DIRECTORY_SEPARATOR . $package . DIRECTORY_SEPARATOR .
|
||||
$fixture['model'] . '.php';
|
||||
require $modelFile;
|
||||
}
|
||||
|
||||
$fixture = self::$_fixtures[$uniqueName];
|
||||
$this->_loadedFixtures[] = $fixture['model'];
|
||||
|
||||
$conn = $this->sharedFixture['connection'];
|
||||
$classMetadata = $conn->getClassMetadata($fixture['model']);
|
||||
$tableName = $classMetadata->getTableName();
|
||||
|
||||
if ( ! in_array($tableName, self::$_exportedTables)) {
|
||||
$conn->export->exportClasses(array($fixture['model']));
|
||||
self::$_exportedTables[] = $tableName;
|
||||
}
|
||||
|
||||
foreach ($fixture['rows'] as $row) {
|
||||
$conn->insert($classMetadata, $row);
|
||||
}
|
||||
}
|
||||
|
||||
protected function loadFixtures($package, array $names)
|
||||
{
|
||||
foreach ($names as $name) {
|
||||
$this->loadFixture($package, $name);
|
||||
}
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$conn = $this->sharedFixture['connection'];
|
||||
foreach (array_reverse($this->_loadedFixtures) as $model) {
|
||||
$conn->exec("DELETE FROM " . $conn->getClassMetadata($model)->getTableName());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public function loadFixturesPackage($package, $models = array())
|
||||
{
|
||||
$packagePath = 'fixtures' . DIRECTORY_SEPARATOR . $package;
|
||||
@ -23,4 +76,5 @@ class Doctrine_OrmTestCase extends Doctrine_TestCase
|
||||
$data = new Doctrine_Data();
|
||||
$data->importData($dataPath, 'yml', $models);
|
||||
}
|
||||
*/
|
||||
}
|
@ -20,8 +20,5 @@ class Doctrine_OrmTestSuite extends Doctrine_TestSuite
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
Doctrine_Manager::getInstance()->getConnection('sqlite_memory')->close();
|
||||
$this->sharedFixture = NULL;
|
||||
}
|
||||
{}
|
||||
}
|
@ -4,5 +4,5 @@
|
||||
*/
|
||||
class Doctrine_TestCase extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
|
||||
}
|
9
tests/models/forum/ForumUser.php
Normal file
9
tests/models/forum/ForumUser.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
class ForumUser extends Doctrine_Record
|
||||
{
|
||||
public static function initMetadata($class)
|
||||
{
|
||||
$class->setColumn('id', 'integer', 4, array('primary' => true, 'autoincrement' => true));
|
||||
$class->setColumn('username', 'string', 255);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user