Skip to content

Commit

Permalink
Fix insufficient variable check
Browse files Browse the repository at this point in the history
To ensure that `AbstractQuery#setResultCacheProfile()` doesn't raise
errors when being called with `null`.
  • Loading branch information
KonstantinKuklin authored and lcobucci committed Dec 17, 2017
1 parent 2260381 commit ff8fdbf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/AbstractQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
15 changes: 15 additions & 0 deletions tests/Doctrine/Tests/ORM/Query/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}

0 comments on commit ff8fdbf

Please sign in to comment.