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