2012-01-22 16:35:06 +04:00
< ? php
namespace Doctrine\Tests\ORM\Tools\Pagination ;
use Doctrine\ORM\Query ;
/**
* @ group DDC - 1613
*/
class LimitSubqueryWalkerTest extends PaginationTestCase
{
public function testLimitSubquery ()
{
$query = $this -> entityManager -> createQuery (
2012-03-07 11:57:51 +04:00
'SELECT p, c, a FROM Doctrine\Tests\ORM\Tools\Pagination\MyBlogPost p JOIN p.category c JOIN p.author a' );
2012-01-22 16:35:06 +04:00
$limitQuery = clone $query ;
$limitQuery -> setHint ( Query :: HINT_CUSTOM_TREE_WALKERS , array ( 'Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker' ));
$this -> assertEquals (
2012-03-07 11:57:51 +04:00
" SELECT DISTINCT m0_.id AS id0 FROM MyBlogPost m0_ INNER JOIN Category c1_ ON m0_.category_id = c1_.id INNER JOIN Author a2_ ON m0_.author_id = a2_.id " , $limitQuery -> getSql ()
2012-01-22 16:35:06 +04:00
);
}
2012-09-18 15:56:32 +04:00
public function testLimitSubqueryWithSort ()
{
$query = $this -> entityManager -> createQuery (
'SELECT p, c, a FROM Doctrine\Tests\ORM\Tools\Pagination\MyBlogPost p JOIN p.category c JOIN p.author a ORDER BY p.title' );
$limitQuery = clone $query ;
$limitQuery -> setHint ( Query :: HINT_CUSTOM_TREE_WALKERS , array ( 'Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker' ));
$this -> assertEquals (
" SELECT DISTINCT m0_.id AS id0, m0_.title AS title1 FROM MyBlogPost m0_ INNER JOIN Category c1_ ON m0_.category_id = c1_.id INNER JOIN Author a2_ ON m0_.author_id = a2_.id ORDER BY m0_.title ASC " , $limitQuery -> getSql ()
);
}
2012-01-22 16:35:06 +04:00
public function testCountQuery_MixedResultsWithName ()
{
$query = $this -> entityManager -> createQuery (
2012-03-07 11:57:51 +04:00
'SELECT a, sum(a.name) as foo FROM Doctrine\Tests\ORM\Tools\Pagination\Author a' );
2012-01-22 16:35:06 +04:00
$limitQuery = clone $query ;
$limitQuery -> setHint ( Query :: HINT_CUSTOM_TREE_WALKERS , array ( 'Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker' ));
$this -> assertEquals (
2012-03-07 11:57:51 +04:00
" SELECT DISTINCT a0_.id AS id0, sum(a0_.name) AS sclr1 FROM Author a0_ " , $limitQuery -> getSql ()
2012-01-22 16:35:06 +04:00
);
}
}