From 7f6ed094cdad1496e19dd16c4cd539a7ef23b7ca Mon Sep 17 00:00:00 2001 From: Warxcell Date: Sun, 21 Feb 2021 21:12:52 +0200 Subject: [PATCH 1/2] Add test to verify that using ResultCache with Query::toIterable is failing. --- .../Tests/ORM/Functional/ResultCacheTest.php | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) 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 */ From 930859f803ae1582bbdd0614b0e26def5d663b54 Mon Sep 17 00:00:00 2001 From: Warxcell Date: Sun, 21 Feb 2021 21:13:50 +0200 Subject: [PATCH 2/2] Fix bug when using ResultCache with Query::toIterable. Signed-off-by: Warxcell --- lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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;