diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index e1f27dcb050..51d88124b3c 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -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; @@ -93,7 +93,7 @@ abstract class AbstractHydrator /** * The statement that provides the data to hydrate. * - * @var Statement + * @var ResultStatement */ protected $_stmt; @@ -154,7 +154,7 @@ public function iterate($stmt, $resultSetMapping, array $hints = []) * * @return iterable */ - 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; diff --git a/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php b/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php index 52e57c48154..d1d72da5684 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php @@ -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 @@ -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 */