From c308986a906a31fb99da583bad5b0e342df8b5de Mon Sep 17 00:00:00 2001 From: Konstantin Kuklin Date: Wed, 4 Oct 2017 03:37:17 +0300 Subject: [PATCH] Fix insufficient variable check To ensure that `AbstractQuery#setResultCacheProfile()` doesn't raise errors when being called with `null`. --- lib/Doctrine/ORM/AbstractQuery.php | 2 +- tests/Doctrine/Tests/ORM/Query/QueryTest.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index 10af39053..3ba0dee26 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -521,7 +521,7 @@ abstract class AbstractQuery */ public function setResultCacheProfile(QueryCacheProfile $profile = null) { - if ( ! $profile->getResultCacheDriver()) { + if ($profile !== null && ! $profile->getResultCacheDriver()) { $resultCacheDriver = $this->_em->getConfiguration()->getResultCacheImpl(); $profile = $profile->setResultCacheDriver($resultCacheDriver); } diff --git a/tests/Doctrine/Tests/ORM/Query/QueryTest.php b/tests/Doctrine/Tests/ORM/Query/QueryTest.php index 354586f15..8cceb6c50 100644 --- a/tests/Doctrine/Tests/ORM/Query/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Query/QueryTest.php @@ -5,6 +5,7 @@ namespace Doctrine\Tests\ORM\Query; use Doctrine\Common\Cache\ArrayCache; use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\DBAL\Cache\QueryCacheProfile; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Internal\Hydration\IterableResult; use Doctrine\ORM\Query\Parameter; @@ -366,4 +367,18 @@ class QueryTest extends OrmTestCase self::assertSame(3, $query->getParameter('0')->getValue()); self::assertSame('Doctrine', $query->getParameter('name')->getValue()); } + + /** + * @group 6748 + */ + public function testResultCacheProfileCanBeRemovedViaSetter() : void + { + $this->_em->getConfiguration()->setResultCacheImpl(new ArrayCache()); + + $query = $this->_em->createQuery('SELECT u FROM ' . CmsUser::class . ' u'); + $query->useResultCache(true); + $query->setResultCacheProfile(); + + self::assertAttributeSame(null, '_queryCacheProfile', $query); + } }