Skip to content

Commit

Permalink
Merge pull request #8495 from Warxcell/fix_to_iterable_with_cache
Browse files Browse the repository at this point in the history
Fix bug when using Result Cache with Query::toIterable
  • Loading branch information
greg0ire committed Feb 23, 2021
2 parents c2d69a3 + 930859f commit ae19f40
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php
Expand Up @@ -20,7 +20,7 @@

namespace Doctrine\ORM\Internal\Hydration;

use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Driver\ResultStatement;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
Expand Down Expand Up @@ -93,7 +93,7 @@ abstract class AbstractHydrator
/**
* The statement that provides the data to hydrate.
*
* @var Statement
* @var ResultStatement
*/
protected $_stmt;

Expand Down Expand Up @@ -154,7 +154,7 @@ public function iterate($stmt, $resultSetMapping, array $hints = [])
*
* @return iterable<mixed>
*/
public function toIterable(Statement $stmt, ResultSetMapping $resultSetMapping, array $hints = []): iterable
public function toIterable(ResultStatement $stmt, ResultSetMapping $resultSetMapping, array $hints = []): iterable
{
$this->_stmt = $stmt;
$this->_rsm = $resultSetMapping;
Expand Down
35 changes: 35 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php
Expand Up @@ -12,6 +12,7 @@
use ReflectionProperty;

use function count;
use function iterator_to_array;

/**
* ResultCacheTest
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 ae19f40

Please sign in to comment.