Skip to content

Commit

Permalink
Add test to verify that using ResultCache with Query::toIterable is f…
Browse files Browse the repository at this point in the history
…ailing.
  • Loading branch information
Warxcell committed Feb 21, 2021
1 parent ebae57e commit 7f6ed09
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
use ReflectionProperty;

use function count;
use function iterator_to_array;

/**
* ResultCacheTest
*/
class ResultCacheTest extends OrmFunctionalTestCase
{
/** @var ReflectionProperty */
/** @var ReflectionProperty */
private $cacheDataReflection;

protected function setUp(): void
Expand Down Expand Up @@ -168,6 +169,40 @@ public function testEnableResultCache(): void
$this->_em->getConfiguration()->setResultCacheImpl(new ArrayCache());
}

public function testEnableResultCacheWithIterable(): void
{
$cache = new ArrayCache();
$expectedSQLCount = count($this->_sqlLoggerStack->queries) + 1;

$query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux');
$query->enableResultCache();
$query->setResultCacheDriver($cache);
$query->setResultCacheId('testing_iterable_result_cache_id');
iterator_to_array($query->toIterable());

$this->_em->clear();

$this->assertCount(
$expectedSQLCount,
$this->_sqlLoggerStack->queries
);
$this->assertTrue($cache->contains('testing_iterable_result_cache_id'));

$query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux');
$query->enableResultCache();
$query->setResultCacheDriver($cache);
$query->setResultCacheId('testing_iterable_result_cache_id');
iterator_to_array($query->toIterable());

$this->assertCount(
$expectedSQLCount,
$this->_sqlLoggerStack->queries,
'Expected query to be cached'
);

$this->_em->getConfiguration()->setResultCacheImpl(new ArrayCache());
}

/**
* @group DDC-1026
*/
Expand Down

0 comments on commit 7f6ed09

Please sign in to comment.