forked from doctrine/orm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DDC7969Test.php
48 lines (35 loc) · 1.42 KB
/
DDC7969Test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?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()));
$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());
}
}