From 063d0f876dfdb07ec30bd4c8d90ba6388f8d590a Mon Sep 17 00:00:00 2001 From: zYne Date: Tue, 29 May 2007 18:32:58 +0000 Subject: [PATCH] --- tests/Collection/SnapshotTestCase.php | 13 +++++- tests/Hydrate/FetchModeTestCase.php | 66 +++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 2 deletions(-) diff --git a/tests/Collection/SnapshotTestCase.php b/tests/Collection/SnapshotTestCase.php index 687f878d0..793f79cad 100644 --- a/tests/Collection/SnapshotTestCase.php +++ b/tests/Collection/SnapshotTestCase.php @@ -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); } + } diff --git a/tests/Hydrate/FetchModeTestCase.php b/tests/Hydrate/FetchModeTestCase.php index e0b1267d8..e8a61c886 100644 --- a/tests/Hydrate/FetchModeTestCase.php +++ b/tests/Hydrate/FetchModeTestCase.php @@ -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); + } }