This commit is contained in:
parent
f4462041f8
commit
063d0f876d
@ -38,6 +38,7 @@
|
||||
*/
|
||||
class Doctrine_Collection_Snapshot_TestCase extends Doctrine_UnitTestCase
|
||||
{
|
||||
|
||||
public function testDiffForSimpleCollection()
|
||||
{
|
||||
$coll = Doctrine_Query::create()->from('User u')->orderby('u.id')->execute();
|
||||
@ -55,34 +56,41 @@ class Doctrine_Collection_Snapshot_TestCase extends Doctrine_UnitTestCase
|
||||
$this->connection->clear();
|
||||
$coll = Doctrine_Query::create()->from('User u')->execute();
|
||||
$this->assertEqual($coll->count(), 7);
|
||||
|
||||
}
|
||||
|
||||
public function testDiffForOneToManyRelatedCollection()
|
||||
{
|
||||
$q = Doctrine_Query::create()->from('User u LEFT JOIN u.Phonenumber p')
|
||||
->where('u.id = 8');
|
||||
$q = new Doctrine_Query();
|
||||
$q->from('User u LEFT JOIN u.Phonenumber p')
|
||||
->where('u.id = 8');
|
||||
|
||||
$coll = $q->execute();
|
||||
|
||||
$this->assertEqual($coll->count(), 1);
|
||||
|
||||
$this->assertEqual($coll[0]->Phonenumber->count(), 3);
|
||||
$this->assertTrue($coll[0]->Phonenumber instanceof Doctrine_Collection);
|
||||
|
||||
unset($coll[0]->Phonenumber[0]);
|
||||
$coll[0]->Phonenumber->remove(2);
|
||||
|
||||
$this->assertEqual(count($coll[0]->Phonenumber->getSnapshot()), 3);
|
||||
$coll[0]->save();
|
||||
|
||||
$this->assertEqual($coll[0]->Phonenumber->count(), 1);
|
||||
|
||||
$this->connection->clear();
|
||||
|
||||
$q = new Doctrine_Query();
|
||||
$q = Doctrine_Query::create()->from('User u LEFT JOIN u.Phonenumber p')->where('u.id = 8');
|
||||
|
||||
$coll = $q->execute();
|
||||
|
||||
$this->assertEqual($coll[0]->Phonenumber->count(), 1);
|
||||
|
||||
}
|
||||
|
||||
public function testDiffForManyToManyRelatedCollection()
|
||||
{
|
||||
$user = new User();
|
||||
@ -110,4 +118,5 @@ class Doctrine_Collection_Snapshot_TestCase extends Doctrine_UnitTestCase
|
||||
|
||||
$this->assertEqual(count($user->Group->getSnapshot()), 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,6 +32,7 @@
|
||||
*/
|
||||
class Doctrine_Hydrate_FetchMode_TestCase extends Doctrine_UnitTestCase
|
||||
{
|
||||
/**
|
||||
public function testFetchArraySupportsOneToManyRelations()
|
||||
{
|
||||
$q = new Doctrine_Query();
|
||||
@ -80,4 +81,69 @@ class Doctrine_Hydrate_FetchMode_TestCase extends Doctrine_UnitTestCase
|
||||
$this->assertEqual(count($users), 8);
|
||||
$this->assertEqual($users[0]['Email']['address'], 'zYne@example.com');
|
||||
}
|
||||
public function testFetchArraySupportsOneToOneRelations2()
|
||||
{
|
||||
$q = new Doctrine_Query();
|
||||
|
||||
$q->select('u.*, e.*')->from('User u')->innerJoin('u.Email e')->where("u.name = 'zYne'");
|
||||
|
||||
$users = $q->execute(array(), Doctrine::FETCH_ARRAY);
|
||||
|
||||
$this->assertEqual(count($users), 1);
|
||||
$this->assertEqual($users[0]['Email']['address'], 'zYne@example.com');
|
||||
}
|
||||
*/
|
||||
public function testFetchRecordSupportsOneToOneRelations()
|
||||
{
|
||||
$q = new Doctrine_Query();
|
||||
|
||||
$q->select('u.*, e.*')->from('User u')->innerJoin('u.Email e');
|
||||
$count = count($this->dbh);
|
||||
$users = $q->execute(array(), Doctrine::FETCH_RECORD);
|
||||
|
||||
$this->assertEqual(count($users), 8);
|
||||
|
||||
$this->assertEqual($users[0]['Email']['address'], 'zYne@example.com');
|
||||
$this->assertTrue($users[0] instanceof User);
|
||||
$this->assertTrue($users instanceof Doctrine_Collection);
|
||||
$this->assertEqual($users[0]->state(), Doctrine_Record::STATE_CLEAN);
|
||||
$this->assertEqual($users[0]->id, 4);
|
||||
|
||||
$this->assertTrue($users[0]['Email'] instanceof Email);
|
||||
$this->assertEqual($users[0]['email_id'], 1);
|
||||
$this->assertEqual(count($this->dbh), $count + 1);
|
||||
}
|
||||
|
||||
public function testFetchRecordSupportsOneToManyRelations()
|
||||
{
|
||||
$q = new Doctrine_Query();
|
||||
|
||||
$q->select('u.*, p.*')->from('User u')->innerJoin('u.Phonenumber p');
|
||||
$count = count($this->dbh);
|
||||
$users = $q->execute(array(), Doctrine::FETCH_RECORD);
|
||||
|
||||
$this->assertEqual(count($users), 8);
|
||||
$this->assertTrue($users[0] instanceof User);
|
||||
$this->assertEqual($users[0]->state(), Doctrine_Record::STATE_CLEAN);
|
||||
$this->assertTrue($users instanceof Doctrine_Collection);
|
||||
$this->assertTrue($users[0]->Phonenumber instanceof Doctrine_Collection);
|
||||
|
||||
$this->assertEqual(count($this->dbh), $count + 1);
|
||||
}
|
||||
|
||||
public function testFetchRecordSupportsSimpleFetching()
|
||||
{
|
||||
$q = new Doctrine_Query();
|
||||
|
||||
$q->select('u.*')->from('User u');
|
||||
$count = count($this->dbh);
|
||||
$users = $q->execute(array(), Doctrine::FETCH_RECORD);
|
||||
|
||||
$this->assertEqual(count($users), 8);
|
||||
$this->assertTrue($users[0] instanceof User);
|
||||
$this->assertEqual($users[0]->state(), Doctrine_Record::STATE_CLEAN);
|
||||
|
||||
|
||||
$this->assertEqual(count($this->dbh), $count + 1);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user