Skip to content

Commit

Permalink
Add a test covering the #11112 issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mpdude committed Jan 27, 2024
1 parent 8503469 commit 300fec5
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/GH11112Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\Tests\Models\CMS\CmsUser;
use Doctrine\Tests\OrmFunctionalTestCase;
use Symfony\Component\Cache\Adapter\ArrayAdapter;

class GH11112Test extends OrmFunctionalTestCase
{
protected function setUp(): void
{
$this->useModelSet('cms');
self::$queryCache = new ArrayAdapter();

parent::setUp();
}

public function testSimpleQueryHasLimitAndOffsetApplied(): void
{
$platform = $this->_em->getConnection()->getDatabasePlatform();

Check failure on line 23 in tests/Doctrine/Tests/ORM/Functional/Ticket/GH11112Test.php

View workflow job for this annotation

GitHub Actions / coding-standards / Coding Standards (8.2)

Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space
$query = $this->_em->createQuery('SELECT u FROM ' . CmsUser::class . ' u');

Check failure on line 24 in tests/Doctrine/Tests/ORM/Functional/Ticket/GH11112Test.php

View workflow job for this annotation

GitHub Actions / coding-standards / Coding Standards (8.2)

Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space
$originalSql = $query->getSQL();

$query->setMaxResults(10);
$query->setFirstResult(20);
$sql10_20 = $query->getSQL();

Check failure on line 29 in tests/Doctrine/Tests/ORM/Functional/Ticket/GH11112Test.php

View workflow job for this annotation

GitHub Actions / coding-standards / Coding Standards (8.2)

Variable "sql10_20" is not in valid camel caps format

$query->setMaxResults(30);
$query->setFirstResult(40);
$sql30_40 = $query->getSQL();

Check failure on line 33 in tests/Doctrine/Tests/ORM/Functional/Ticket/GH11112Test.php

View workflow job for this annotation

GitHub Actions / coding-standards / Coding Standards (8.2)

Variable "sql30_40" is not in valid camel caps format

// The SQL is platform specific and may even be something with outer SELECTS being added. So,
// derive the expected value at runtime through the platform.
self::assertSame($platform->modifyLimitQuery($originalSql, 10, 20), $sql10_20);

Check failure on line 37 in tests/Doctrine/Tests/ORM/Functional/Ticket/GH11112Test.php

View workflow job for this annotation

GitHub Actions / coding-standards / Coding Standards (8.2)

Variable "sql10_20" is not in valid camel caps format
self::assertSame($platform->modifyLimitQuery($originalSql, 30, 40), $sql30_40);

Check failure on line 38 in tests/Doctrine/Tests/ORM/Functional/Ticket/GH11112Test.php

View workflow job for this annotation

GitHub Actions / coding-standards / Coding Standards (8.2)

Variable "sql30_40" is not in valid camel caps format

$cacheEntries = self::$queryCache->getValues();
self::assertCount(1, $cacheEntries);
}

public function testSubqueryLimitAndOffsetAreIgnored(): void
{
// Not sure what to do about this test. Basically, I want to make sure that
// firstResult/maxResult for subqueries are not relevant, they do not make it
// into the final query at all. That would give us the guarantee that the
// "sql finalizer" step is sufficient for the final, "outer" query and we
// do not need to run finalizers for the subqueries.

// This DQL/query makes no sense, it's just about creating a subquery in the first place
$queryBuilder = $this->_em->createQueryBuilder();
$queryBuilder
->select('o')
->from(CmsUser::class, 'o')
->where($queryBuilder->expr()->exists(
$this->_em->createQueryBuilder()
->select('u')
->from(CmsUser::class, 'u')
->setFirstResult(10)
->setMaxResults(20)
));

$query = $queryBuilder->getQuery();

Check failure on line 65 in tests/Doctrine/Tests/ORM/Functional/Ticket/GH11112Test.php

View workflow job for this annotation

GitHub Actions / coding-standards / Coding Standards (8.2)

Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space
$originalSql = $query->getSQL();

$clone = clone $query;
$clone->setFirstResult(24);
$clone->setMaxResults(42);
$limitedSql = $clone->getSQL();

$platform = $this->_em->getConnection()->getDatabasePlatform();

// The SQL is platform specific and may even be something with outer SELECTS being added. So,
// derive the expected value at runtime through the platform.
self::assertSame($platform->modifyLimitQuery($originalSql, 42, 24), $limitedSql);
}
}

0 comments on commit 300fec5

Please sign in to comment.