1
0
mirror of synced 2025-02-02 21:41:45 +03:00

Fix insufficient variable check

To ensure that `AbstractQuery#setResultCacheProfile()` doesn't raise
errors when being called with `null`.
This commit is contained in:
Konstantin Kuklin 2017-10-04 03:37:17 +03:00 committed by Luís Cobucci
parent 739f518ebe
commit c308986a90
No known key found for this signature in database
GPG Key ID: EC61C5F01750ED3C
2 changed files with 16 additions and 1 deletions

View File

@ -521,7 +521,7 @@ abstract class AbstractQuery
*/ */
public function setResultCacheProfile(QueryCacheProfile $profile = null) public function setResultCacheProfile(QueryCacheProfile $profile = null)
{ {
if ( ! $profile->getResultCacheDriver()) { if ($profile !== null && ! $profile->getResultCacheDriver()) {
$resultCacheDriver = $this->_em->getConfiguration()->getResultCacheImpl(); $resultCacheDriver = $this->_em->getConfiguration()->getResultCacheImpl();
$profile = $profile->setResultCacheDriver($resultCacheDriver); $profile = $profile->setResultCacheDriver($resultCacheDriver);
} }

View File

@ -5,6 +5,7 @@ namespace Doctrine\Tests\ORM\Query;
use Doctrine\Common\Cache\ArrayCache; use Doctrine\Common\Cache\ArrayCache;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\DBAL\Cache\QueryCacheProfile;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Internal\Hydration\IterableResult; use Doctrine\ORM\Internal\Hydration\IterableResult;
use Doctrine\ORM\Query\Parameter; use Doctrine\ORM\Query\Parameter;
@ -366,4 +367,18 @@ class QueryTest extends OrmTestCase
self::assertSame(3, $query->getParameter('0')->getValue()); self::assertSame(3, $query->getParameter('0')->getValue());
self::assertSame('Doctrine', $query->getParameter('name')->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);
}
} }