Skip to content

Commit

Permalink
#1188 - accessing `Doctrine\ORM\Tools\Pagination\Paginator#getCountQu…
Browse files Browse the repository at this point in the history
…ery()` via reflection for test purposes
  • Loading branch information
Ocramius committed Nov 28, 2014
1 parent 5f9dc2e commit 684ae85
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions tests/Doctrine/Tests/ORM/Functional/PaginationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Doctrine\Tests\Models\CMS\CmsArticle;
use Doctrine\Tests\Models\CMS\CmsComment;
use Doctrine\ORM\Tools\Pagination\Paginator;
use ReflectionMethod;

/**
* @group DDC-1613
Expand Down Expand Up @@ -151,7 +152,7 @@ public function testQueryWalkerIsKept()
$this->assertEquals(1, $paginator->count());
}

public function testCountQuery_ParametersInSelect()
public function testCountQueryStripsParametersInSelect()
{
/** @var $query Query */
$query = $this->_em->createQuery(
Expand All @@ -162,13 +163,23 @@ public function testCountQuery_ParametersInSelect()
$query->setFirstResult(null)->setMaxResults(null);

$paginator = new Paginator($query);
$countQuery = $paginator->getCountQuery();

//
$getCountQuery = new ReflectionMethod($paginator, 'getCountQuery');

$getCountQuery->setAccessible(true);

$countQuery = $getCountQuery->invoke($paginator);

$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();

$countQuery = $getCountQuery->invoke($paginator);

//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());
Expand Down

0 comments on commit 684ae85

Please sign in to comment.