Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8023 from peterkeatingie/query-cache-fix
Put into cache using root entity name
- Loading branch information
Showing
2 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC7969Test.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace tests\Doctrine\Tests\ORM\Functional\Ticket; | ||
|
||
use Doctrine\ORM\Cache\Region\DefaultMultiGetRegion; | ||
use Doctrine\Tests\Models\Cache\Attraction; | ||
use Doctrine\Tests\Models\Cache\Bar; | ||
use Doctrine\Tests\ORM\Functional\SecondLevelCacheAbstractTest; | ||
|
||
class DDC7969Test extends SecondLevelCacheAbstractTest | ||
{ | ||
public function testChildEntityRetrievedFromCache() : void | ||
{ | ||
$this->loadFixturesCountries(); | ||
$this->loadFixturesStates(); | ||
$this->loadFixturesCities(); | ||
$this->loadFixturesAttractions(); | ||
|
||
// Entities are already cached due to fixtures - hence flush before testing | ||
$region = $this->cache->getEntityCacheRegion(Attraction::class); | ||
|
||
if ($region instanceof DefaultMultiGetRegion) { | ||
$region->getCache()->flushAll(); | ||
} | ||
|
||
/** @var Bar $bar */ | ||
$bar = $this->attractions[0]; | ||
|
||
$repository = $this->_em->getRepository(Bar::class); | ||
|
||
$this->assertFalse($this->cache->containsEntity(Bar::class, $bar->getId())); | ||
$this->assertFalse($this->cache->containsEntity(Attraction::class, $bar->getId())); | ||
|
||
$repository->findOneBy([ | ||
'name' => $bar->getName(), | ||
]); | ||
|
||
$this->assertTrue($this->cache->containsEntity(Bar::class, $bar->getId())); | ||
|
||
$repository->findOneBy([ | ||
'name' => $bar->getName(), | ||
]); | ||
|
||
// One hit for entity cache, one hit for query cache | ||
$this->assertEquals(2, $this->secondLevelCacheLogger->getHitCount()); | ||
} | ||
} |