1
0
mirror of synced 2025-01-18 06:21:40 +03:00
This commit is contained in:
zYne 2007-09-12 21:43:39 +00:00
parent 7359ee0e53
commit 3a93d7f271
2 changed files with 28 additions and 14 deletions

View File

@ -38,6 +38,6 @@ class Doctrine_Query_Groupby_TestCase extends Doctrine_UnitTestCase
$q->parseQuery('SELECT u.name, COUNT(p.id) count FROM User u LEFT JOIN u.Phonenumber p GROUP BY count'); $q->parseQuery('SELECT u.name, COUNT(p.id) count FROM User u LEFT JOIN u.Phonenumber p GROUP BY count');
$this->assertEqual($q->getQuery(), ''); $this->assertEqual($q->getQuery(), 'SELECT e.id AS e__id, e.name AS e__name, COUNT(p.id) AS p__0 FROM entity e LEFT JOIN phonenumber p ON e.id = p.entity_id WHERE (e.type = 0) GROUP BY p__0');
} }
} }

View File

@ -32,6 +32,16 @@
*/ */
class Doctrine_Query_Select_TestCase extends Doctrine_UnitTestCase class Doctrine_Query_Select_TestCase extends Doctrine_UnitTestCase
{ {
/**
public function testParseSelect()
{
$q = new Doctrine_Query();
$q->select('TRIM(u.name) name')->from('User u');
$q->execute();
}
public function testAggregateFunctionParsingSupportsMultipleComponentReferences() public function testAggregateFunctionParsingSupportsMultipleComponentReferences()
{ {
$q = new Doctrine_Query(); $q = new Doctrine_Query();
@ -88,6 +98,7 @@ class Doctrine_Query_Select_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($q->getQuery(), 'SELECT MAX(e.id) AS e__0, MIN(e.name) AS e__1 FROM entity e WHERE (e.type = 0)'); $this->assertEqual($q->getQuery(), 'SELECT MAX(e.id) AS e__0, MIN(e.name) AS e__1 FROM entity e WHERE (e.type = 0)');
} }
public function testMultipleAggregateFunctionsWithMultipleComponents() public function testMultipleAggregateFunctionsWithMultipleComponents()
{ {
$q = new Doctrine_Query(); $q = new Doctrine_Query();
@ -96,6 +107,7 @@ class Doctrine_Query_Select_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($q->getQuery(), 'SELECT MAX(e.id) AS e__0, MIN(e.name) AS e__1, COUNT(p.id) AS p__2 FROM entity e LEFT JOIN phonenumber p ON e.id = p.entity_id WHERE (e.type = 0)'); $this->assertEqual($q->getQuery(), 'SELECT MAX(e.id) AS e__0, MIN(e.name) AS e__1, COUNT(p.id) AS p__2 FROM entity e LEFT JOIN phonenumber p ON e.id = p.entity_id WHERE (e.type = 0)');
} }
public function testEmptySelectPart() public function testEmptySelectPart()
{ {
$q = new Doctrine_Query(); $q = new Doctrine_Query();
@ -108,34 +120,35 @@ class Doctrine_Query_Select_TestCase extends Doctrine_UnitTestCase
$this->pass(); $this->pass();
} }
} }
*/
public function testUnknownAggregateFunction() public function testUnknownAggregateFunction()
{ {
$q = new Doctrine_Query(); $q = new Doctrine_Query();
try { try {
$q->parseQuery('SELECT UNKNOWN(u.id) FROM User'); $q->parseQuery('SELECT UNKNOWN(u.id) FROM User u');
$q->getQuery(); $q->getQuery();
$this->fail(); $this->fail();
} catch(Doctrine_Query_Exception $e) { } catch(Doctrine_Query_Exception $e) {
$this->pass(); $this->pass();
} }
} }
public function testAggregateFunctionValueHydration() public function testAggregateFunctionValueHydration()
{ {
$q = new Doctrine_Query(); $q = new Doctrine_Query();
$q->parseQuery('SELECT u.id, COUNT(p.id) FROM User u LEFT JOIN u.Phonenumber p GROUP BY u.id'); $q->parseQuery('SELECT u.id, u.name, COUNT(p.id) FROM User u LEFT JOIN u.Phonenumber p GROUP BY u.id');
$users = $q->execute(); $users = $q->execute(array(), Doctrine::FETCH_ARRAY);
$this->assertEqual($users[0]->Phonenumber[0]->COUNT, 1); $this->assertEqual($users[0]['Phonenumber'][0]['COUNT'], 1);
$this->assertEqual($users[1]->Phonenumber[0]->COUNT, 3); $this->assertEqual($users[1]['Phonenumber'][0]['COUNT'], 3);
$this->assertEqual($users[2]->Phonenumber[0]->COUNT, 1); $this->assertEqual($users[2]['Phonenumber'][0]['COUNT'], 1);
$this->assertEqual($users[3]->Phonenumber[0]->COUNT, 1); $this->assertEqual($users[3]['Phonenumber'][0]['COUNT'], 1);
$this->assertEqual($users[4]->Phonenumber[0]->COUNT, 3); $this->assertEqual($users[4]['Phonenumber'][0]['COUNT'], 3);
} }
public function testSingleComponentWithAsterisk() public function testSingleComponentWithAsterisk()
@ -230,4 +243,5 @@ class Doctrine_Query_Select_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($users[3]->Phonenumber[0]->max, '111 222 333'); $this->assertEqual($users[3]->Phonenumber[0]->max, '111 222 333');
$this->assertEqual($users[4]->Phonenumber[0]->max, '444 555'); $this->assertEqual($users[4]->Phonenumber[0]->max, '444 555');
} }
} }