From 34711038921b3b3546f18cbc18e8bcb62a3f1ebc Mon Sep 17 00:00:00 2001 From: zYne Date: Tue, 31 Jul 2007 19:33:17 +0000 Subject: [PATCH] --- tests/Query/AggregateValueTestCase.php | 20 +++++++++---------- tests/Query/JoinConditionTestCase.php | 8 ++++---- tests/Query/JoinTestCase.php | 27 +++++++++++++++++++++++++- tests/Query/SubqueryTestCase.php | 4 ++-- 4 files changed, 42 insertions(+), 17 deletions(-) diff --git a/tests/Query/AggregateValueTestCase.php b/tests/Query/AggregateValueTestCase.php index 5bb064e2f..7e6ea864b 100644 --- a/tests/Query/AggregateValueTestCase.php +++ b/tests/Query/AggregateValueTestCase.php @@ -53,7 +53,7 @@ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase $users->save(); } - + /** public function testRecordSupportsValueMapping() { $record = new User(); @@ -77,7 +77,7 @@ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase public function testAggregateValueIsMappedToNewRecordOnEmptyResultSet() { - $this->connection->clear(); + $this->connection->clear(); $q = new Doctrine_Query(); @@ -124,21 +124,21 @@ class Doctrine_Query_AggregateValue_TestCase extends Doctrine_UnitTestCase $this->assertEqual($users[0]->count, 2); $this->assertEqual($users[1]->count, 2); } - + */ public function testAggregateValueMappingSupportsLeftJoins() { $q = new Doctrine_Query(); $q->select('u.name, COUNT(p.id) count')->from('User u')->leftJoin('u.Phonenumber p')->groupby('u.id'); - - $users = $q->execute(); - $this->assertEqual($users->count(), 4); + $users = $q->execute(); - $this->assertEqual($users[0]->Phonenumber[0]->count, 3); - $this->assertEqual($users[1]->Phonenumber[0]->count, 0); - $this->assertEqual($users[2]->Phonenumber[0]->count, 2); - $this->assertEqual($users[3]->Phonenumber[0]->count, 1); + $this->assertEqual(count($users), 4); + + $this->assertEqual($users[0]['Phonenumber'][0]['count'], 3); + $this->assertEqual($users[1]['Phonenumber'][0]['count'], 0); + $this->assertEqual($users[2]['Phonenumber'][0]['count'], 2); + $this->assertEqual($users[3]['Phonenumber'][0]['count'], 1); } public function testAggregateValueMappingSupportsLeftJoins2() diff --git a/tests/Query/JoinConditionTestCase.php b/tests/Query/JoinConditionTestCase.php index 823fa8203..7a0901ff8 100644 --- a/tests/Query/JoinConditionTestCase.php +++ b/tests/Query/JoinConditionTestCase.php @@ -42,7 +42,7 @@ class Doctrine_Query_JoinCondition_TestCase extends Doctrine_UnitTestCase $q->parseQuery("SELECT u.name, p.id FROM User u LEFT JOIN u.Phonenumber p ON p.phonenumber = '123 123'"); - $this->assertEqual($q->getQuery(), "SELECT e.id AS e__id, e.name AS e__name, p.id AS p__id FROM entity e LEFT JOIN phonenumber p ON e.id = p.entity_id AND p.phonenumber = '123 123' WHERE (e.type = 0)"); + $this->assertEqual($q->getQuery(), "SELECT e.id AS e__id, e.name AS e__name, p.id AS p__id FROM entity e LEFT JOIN phonenumber p ON p.phonenumber = '123 123' WHERE (e.type = 0)"); } public function testJoinConditionsAreSupportedForOneToManyInnerJoins() { @@ -50,7 +50,7 @@ class Doctrine_Query_JoinCondition_TestCase extends Doctrine_UnitTestCase $q->parseQuery("SELECT u.name, p.id FROM User u INNER JOIN u.Phonenumber p ON p.phonenumber = '123 123'"); - $this->assertEqual($q->getQuery(), "SELECT e.id AS e__id, e.name AS e__name, p.id AS p__id FROM entity e INNER JOIN phonenumber p ON e.id = p.entity_id AND p.phonenumber = '123 123' WHERE (e.type = 0)"); + $this->assertEqual($q->getQuery(), "SELECT e.id AS e__id, e.name AS e__name, p.id AS p__id FROM entity e INNER JOIN phonenumber p ON p.phonenumber = '123 123' WHERE (e.type = 0)"); } public function testJoinConditionsAreSupportedForManyToManyLeftJoins() { @@ -58,7 +58,7 @@ class Doctrine_Query_JoinCondition_TestCase extends Doctrine_UnitTestCase $q->parseQuery("SELECT u.name, g.id FROM User u LEFT JOIN u.Group g ON g.id > 2"); - $this->assertEqual($q->getQuery(), "SELECT e.id AS e__id, e.name AS e__name, e2.id AS e2__id FROM entity e LEFT JOIN groupuser g ON e.id = g.user_id LEFT JOIN entity e2 ON e2.id = g.group_id AND e2.id > 2 WHERE (e.type = 0 AND (e2.type = 1 OR e2.type IS NULL))"); + $this->assertEqual($q->getQuery(), "SELECT e.id AS e__id, e.name AS e__name, e2.id AS e2__id FROM entity e LEFT JOIN groupuser g ON e.id = g.user_id LEFT JOIN entity e2 ON e2.id > 2 WHERE (e.type = 0 AND (e2.type = 1 OR e2.type IS NULL))"); } public function testJoinConditionsAreSupportedForManyToManyInnerJoins() { @@ -66,6 +66,6 @@ class Doctrine_Query_JoinCondition_TestCase extends Doctrine_UnitTestCase $q->parseQuery("SELECT u.name, g.id FROM User u INNER JOIN u.Group g ON g.id > 2"); - $this->assertEqual($q->getQuery(), "SELECT e.id AS e__id, e.name AS e__name, e2.id AS e2__id FROM entity e INNER JOIN groupuser g ON e.id = g.user_id INNER JOIN entity e2 ON e2.id = g.group_id AND e2.id > 2 WHERE (e.type = 0 AND (e2.type = 1 OR e2.type IS NULL))"); + $this->assertEqual($q->getQuery(), "SELECT e.id AS e__id, e.name AS e__name, e2.id AS e2__id FROM entity e INNER JOIN groupuser g ON e.id = g.user_id INNER JOIN entity e2 ON e2.id > 2 WHERE (e.type = 0 AND (e2.type = 1 OR e2.type IS NULL))"); } } diff --git a/tests/Query/JoinTestCase.php b/tests/Query/JoinTestCase.php index 0389ae9db..6461b3bd3 100644 --- a/tests/Query/JoinTestCase.php +++ b/tests/Query/JoinTestCase.php @@ -61,6 +61,29 @@ class Doctrine_Query_Join_TestCase extends Doctrine_UnitTestCase $this->connection->clear(); } + + public function testQuerySupportsCustomJoins() + { + $q = new Doctrine_Query(); + + $q->select('c.*, c2.*, d.*') + ->from('Record_Country c')->innerJoin('c.City c2 ON c2.id = 2') + ->where('c.id = ?', array(1)); + + $this->assertEqual($q->getSql(), 'SELECT r.id AS r__id, r.name AS r__name, r2.id AS r2__id, r2.name AS r2__name, r2.country_id AS r2__country_id, r2.district_id AS r2__district_id FROM record__country r INNER JOIN record__city r2 ON r2.id = 2 WHERE r.id = ?'); + } + + public function testQuerySupportsCustomJoinsAndWithKeyword() + { + $q = new Doctrine_Query(); + + $q->select('c.*, c2.*, d.*') + ->from('Record_Country c')->innerJoin('c.City c2 WITH c2.id = 2') + ->where('c.id = ?', array(1)); + + $this->assertEqual($q->getSql(), 'SELECT r.id AS r__id, r.name AS r__name, r2.id AS r2__id, r2.name AS r2__name, r2.country_id AS r2__country_id, r2.district_id AS r2__district_id FROM record__country r INNER JOIN record__city r2 ON r.id = r2.country_id AND r2.id = 2 WHERE r.id = ?'); + } + public function testRecordHydrationWorksWithDeeplyNestedStructuresAndArrayFetching() { $q = new Doctrine_Query(); @@ -100,6 +123,7 @@ class Doctrine_Query_Join_TestCase extends Doctrine_UnitTestCase $this->assertEqual($c->City[0]->District->name, 'District 1'); $this->assertEqual($c->City[2]->District->name, 'District 2'); } + public function testManyToManyJoinUsesProperTableAliases() { $q = new Doctrine_Query(); @@ -117,6 +141,7 @@ class Doctrine_Query_Join_TestCase extends Doctrine_UnitTestCase $this->assertEqual($q->getQuery(), 'SELECT e.id AS e__id, e.name AS e__name FROM entity e INNER JOIN entity_reference e3 ON e.id = e3.entity1 OR e.id = e3.entity2 INNER JOIN entity e2 ON (e2.id = e3.entity2 OR e2.id = e3.entity1) AND e2.id != e.id'); } + public function testMultipleJoins() { $q = new Doctrine_Query(); @@ -131,6 +156,7 @@ class Doctrine_Query_Join_TestCase extends Doctrine_UnitTestCase $this->fail(); } } + public function testMultipleJoins2() { $q = new Doctrine_Query(); @@ -145,5 +171,4 @@ class Doctrine_Query_Join_TestCase extends Doctrine_UnitTestCase $this->fail(); } } - } diff --git a/tests/Query/SubqueryTestCase.php b/tests/Query/SubqueryTestCase.php index 63d3e38bc..c0eb6490c 100644 --- a/tests/Query/SubqueryTestCase.php +++ b/tests/Query/SubqueryTestCase.php @@ -63,9 +63,9 @@ class Doctrine_Query_Subquery_TestCase extends Doctrine_UnitTestCase $q->parseQuery("SELECT u.name, (SELECT COUNT(p.id) FROM Phonenumber p WHERE p.entity_id = u.id) pcount FROM User u WHERE u.name = 'zYne' LIMIT 1"); - $this->assertEqual($q->getQuery(), "SELECT e.id AS e__id, e.name AS e__name, (SELECT COUNT(p.id) AS p__0 FROM phonenumber p WHERE p.entity_id = e.id) AS e__0 FROM entity e WHERE e.name = 'zYne' AND (e.type = 0) LIMIT 1"); + $this->assertEqual($q->getQuery(), "SELECT e.id AS e__id, e.name AS e__name, (SELECT COUNT(p.id) AS p__0 FROM phonenumber p WHERE p.entity_id = e.id AND (e.type = 0)) AS e__0 FROM entity e WHERE e.name = 'zYne' AND (e.type = 0) LIMIT 1"); // test consequent call - $this->assertEqual($q->getQuery(), "SELECT e.id AS e__id, e.name AS e__name, (SELECT COUNT(p.id) AS p__0 FROM phonenumber p WHERE p.entity_id = e.id) AS e__0 FROM entity e WHERE e.name = 'zYne' AND (e.type = 0) LIMIT 1"); + $this->assertEqual($q->getQuery(), "SELECT e.id AS e__id, e.name AS e__name, (SELECT COUNT(p.id) AS p__0 FROM phonenumber p WHERE p.entity_id = e.id AND (e.type = 0)) AS e__0 FROM entity e WHERE e.name = 'zYne' AND (e.type = 0) LIMIT 1"); $users = $q->execute();