Completed
Pull Request — 2.8.x (#8009)
by Peter
63:38
created

DDC7969Test::testChildEntityRetrievedFromCache()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 33
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 16
c 2
b 0
f 0
dl 0
loc 33
rs 9.7333
cc 2
nc 2
nop 0
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
35
        $repository->findOneBy([
36
            'name' => $bar->getName(),
37
        ]);
38
39
        $this->assertTrue($this->cache->containsEntity(Bar::class, $bar->getId()));
40
41
        $repository->findOneBy([
42
            'name' => $bar->getName(),
43
        ]);
44
45
        // One hit for entity cache, one hit for query cache
46
        $this->assertEquals(2, $this->secondLevelCacheLogger->getHitCount());
47
    }
48
}
49