From 1242c8e8460dc5acf95dceebd99c97d4e39c5083 Mon Sep 17 00:00:00 2001 From: "Jonathan.Wage" Date: Wed, 27 Jun 2007 18:02:08 +0000 Subject: [PATCH] added test case for using aggregate functions in the orderby/having --- tests/Query/MysqlSubqueryHavingTestCase.php | 57 +++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 tests/Query/MysqlSubqueryHavingTestCase.php diff --git a/tests/Query/MysqlSubqueryHavingTestCase.php b/tests/Query/MysqlSubqueryHavingTestCase.php new file mode 100644 index 000000000..7a573d789 --- /dev/null +++ b/tests/Query/MysqlSubqueryHavingTestCase.php @@ -0,0 +1,57 @@ +. + */ + +/** + * Doctrine_Query_MysqlSubquery_TestCase + * + * @package Doctrine + * @author Konsta Vesterinen + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @category Object Relational Mapping + * @link www.phpdoctrine.com + * @since 1.0 + * @version $Revision$ + */ +class Doctrine_Query_MysqlSubqueryHaving_TestCase extends Doctrine_UnitTestCase +{ + public function setUp() + { + $this->dbh = new Doctrine_Adapter_Mock('mysql'); + $this->conn = Doctrine_Manager::getInstance()->openConnection($this->dbh); + } + + public function testGetLimitSubqueryWithHavingOnAggregateValues() + { + $q = new Doctrine_Query(); + $q->select('u.name, COUNT(DISTINCT a.id) num_albums'); + $q->from('User u, u.Album a'); + $q->orderby('num_albums DESC'); + $q->having('num_albums > 0'); + $q->groupby('u.id'); + $q->limit(5); + + $q->execute(); + + $this->dbh->pop(); + + $this->assertEqual($this->dbh->pop(), 'SELECT DISTINCT e2.id, COUNT(DISTINCT a2.id) AS a2__0 FROM entity e2 LEFT JOIN album a2 ON e2.id = a2.user_id WHERE (e2.type = 0) GROUP BY e2.id HAVING a2__0 > 0 ORDER BY a2__0 LIMIT 5'); + } +} \ No newline at end of file