From 42bea80a6a1e21c839fe1fa8ed7b6191408f3ab2 Mon Sep 17 00:00:00 2001 From: Bill Schaller Date: Tue, 16 Dec 2014 11:59:13 -0500 Subject: [PATCH] Added failing test cases for limit queries with with complex scalar order by items --- .../LimitSubqueryOutputWalkerTest.php | 31 +++++++++++++++++++ .../Tools/Pagination/PaginationTestCase.php | 18 +++++++++++ 2 files changed, 49 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php b/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php index 027ae11e2..3015a7044 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php @@ -5,6 +5,7 @@ namespace Doctrine\Tests\ORM\Tools\Pagination; use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Platforms\PostgreSqlPlatform; +use Doctrine\DBAL\Platforms\SQLServerPlatform; use Doctrine\ORM\Query; class LimitSubqueryOutputWalkerTest extends PaginationTestCase @@ -212,6 +213,36 @@ class LimitSubqueryOutputWalkerTest extends PaginationTestCase ); } + public function testCountQueryWithComplexScalarOrderByItem() + { + $query = $this->entityManager->createQuery( + 'SELECT a FROM Doctrine\Tests\ORM\Tools\Pagination\Avatar a ORDER BY a.image_height * a.image_width DESC' + ); + $this->entityManager->getConnection()->setDatabasePlatform(new MySqlPlatform()); + + $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker'); + + $this->assertSame( + 'SELECT DISTINCT id_0, image_height_2, image_width_3 FROM (SELECT a0_.id AS id_0, a0_.image AS image_1, a0_.image_height AS image_height_2, a0_.image_width AS image_width_3, a0_.user_id AS user_id_4 FROM Avatar a0_) dctrn_result ORDER BY image_height_2 * image_width_3 DESC', + $query->getSQL() + ); + } + + public function testCountQueryWithComplexScalarOrderByItemOracle() + { + $query = $this->entityManager->createQuery( + 'SELECT a FROM Doctrine\Tests\ORM\Tools\Pagination\Avatar a ORDER BY a.image_height * a.image_width DESC' + ); + $this->entityManager->getConnection()->setDatabasePlatform(new OraclePlatform()); + + $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker'); + + $this->assertSame( + 'SELECT DISTINCT ID_0, IMAGE_HEIGHT_2, IMAGE_WIDTH_3 FROM (SELECT a0_.id AS ID_0, a0_.image AS IMAGE_1, a0_.image_height AS IMAGE_HEIGHT_2, a0_.image_width AS IMAGE_WIDTH_3, a0_.user_id AS USER_ID_4 FROM Avatar a0_) dctrn_result ORDER BY IMAGE_HEIGHT_2 * IMAGE_WIDTH_3 DESC', + $query->getSQL() + ); + } + /** * @group DDC-3434 */ diff --git a/tests/Doctrine/Tests/ORM/Tools/Pagination/PaginationTestCase.php b/tests/Doctrine/Tests/ORM/Tools/Pagination/PaginationTestCase.php index d3e77f6f0..ffc4c4669 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Pagination/PaginationTestCase.php +++ b/tests/Doctrine/Tests/ORM/Tools/Pagination/PaginationTestCase.php @@ -145,3 +145,21 @@ class User */ public $groups; } + +/** @Entity */ +class Avatar +{ + /** @Id @column(type="integer") @generatedValue */ + public $id; + /** + * @OneToOne(targetEntity="User", inversedBy="avatar") + * @JoinColumn(name="user_id", referencedColumnName="id") + */ + public $user; + /** @column(type="string", length=255) */ + public $image; + /** @column(type="integer") */ + public $image_height; + /** @column(type="integer") */ + public $image_width; +} \ No newline at end of file