diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index 12adf2d07d8..7ca5f51ca19 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -525,7 +525,7 @@ public function getHydrationCacheProfile() */ 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 2703ccf034b..d18a263c596 100644 --- a/tests/Doctrine/Tests/ORM/Query/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Query/QueryTest.php @@ -5,6 +5,7 @@ use Doctrine\Common\Cache\ArrayCache; use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\DBAL\Cache\QueryCacheProfile; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Query\Parameter; @@ -259,4 +260,18 @@ public function testSetParameterWithTypeJugglingWorks() self::assertSame(3, $query->getParameter('0')->getValue()); self::assertSame('Doctrine', $query->getParameter('name')->getValue()); } + + /** + * @group 6748 + */ + public function testResultCacheProfileCanBeRemovedViaSetter() + { + $this->_em->getConfiguration()->setResultCacheImpl(new ArrayCache()); + + $query = $this->_em->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u'); + $query->useResultCache(true); + $query->setResultCacheProfile(); + + self::assertAttributeSame(null, '_queryCacheProfile', $query); + } }