From 91638aadcfe9675e8c3d3f85dbfd5ba3cad56b53 Mon Sep 17 00:00:00 2001 From: Roger Llopart Pla Date: Wed, 3 Jul 2013 11:18:19 +0000 Subject: [PATCH] Added a test which verifies that the tree walkers are kept. --- .../Tests/ORM/Functional/PaginationTest.php | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Functional/PaginationTest.php b/tests/Doctrine/Tests/ORM/Functional/PaginationTest.php index 0a2845582..15c043d84 100644 --- a/tests/Doctrine/Tests/ORM/Functional/PaginationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/PaginationTest.php @@ -139,6 +139,18 @@ class PaginationTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertTrue($query->getParameters()->isEmpty()); } + public function testQueryWalkerIsKept() + { + $dql = "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u"; + $query = $this->_em->createQuery($dql); + $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\Tests\ORM\Functional\CustomTreeWalker')); + + $paginator = new Paginator($query, true); + $paginator->setUseOutputWalkers(false); + $this->assertCount(1, $paginator->getIterator()); + $this->assertEquals(1, $paginator->count()); + } + public function populate() { for ($i = 0; $i < 3; $i++) { @@ -166,3 +178,22 @@ class PaginationTest extends \Doctrine\Tests\OrmFunctionalTestCase ); } } + +class CustomTreeWalker extends Query\TreeWalkerAdapter +{ + public function walkSelectStatement(Query\AST\SelectStatement $selectStatement) + { + $condition = new Query\AST\ConditionalPrimary(); + + $path = new Query\AST\PathExpression(Query\AST\PathExpression::TYPE_STATE_FIELD, 'u', 'name'); + $path->type = Query\AST\PathExpression::TYPE_STATE_FIELD; + + $condition->simpleConditionalExpression = new Query\AST\ComparisonExpression( + $path, + '=', + new Query\AST\Literal(Query\AST\Literal::STRING, 'Name1') + ); + + $selectStatement->whereClause = new Query\AST\WhereClause($condition); + } +}