Fix insufficient variable check
To ensure that `AbstractQuery#setResultCacheProfile()` doesn't raise errors when being called with `null`.
This commit is contained in:
parent
739f518ebe
commit
c308986a90
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user