1
0
mirror of synced 2025-01-18 06:21:40 +03:00
This commit is contained in:
zYne 2007-04-11 19:12:52 +00:00
parent 93c386f612
commit 7f68e096b1
6 changed files with 69 additions and 72 deletions

View File

@ -32,29 +32,30 @@
*/ */
class Doctrine_Collection_TestCase extends Doctrine_UnitTestCase class Doctrine_Collection_TestCase extends Doctrine_UnitTestCase
{ {
/**
public function testLoadRelatedForAssociation() public function testLoadRelatedForAssociation()
{ {
$coll = $this->connection->query("FROM User"); $coll = $this->connection->query('FROM User');
$this->assertEqual($coll->count(), 8); $this->assertEqual($coll->count(), 8);
$coll[0]->Group[1]->name = "Actors House 2"; $coll[0]->Group[1]->name = 'Actors House 2';
$coll[0]->Group[2]->name = "Actors House 3"; $coll[0]->Group[2]->name = 'Actors House 3';
$coll[2]->Group[0]->name = "Actors House 4"; $coll[2]->Group[0]->name = 'Actors House 4';
$coll[2]->Group[1]->name = "Actors House 5"; $coll[2]->Group[1]->name = 'Actors House 5';
$coll[2]->Group[2]->name = "Actors House 6"; $coll[2]->Group[2]->name = 'Actors House 6';
$coll[5]->Group[0]->name = "Actors House 7"; $coll[5]->Group[0]->name = 'Actors House 7';
$coll[5]->Group[1]->name = "Actors House 8"; $coll[5]->Group[1]->name = 'Actors House 8';
$coll[5]->Group[2]->name = "Actors House 9"; $coll[5]->Group[2]->name = 'Actors House 9';
$coll->save(); $coll->save();
$this->connection->clear(); $this->connection->clear();
$coll = $this->connection->query("FROM User"); $coll = $this->connection->query('FROM User');
$this->assertEqual($coll->count(), 8); $this->assertEqual($coll->count(), 8);
$this->assertEqual($coll[0]->Group->count(), 2); $this->assertEqual($coll[0]->Group->count(), 2);
@ -64,13 +65,13 @@ class Doctrine_Collection_TestCase extends Doctrine_UnitTestCase
$this->connection->clear(); $this->connection->clear();
$coll = $this->connection->query("FROM User"); $coll = $this->connection->query('FROM User');
$this->assertEqual($coll->count(), 8); $this->assertEqual($coll->count(), 8);
$count = $this->dbh->count(); $count = $this->dbh->count();
$coll->loadRelated("Group"); $coll->loadRelated('Group');
$this->assertEqual(($count + 1), $this->dbh->count()); $this->assertEqual(($count + 1), $this->dbh->count());
$this->assertEqual($coll[0]->Group->count(), 2); $this->assertEqual($coll[0]->Group->count(), 2);
$this->assertEqual(($count + 1), $this->dbh->count()); $this->assertEqual(($count + 1), $this->dbh->count());
@ -97,6 +98,7 @@ class Doctrine_Collection_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($coll->count(), 1); $this->assertEqual($coll->count(), 1);
$this->assertEqual($coll[0]->name, 'zYne'); $this->assertEqual($coll[0]->name, 'zYne');
} }
*/
public function testLoadRelatedForNormalAssociation() public function testLoadRelatedForNormalAssociation()
{ {
@ -148,7 +150,7 @@ class Doctrine_Collection_TestCase extends Doctrine_UnitTestCase
public function testLoadRelated() public function testLoadRelated()
{ {
$coll = $this->connection->query("FROM User(id)"); $coll = $this->connection->query('FROM User(id)');
$q = $coll->loadRelated(); $q = $coll->loadRelated();
@ -165,24 +167,24 @@ class Doctrine_Collection_TestCase extends Doctrine_UnitTestCase
} }
public function testLoadRelatedForLocalKeyRelation() public function testLoadRelatedForLocalKeyRelation()
{ {
$coll = $this->connection->query("FROM User"); $coll = $this->connection->query('FROM User');
$this->assertEqual($coll->count(), 8); $this->assertEqual($coll->count(), 8);
$count = $this->dbh->count(); $count = $this->dbh->count();
$coll->loadRelated("Email"); $coll->loadRelated('Email');
$this->assertEqual(($count + 1), $this->dbh->count()); $this->assertEqual(($count + 1), $this->dbh->count());
$this->assertEqual($coll[0]->Email->address, "zYne@example.com"); $this->assertEqual($coll[0]->Email->address, 'zYne@example.com');
$this->assertEqual(($count + 1), $this->dbh->count()); $this->assertEqual(($count + 1), $this->dbh->count());
$this->assertEqual($coll[2]->Email->address, "caine@example.com"); $this->assertEqual($coll[2]->Email->address, 'caine@example.com');
$this->assertEqual($coll[3]->Email->address, "kitano@example.com"); $this->assertEqual($coll[3]->Email->address, 'kitano@example.com');
$this->assertEqual($coll[4]->Email->address, "stallone@example.com"); $this->assertEqual($coll[4]->Email->address, 'stallone@example.com');
$this->assertEqual(($count + 1), $this->dbh->count()); $this->assertEqual(($count + 1), $this->dbh->count());

View File

@ -80,6 +80,10 @@ class Doctrine_Export_TestCase extends Doctrine_UnitTestCase
public function testRecordIsExportedProperly() public function testRecordIsExportedProperly()
{ {
}
public function testExport()
{
} }
} }
?> ?>

View File

@ -13,14 +13,7 @@ class M2MTest extends Doctrine_Record {
} }
} }
class RelationErrorTest extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn('name', 'string', 200);
}
public function setUp() {
$this->hasMany('RTCUnknown', 'JC1.c1_id');
}
}
class M2MTest2 extends Doctrine_Record { class M2MTest2 extends Doctrine_Record {
public function setTableDefinition() { public function setTableDefinition() {
$this->hasColumn('oid', 'integer', 11, array('autoincrement', 'primary')); $this->hasColumn('oid', 'integer', 11, array('autoincrement', 'primary'));
@ -30,14 +23,7 @@ class M2MTest2 extends Doctrine_Record {
$this->hasMany('RTC4 as RTC5', 'JC3.c1_id'); $this->hasMany('RTC4 as RTC5', 'JC3.c1_id');
} }
} }
class RTCUnknown extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn('name', 'string', 200);
}
public function setUp() {
$this->hasMany('M2MTest', 'JC2.c2_id');
}
}
class JC3 extends Doctrine_Record { class JC3 extends Doctrine_Record {
public function setTableDefinition() { public function setTableDefinition() {
$this->hasColumn('c1_id', 'integer'); $this->hasColumn('c1_id', 'integer');
@ -153,21 +139,10 @@ class Doctrine_Relation_ManyToMany_TestCase extends Doctrine_UnitTestCase {
$this->fail(); $this->fail();
} }
} }
public function testUnknownManyToManyRelation() {
try {
$component = new RelationErrorTest();
$rel = $component->getTable()->getRelation('RTCUnknown');
$this->fail();
} catch(Doctrine_Table_Exception $e) {
$this->pass();
}
}
public function testManyToManyRelationFetchingWithAliasesAndCustomPKs2() { public function testManyToManyRelationFetchingWithAliasesAndCustomPKs2() {
$q = new Doctrine_Query(); $q = new Doctrine_Query();
try { try {
$q->from('M2MTest2 m INNER JOIN m.JC3'); $q->from('M2MTest2 m INNER JOIN m.JC3');
$this->pass(); $this->pass();
@ -182,17 +157,14 @@ class Doctrine_Relation_ManyToMany_TestCase extends Doctrine_UnitTestCase {
} }
} }
public function testManyToManyHasRelationWithAliases4() { public function testManyToManyHasRelationWithAliases4() {
$component = new M2MTest();
try { try {
$rel = $component->getTable()->getRelation('RTC4'); $component = new M2MTest();
$this->pass(); $this->pass();
} catch(Doctrine_Exception $e) { } catch(Doctrine_Exception $e) {
$this->fail(); $this->fail();
} }
$this->assertTrue($rel instanceof Doctrine_Relation_Association);
$this->assertTrue($component->RTC4 instanceof Doctrine_Collection);
} }
public function testManyToManyHasRelationWithAliases3() { public function testManyToManyHasRelationWithAliases3() {
@ -212,7 +184,7 @@ class Doctrine_Relation_ManyToMany_TestCase extends Doctrine_UnitTestCase {
public function testManyToManyHasRelationWithAliases() { public function testManyToManyHasRelationWithAliases() {
$component = new M2MTest(); $component = new M2MTest();
try { try {
$rel = $component->getTable()->getRelation('RTC1'); $rel = $component->getTable()->getRelation('RTC1');
$this->pass(); $this->pass();
@ -226,7 +198,7 @@ class Doctrine_Relation_ManyToMany_TestCase extends Doctrine_UnitTestCase {
public function testManyToManyHasRelationWithAliases2() { public function testManyToManyHasRelationWithAliases2() {
$component = new M2MTest(); $component = new M2MTest();
try { try {
$rel = $component->getTable()->getRelation('RTC2'); $rel = $component->getTable()->getRelation('RTC2');
$this->pass(); $this->pass();

View File

@ -1,16 +1,21 @@
<?php <?php
class RelationTest extends Doctrine_Record { class RelationTest extends Doctrine_Record
public function setTableDefinition() { {
public function setTableDefinition()
{
$this->hasColumn('name', 'string', 200); $this->hasColumn('name', 'string', 200);
$this->hasColumn('child_id', 'integer'); $this->hasColumn('child_id', 'integer');
} }
public function setUp() { public function setUp()
{
$this->ownsMany('OwnsOneToManyWithAlias as AliasO2M', 'AliasO2M.component_id'); $this->ownsMany('OwnsOneToManyWithAlias as AliasO2M', 'AliasO2M.component_id');
} }
} }
class RelationTestChild extends RelationTest { class RelationTestChild extends RelationTest
public function setUp() { {
public function setUp()
{
$this->hasOne('RelationTest as Parent', 'RelationTestChild.child_id'); $this->hasOne('RelationTest as Parent', 'RelationTestChild.child_id');
$this->ownsMany('RelationTestChild as Children', 'RelationTestChild.child_id'); $this->ownsMany('RelationTestChild as Children', 'RelationTestChild.child_id');
@ -37,28 +42,39 @@ class OwnsOneToManyWithAlias extends Doctrine_Record {
} }
class Doctrine_Relation_TestCase extends Doctrine_UnitTestCase { class Doctrine_Relation_TestCase extends Doctrine_UnitTestCase {
public function prepareData() { }
public function prepareTables() { public function prepareData()
parent::prepareTables(); { }
public function prepareTables()
{}
public function setUp() {
if( ! $this->init) $this->init();
if(isset($this->objTable)) {
$this->objTable->clear();
}
$this->init = true;
} }
public function testOneToManyTreeRelationWithConcreteInheritance() { public function testOneToManyTreeRelationWithConcreteInheritance() {
$component = new RelationTestChild(); $component = new RelationTestChild();
try { try {
$rel = $component->getTable()->getRelation('Children'); $rel = $component->getTable()->getRelation('Children');
$this->pass(); $this->pass();
} catch(Doctrine_Exception $e) { } catch(Doctrine_Exception $e) {
$this->fail(); $this->fail();
} }
$this->assertTrue($rel instanceof Doctrine_Relation_ForeignKey); $this->assertTrue($rel instanceof Doctrine_Relation_ForeignKey);
$this->assertTrue($component->Children instanceof Doctrine_Collection); $this->assertTrue($component->Children instanceof Doctrine_Collection);
$this->assertTrue($component->Children[0] instanceof RelationTestChild); $this->assertTrue($component->Children[0] instanceof RelationTestChild);
} }
public function testOneToOneTreeRelationWithConcreteInheritance() { public function testOneToOneTreeRelationWithConcreteInheritance() {
$component = new RelationTestChild(); $component = new RelationTestChild();
@ -114,5 +130,6 @@ class Doctrine_Relation_TestCase extends Doctrine_UnitTestCase {
$this->assertTrue($user->getTable()->getRelation('Phonenumber') instanceof Doctrine_Relation_ForeignKey); $this->assertTrue($user->getTable()->getRelation('Phonenumber') instanceof Doctrine_Relation_ForeignKey);
$this->manager->setAttribute(Doctrine::ATTR_CREATE_TABLES, true); $this->manager->setAttribute(Doctrine::ATTR_CREATE_TABLES, true);
} }
} }

View File

@ -22,14 +22,14 @@ class Doctrine_UnitTestCase extends UnitTestCase {
protected $transaction; protected $transaction;
private $init = false; protected $init = false;
public function init() { public function init() {
$name = get_class($this); $name = get_class($this);
$this->manager = Doctrine_Manager::getInstance(); $this->manager = Doctrine_Manager::getInstance();
$this->manager->setAttribute(Doctrine::ATTR_FETCHMODE, Doctrine::FETCH_IMMEDIATE); $this->manager->setAttribute(Doctrine::ATTR_FETCHMODE, Doctrine::FETCH_IMMEDIATE);
$this->manager->setAttribute(Doctrine::ATTR_EXPORT, Doctrine::EXPORT_ALL); $this->manager->setAttribute(Doctrine::ATTR_EXPORT, Doctrine::EXPORT_ALL);
$this->tables = array_merge($this->tables, $this->tables = array_merge($this->tables,
array("entity", array("entity",
@ -129,8 +129,6 @@ class Doctrine_UnitTestCase extends UnitTestCase {
$this->prepareTables(); $this->prepareTables();
$this->prepareData(); $this->prepareData();
} }
$this->valueHolder = new Doctrine_ValueHolder($this->connection->getTable('User'));
} }
public function prepareTables() { public function prepareTables() {
foreach($this->tables as $name) { foreach($this->tables as $name) {

View File

@ -104,11 +104,11 @@ $test->addTestCase(new Doctrine_Sequence_Sqlite_TestCase());
// Export module (not yet fully tested) // Export module (not yet fully tested)
$test->addTestCase(new Doctrine_Export_TestCase());
//$test->addTestCase(new Doctrine_Export_Reporter_TestCase()); //$test->addTestCase(new Doctrine_Export_Reporter_TestCase());
$test->addTestCase(new Doctrine_Export_Firebird_TestCase()); $test->addTestCase(new Doctrine_Export_Firebird_TestCase());
$test->addTestCase(new Doctrine_Export_Informix_TestCase()); $test->addTestCase(new Doctrine_Export_Informix_TestCase());
$test->addTestCase(new Doctrine_Export_TestCase());
$test->addTestCase(new Doctrine_Export_Mssql_TestCase()); $test->addTestCase(new Doctrine_Export_Mssql_TestCase());
$test->addTestCase(new Doctrine_Export_Pgsql_TestCase()); $test->addTestCase(new Doctrine_Export_Pgsql_TestCase());
$test->addTestCase(new Doctrine_Export_Oracle_TestCase()); $test->addTestCase(new Doctrine_Export_Oracle_TestCase());
@ -116,6 +116,8 @@ $test->addTestCase(new Doctrine_Export_Sqlite_TestCase());
$test->addTestCase(new Doctrine_Export_Mysql_TestCase()); $test->addTestCase(new Doctrine_Export_Mysql_TestCase());
$test->addTestCase(new Doctrine_CascadingDelete_TestCase());
// Import module (not yet fully tested) // Import module (not yet fully tested)
//$test->addTestCase(new Doctrine_Import_TestCase()); //$test->addTestCase(new Doctrine_Import_TestCase());
$test->addTestCase(new Doctrine_Import_Firebird_TestCase()); $test->addTestCase(new Doctrine_Import_Firebird_TestCase());
@ -146,6 +148,7 @@ $test->addTestCase(new Doctrine_Manager_TestCase());
$test->addTestCase(new Doctrine_Connection_TestCase()); $test->addTestCase(new Doctrine_Connection_TestCase());
$test->addTestCase(new Doctrine_Table_TestCase()); $test->addTestCase(new Doctrine_Table_TestCase());
$test->addTestCase(new Doctrine_UnitOfWork_TestCase()); $test->addTestCase(new Doctrine_UnitOfWork_TestCase());
$test->addTestCase(new Doctrine_Connection_Transaction_TestCase()); $test->addTestCase(new Doctrine_Connection_Transaction_TestCase());
@ -234,6 +237,7 @@ $test->addTestCase(new Doctrine_Cache_Apc_TestCase());
$test->addTestCase(new Doctrine_Cache_Memcache_TestCase()); $test->addTestCase(new Doctrine_Cache_Memcache_TestCase());
$test->addTestCase(new Doctrine_Cache_Sqlite_TestCase()); $test->addTestCase(new Doctrine_Cache_Sqlite_TestCase());
$test->addTestCase(new Doctrine_Query_Check_TestCase());
// Cache tests // Cache tests
//$test->addTestCase(new Doctrine_Cache_Query_SqliteTestCase()); //$test->addTestCase(new Doctrine_Cache_Query_SqliteTestCase());