From 91988123a03b0d81722cdeac76f76098c0732019 Mon Sep 17 00:00:00 2001 From: doctrine Date: Sun, 16 Apr 2006 22:17:23 +0000 Subject: [PATCH] --- classes/Collection/Batch.class.php | 4 ++- tests/BatchIteratorTestCase.class.php | 36 +++++++++++++++++++++++++-- tests/classes.php | 5 ++-- tests/run.php | 7 +++--- 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/classes/Collection/Batch.class.php b/classes/Collection/Batch.class.php index 6c3424df3..4931975e2 100644 --- a/classes/Collection/Batch.class.php +++ b/classes/Collection/Batch.class.php @@ -102,11 +102,13 @@ class Doctrine_Collection_Batch extends Doctrine_Collection { $query .= ($c > 1)?"id IN (":"id = "; $query .= substr(str_repeat("?, ",count($a)),0,-2); $query .= ($c > 1)?")":""; + $query .= " ORDER BY id ASC"; $stmt = $this->table->getSession()->execute($query,array_values($a)); - foreach($a as $k => $id) { + foreach($a as $k => $id) { $row = $stmt->fetch(PDO::FETCH_ASSOC); + if($row === false) break; diff --git a/tests/BatchIteratorTestCase.class.php b/tests/BatchIteratorTestCase.class.php index 30711e652..e7a85ddcb 100644 --- a/tests/BatchIteratorTestCase.class.php +++ b/tests/BatchIteratorTestCase.class.php @@ -13,8 +13,40 @@ class Doctrine_BatchIteratorTestCase extends Doctrine_UnitTestCase { $user = $graph->query("FROM User"); foreach($user[1]->Group as $group) { - print $group->name; - } + $this->assertTrue(is_string($group->name)); + } + + $user = new User(); + $user->name = "tester"; + + $user->Address[0]->address = "street 1"; + $user->Address[1]->address = "street 2"; + + $this->assertEqual($user->name, "tester"); + $this->assertEqual($user->Address[0]->address, "street 1"); + $this->assertEqual($user->Address[1]->address, "street 2"); + + foreach($user->Address as $address) { + $a[] = $address->address; + } + $this->assertEqual($a, array("street 1", "street 2")); + + $user->save(); + + $user = $user->getTable()->find($user->getID()); + $this->assertEqual($user->name, "tester"); + $this->assertEqual($user->Address[0]->address, "street 1"); + $this->assertEqual($user->Address[1]->address, "street 2"); + + $user = $user->getTable()->find($user->getID()); + $a = array(); + foreach($user->Address as $address) { + $a[] = $address->address; + } + $this->assertEqual($a, array("street 1", "street 2")); + + + $user = $graph->query("FROM User"); } } diff --git a/tests/classes.php b/tests/classes.php index 2637c95d3..6c6f3769f 100644 --- a/tests/classes.php +++ b/tests/classes.php @@ -3,8 +3,6 @@ class Entity extends Doctrine_Record { public function setUp() { $this->ownsOne("Email","Entity.email_id"); $this->ownsMany("Phonenumber","Phonenumber.entity_id"); - $this->hasMany("Address","Entityaddress.address_id"); - $this->setAttribute(Doctrine::ATTR_FETCHMODE,Doctrine::FETCH_BATCH); } public function setTableDefinition() { @@ -25,7 +23,7 @@ class EntityAddress extends Doctrine_Record { } class Address extends Doctrine_Record { public function setUp() { - $this->hasMany("Entity","Entityaddress.entity_id"); + $this->hasMany("User","Entityaddress.entity_id"); } public function setTableDefinition() { $this->hasColumn("address","string",200); @@ -63,6 +61,7 @@ class UserTable extends Doctrine_Table { } class User extends Entity { public function setUp() { parent::setUp(); + $this->hasMany("Address","Entityaddress.address_id"); $this->ownsMany("Album","Album.user_id"); $this->hasMany("Group","Groupuser.group_id"); $this->setInheritanceMap(array("type"=>0)); diff --git a/tests/run.php b/tests/run.php index e31e7e66a..9bfee4513 100644 --- a/tests/run.php +++ b/tests/run.php @@ -24,7 +24,7 @@ $test = new GroupTest("Doctrine Framework Unit Tests"); -/** + $test->addTestCase(new Doctrine_RecordTestCase()); @@ -39,17 +39,16 @@ $test->addTestCase(new Doctrine_AccessTestCase()); $test->addTestCase(new Doctrine_EventListenerTestCase()); -*/ + $test->addTestCase(new Doctrine_BatchIteratorTestCase()); -/** $test->addTestCase(new Doctrine_DQL_ParserTestCase()); $test->addTestCase(new Doctrine_CollectionTestCase()); $test->addTestCase(new Doctrine_ConfigurableTestCase()); $test->addTestCase(new Sensei_UnitTestCase()); -*/ + //$test->addTestCase(new Doctrine_Cache_FileTestCase()); //$test->addTestCase(new Doctrine_Cache_SqliteTestCase());