Add test for paginating on a query with a subquery in the where clause
Conflicts: tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php
This commit is contained in:
parent
a4aa18f796
commit
af3f5c5c5a
@ -3,6 +3,7 @@
|
||||
namespace Doctrine\Tests\ORM\Functional;
|
||||
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\Tests\Models\CMS\CmsArticle;
|
||||
use Doctrine\Tests\Models\CMS\CmsEmail;
|
||||
use Doctrine\Tests\Models\CMS\CmsUser;
|
||||
use Doctrine\Tests\Models\CMS\CmsGroup;
|
||||
@ -571,6 +572,31 @@ class PaginationTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
iterator_to_array($iter);
|
||||
}
|
||||
|
||||
public function testCountWithCountSubqueryInWhereClauseWithOutputWalker()
|
||||
{
|
||||
$dql = "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE ((SELECT COUNT(s.id) FROM Doctrine\Tests\Models\CMS\CmsUser s) = 9) ORDER BY u.id desc";
|
||||
$query = $this->_em->createQuery($dql);
|
||||
|
||||
$paginator = new Paginator($query, true);
|
||||
$paginator->setUseOutputWalkers(true);
|
||||
$this->assertCount(9, $paginator);
|
||||
}
|
||||
|
||||
public function testIterateWithCountSubqueryInWhereClause()
|
||||
{
|
||||
$dql = "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE ((SELECT COUNT(s.id) FROM Doctrine\Tests\Models\CMS\CmsUser s) = 9) ORDER BY u.id desc";
|
||||
$query = $this->_em->createQuery($dql);
|
||||
|
||||
$paginator = new Paginator($query, true);
|
||||
$paginator->setUseOutputWalkers(true);
|
||||
|
||||
$users = iterator_to_array($paginator->getIterator());
|
||||
$this->assertCount(9, $users);
|
||||
foreach ($users as $i => $user) {
|
||||
$this->assertEquals("username" . (8 - $i), $user->username);
|
||||
}
|
||||
}
|
||||
|
||||
public function testDetectOutputWalker()
|
||||
{
|
||||
// This query works using the output walkers but causes an exception using the TreeWalker
|
||||
@ -665,6 +691,14 @@ class PaginationTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$user->addGroup($groups[$j]);
|
||||
}
|
||||
$this->_em->persist($user);
|
||||
for ($j = 0; $j < $i + 1; $j++) {
|
||||
$article = new CmsArticle();
|
||||
$article->topic = "topic$i$j";
|
||||
$article->text = "text$i$j";
|
||||
$article->setAuthor($user);
|
||||
$article->version = 0;
|
||||
$this->_em->persist($article);
|
||||
}
|
||||
}
|
||||
|
||||
for ($i = 0; $i < 9; $i++) {
|
||||
|
@ -318,5 +318,37 @@ class LimitSubqueryOutputWalkerTest extends PaginationTestCase
|
||||
$query->getSQL()
|
||||
);
|
||||
}
|
||||
|
||||
public function testLimitSubqueryWithOrderByAndSubSelectInWhereClauseMySql()
|
||||
{
|
||||
$this->entityManager->getConnection()->setDatabasePlatform(new MySqlPlatform());
|
||||
$query = $this->entityManager->createQuery(
|
||||
'SELECT b FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost b
|
||||
WHERE ((SELECT COUNT(simple.id) FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost simple) = 1)
|
||||
ORDER BY b.id DESC'
|
||||
);
|
||||
$query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker');
|
||||
|
||||
$this->assertEquals(
|
||||
'SELECT DISTINCT id_0 FROM (SELECT b0_.id AS id_0, b0_.author_id AS author_id_1, b0_.category_id AS category_id_2 FROM BlogPost b0_ WHERE ((SELECT COUNT(b1_.id) AS dctrn__1 FROM BlogPost b1_) = 1)) dctrn_result ORDER BY id_0 DESC',
|
||||
$query->getSQL()
|
||||
);
|
||||
}
|
||||
|
||||
public function testLimitSubqueryWithOrderByAndSubSelectInWhereClausePgSql()
|
||||
{
|
||||
$this->entityManager->getConnection()->setDatabasePlatform(new PostgreSqlPlatform());
|
||||
$query = $this->entityManager->createQuery(
|
||||
'SELECT b FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost b
|
||||
WHERE ((SELECT COUNT(simple.id) FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost simple) = 1)
|
||||
ORDER BY b.id DESC'
|
||||
);
|
||||
$query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker');
|
||||
|
||||
$this->assertEquals(
|
||||
'SELECT DISTINCT id_0, MIN(sclr_1) AS dctrn_minrownum FROM (SELECT b0_.id AS id_0, ROW_NUMBER() OVER(ORDER BY b0_.id DESC) AS sclr_1, b0_.author_id AS author_id_2, b0_.category_id AS category_id_3 FROM BlogPost b0_ WHERE ((SELECT COUNT(b1_.id) AS dctrn__1 FROM BlogPost b1_) = 1)) dctrn_result GROUP BY id_0 ORDER BY dctrn_minrownum ASC',
|
||||
$query->getSQL()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user