From 2e6ed4d02f11cfbca5adcdda28e8bff22862a4b9 Mon Sep 17 00:00:00 2001 From: romanb Date: Sat, 2 Jun 2007 11:36:31 +0000 Subject: [PATCH] Updated 2 test cases to outline two major issues with the new hydration (at least i think that it has to do with the problems): 1) When the result set is in a custom order, components may be doubled (this already occured half a year ago though the symptoms were different (items were assigned to the wrong collection). 2) Accessing related components that are already loaded (but empty) results in lots of extra queries. The only way to get around that is do wrap an isset() check around nearly all places before accessing a relation. This was not the case in earlier revisions though at that time an isset() was sometimes needed, too to prevent extra queries. But now it seems to be necessary everywhere. --- tests/CustomResultSetOrderTestCase.php | 12 +++++++++--- tests/Query/MultiJoin2TestCase.php | 26 ++++++++++++++++++++++++++ tests/run.php | 2 +- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/tests/CustomResultSetOrderTestCase.php b/tests/CustomResultSetOrderTestCase.php index 67523562f..ba8dc1d02 100644 --- a/tests/CustomResultSetOrderTestCase.php +++ b/tests/CustomResultSetOrderTestCase.php @@ -98,9 +98,15 @@ class Doctrine_CustomResultSetOrder_TestCase extends Doctrine_UnitTestCase { * 3 | 2 | Third | NULL */ public function testQueryWithOrdering() { - $categories = $this->connection->query("FROM CategoryWithPosition.Boards - ORDER BY CategoryWithPosition.position ASC, CategoryWithPosition.Boards.position ASC"); + $q = new Doctrine_Query($this->connection); + $categories = $q->select("c.*, b.*") + ->from("CategoryWithPosition c") + ->leftJoin("c.Boards b") + ->orderBy("c.position ASC, b.position ASC") + ->execute(); + $this->assertEqual(3, $categories->count(), "Some categories were doubled!"); + // Check each category foreach ($categories as $category) { @@ -117,7 +123,7 @@ class Doctrine_CustomResultSetOrder_TestCase extends Doctrine_UnitTestCase { case "Third": // The third has no boards as expected. $this->assertEqual(0, $category->Boards->count()); - break; + break; } } diff --git a/tests/Query/MultiJoin2TestCase.php b/tests/Query/MultiJoin2TestCase.php index 66e1a78de..7edbb99d3 100644 --- a/tests/Query/MultiJoin2TestCase.php +++ b/tests/Query/MultiJoin2TestCase.php @@ -59,6 +59,7 @@ class Doctrine_Query_MultiJoin2_TestCase extends Doctrine_UnitTestCase { } public function testMultipleJoinFetchingWithDeepJoins() { $query = new Doctrine_Query($this->connection); + $queryCount = $this->connection->getDbh()->count(); try { $categories = $query->select('c.*, subCats.*, b.*, le.*, a.*') ->from('QueryTest_Category c') @@ -69,6 +70,31 @@ class Doctrine_Query_MultiJoin2_TestCase extends Doctrine_UnitTestCase { ->where('c.parentCategoryId = 0') ->orderBy('c.position ASC, subCats.position ASC, b.position ASC') ->execute(); + // Test that accessing a loaded (but empty) relation doesnt trigger an extra query + $this->assertEqual($queryCount + 1, $this->connection->getDbh()->count()); + $categories[0]->subCategories; + $this->assertEqual($queryCount + 1, $this->connection->getDbh()->count()); + } catch (Doctrine_Exception $e) { + $this->fail(); + } + } + + public function testMultipleJoinFetchingWithArrayFetching() { + $query = new Doctrine_Query($this->connection); + $queryCount = $this->connection->getDbh()->count(); + try { + $categories = $query->select('c.*, subCats.*, b.*, le.*, a.*') + ->from('QueryTest_Category c') + ->leftJoin('c.subCategories subCats') + ->leftJoin('c.boards b') + ->leftJoin('b.lastEntry le') + ->leftJoin('le.author a') + ->where('c.parentCategoryId = 0') + ->orderBy('c.position ASC, subCats.position ASC, b.position ASC') + ->execute(array(), Doctrine::FETCH_ARRAY); + //echo "
";
+            //var_dump($categories);
+            //echo "
"; $this->pass(); } catch (Doctrine_Exception $e) { $this->fail(); diff --git a/tests/run.php b/tests/run.php index 5fa276670..bd6f8910c 100644 --- a/tests/run.php +++ b/tests/run.php @@ -200,7 +200,7 @@ $test->addTestCase(new Doctrine_SchemaTestCase()); $test->addTestCase(new Doctrine_Query_Condition_TestCase()); $test->addTestCase(new Doctrine_CustomPrimaryKey_TestCase()); -$test->addTestCase(new Doctrine_CustomResultSetOrderTestCase()); +$test->addTestCase(new Doctrine_CustomResultSetOrder_TestCase()); // Query tests