From fa014ee55ded1bc598ce98c9fa30ad201db5b52f Mon Sep 17 00:00:00 2001 From: Merixstudio Date: Mon, 24 Nov 2014 15:28:37 +0100 Subject: [PATCH] Test parameter removing parameters passed to select part of query. --- .../Tests/ORM/Functional/PaginationTest.php | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Functional/PaginationTest.php b/tests/Doctrine/Tests/ORM/Functional/PaginationTest.php index bf9e4a685..487a57577 100644 --- a/tests/Doctrine/Tests/ORM/Functional/PaginationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/PaginationTest.php @@ -150,6 +150,43 @@ class PaginationTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertCount(1, $paginator->getIterator()); $this->assertEquals(1, $paginator->count()); } + + public function testCountQuery_ParametersInSelect() + { + /** @var $query Query */ + $query = $this->_em->createQuery( + 'SELECT u, (CASE WHEN u.id < :vipMaxId THEN 1 ELSE 0 END) AS hidden promotedFirst FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id < :id ORDER BY promotedFirst' + ); + $query->setParameter('vipMaxId', 10); + $query->setParameter('id', 100); + $query->setFirstResult(null)->setMaxResults(null); + + $this->assertEquals( + "SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3, (CASE WHEN c0_.id < ? THEN 1 ELSE 0 END) AS sclr4, c0_.email_id AS email_id5 FROM cms_users c0_ WHERE c0_.id < ? ORDER BY sclr4 ASC", + $query->getSQL() + ); + $paginator = new Paginator($query); + $countQuery = $paginator->getCountQuery(); + + $this->assertEquals( + "SELECT COUNT(*) AS dctrn_count FROM (SELECT DISTINCT id0 FROM (SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3, (CASE WHEN c0_.id < ? THEN 1 ELSE 0 END) AS sclr4, c0_.email_id AS email_id5 FROM cms_users c0_ WHERE c0_.id < ? ORDER BY sclr4 ASC) dctrn_result) dctrn_table", + $countQuery->getSQL() + ); + $this->assertEquals(2, count($countQuery->getParameters())); + $this->assertEquals(3, $paginator->count()); + + + $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Query\SqlWalker'); + $paginator = new Paginator($query); + $countQuery = $paginator->getCountQuery(); + $this->assertEquals( + "SELECT count(DISTINCT c0_.id) AS sclr0 FROM cms_users c0_ WHERE c0_.id < ?", + $countQuery->getSQL() + ); + //if select part of query is replaced with count(...) paginator should remove parameters from query object not used in new query. + $this->assertEquals(1, count($countQuery->getParameters())); + $this->assertEquals(3, $paginator->count()); + } public function populate() {