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 ()
{
2014-04-17 23:29:18 +04:00
$dql = 'SELECT p, c, a FROM Doctrine\Tests\ORM\Tools\Pagination\MyBlogPost p JOIN p.category c JOIN p.author a' ;
$query = $this -> entityManager -> createQuery ( $dql );
2012-01-22 16:35:06 +04:00
$limitQuery = clone $query ;
2014-04-17 23:29:18 +04:00
2012-01-22 16:35:06 +04:00
$limitQuery -> setHint ( Query :: HINT_CUSTOM_TREE_WALKERS , array ( 'Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker' ));
$this -> assertEquals (
2014-04-17 23:29:18 +04:00
" SELECT DISTINCT m0_.id AS id_0 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 ()
{
2014-04-17 23:29:18 +04:00
$dql = 'SELECT p, c, a FROM Doctrine\Tests\ORM\Tools\Pagination\MyBlogPost p JOIN p.category c JOIN p.author a ORDER BY p.title' ;
$query = $this -> entityManager -> createQuery ( $dql );
2012-09-18 15:56:32 +04:00
$limitQuery = clone $query ;
2014-04-17 23:29:18 +04:00
2012-09-18 15:56:32 +04:00
$limitQuery -> setHint ( Query :: HINT_CUSTOM_TREE_WALKERS , array ( 'Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker' ));
$this -> assertEquals (
2014-04-17 23:29:18 +04:00
" SELECT DISTINCT m0_.id AS id_0, m0_.title AS title_1 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-09-18 15:56:32 +04:00
);
}
2012-01-22 16:35:06 +04:00
public function testCountQuery_MixedResultsWithName ()
{
2014-04-17 23:29:18 +04:00
$dql = 'SELECT a, sum(a.name) as foo FROM Doctrine\Tests\ORM\Tools\Pagination\Author a' ;
$query = $this -> entityManager -> createQuery ( $dql );
2012-01-22 16:35:06 +04:00
$limitQuery = clone $query ;
2014-04-17 23:29:18 +04:00
2012-01-22 16:35:06 +04:00
$limitQuery -> setHint ( Query :: HINT_CUSTOM_TREE_WALKERS , array ( 'Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker' ));
$this -> assertEquals (
2014-04-17 23:29:18 +04:00
" SELECT DISTINCT a0_.id AS id_0, sum(a0_.name) AS sclr_1 FROM Author a0_ " ,
$limitQuery -> getSql ()
);
}
/**
* @ group DDC - 2890
*/
public function testLimitSubqueryWithSortOnAssociation ()
{
$dql = 'SELECT p FROM Doctrine\Tests\ORM\Tools\Pagination\MyBlogPost p ORDER BY p.author' ;
$query = $this -> entityManager -> createQuery ( $dql );
$limitQuery = clone $query ;
$limitQuery -> setHint ( Query :: HINT_CUSTOM_TREE_WALKERS , array ( 'Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker' ));
$this -> assertEquals (
" SELECT DISTINCT m0_.id AS id_0, m0_.author_id AS sclr_1 FROM MyBlogPost m0_ ORDER BY m0_.author_id ASC " ,
$limitQuery -> getSql ()
2012-01-22 16:35:06 +04:00
);
}
2014-07-31 10:31:39 +04:00
/**
* Arbitrary Join
*/
public function testLimitSubqueryWithArbitraryJoin ()
{
2014-07-31 10:43:02 +04:00
$dql = 'SELECT p, c FROM Doctrine\Tests\ORM\Tools\Pagination\MyBlogPost p JOIN Doctrine\Tests\ORM\Tools\Pagination\Category c WITH p.category = c' ;
2014-07-31 10:31:39 +04:00
$query = $this -> entityManager -> createQuery ( $dql );
$limitQuery = clone $query ;
$limitQuery -> setHint ( Query :: HINT_CUSTOM_TREE_WALKERS , array ( 'Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker' ));
$this -> assertEquals (
2014-07-31 11:01:58 +04:00
" SELECT DISTINCT m0_.id AS id_0 FROM MyBlogPost m0_ INNER JOIN Category c1_ ON (m0_.category_id = c1_.id) " ,
2014-07-31 10:31:39 +04:00
$limitQuery -> getSql ()
);
}
public function testLimitSubqueryWithSortWithArbitraryJoin ()
{
2014-07-31 10:43:02 +04:00
$dql = 'SELECT p, c FROM Doctrine\Tests\ORM\Tools\Pagination\MyBlogPost p JOIN Doctrine\Tests\ORM\Tools\Pagination\Category c WITH p.category = c ORDER BY p.title' ;
2014-07-31 10:31:39 +04:00
$query = $this -> entityManager -> createQuery ( $dql );
$limitQuery = clone $query ;
$limitQuery -> setHint ( Query :: HINT_CUSTOM_TREE_WALKERS , array ( 'Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker' ));
$this -> assertEquals (
2014-07-31 11:01:58 +04:00
" SELECT DISTINCT m0_.id AS id_0, m0_.title AS title_1 FROM MyBlogPost m0_ INNER JOIN Category c1_ ON (m0_.category_id = c1_.id) ORDER BY m0_.title ASC " ,
2014-07-31 10:31:39 +04:00
$limitQuery -> getSql ()
);
}
2012-01-22 16:35:06 +04:00
}