1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace tests\Doctrine\Tests\ORM\Functional\Ticket; |
6
|
|
|
|
7
|
|
|
use Doctrine\ORM\Cache\Region\DefaultMultiGetRegion; |
8
|
|
|
use Doctrine\Tests\Models\Cache\Attraction; |
9
|
|
|
use Doctrine\Tests\Models\Cache\Bar; |
10
|
|
|
use Doctrine\Tests\ORM\Functional\SecondLevelCacheAbstractTest; |
11
|
|
|
|
12
|
|
|
class DDC7969Test extends SecondLevelCacheAbstractTest |
13
|
|
|
{ |
14
|
|
|
public function testChildEntityRetrievedFromCache() : void |
15
|
|
|
{ |
16
|
|
|
$this->loadFixturesCountries(); |
17
|
|
|
$this->loadFixturesStates(); |
18
|
|
|
$this->loadFixturesCities(); |
19
|
|
|
$this->loadFixturesAttractions(); |
20
|
|
|
|
21
|
|
|
// Entities are already cached due to fixtures - hence flush before testing |
22
|
|
|
$region = $this->cache->getEntityCacheRegion(Attraction::class); |
23
|
|
|
|
24
|
|
|
if ($region instanceof DefaultMultiGetRegion) { |
25
|
|
|
$region->getCache()->flushAll(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** @var Bar $bar */ |
29
|
|
|
$bar = $this->attractions[0]; |
30
|
|
|
|
31
|
|
|
$repository = $this->_em->getRepository(Bar::class); |
32
|
|
|
|
33
|
|
|
$this->assertFalse($this->cache->containsEntity(Bar::class, $bar->getId())); |
34
|
|
|
$this->assertFalse($this->cache->containsEntity(Attraction::class, $bar->getId())); |
35
|
|
|
|
36
|
|
|
$repository->findOneBy([ |
37
|
|
|
'name' => $bar->getName(), |
38
|
|
|
]); |
39
|
|
|
|
40
|
|
|
$this->assertTrue($this->cache->containsEntity(Bar::class, $bar->getId())); |
41
|
|
|
|
42
|
|
|
$repository->findOneBy([ |
43
|
|
|
'name' => $bar->getName(), |
44
|
|
|
]); |
45
|
|
|
|
46
|
|
|
// One hit for entity cache, one hit for query cache |
47
|
|
|
$this->assertEquals(2, $this->secondLevelCacheLogger->getHitCount()); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|