Passed
Pull Request — 2.8.x (#7953)
by Grégoire
14:03
created

DDC7969Test::testChildEntityRetrievedFromCache()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 34
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 34
rs 9.7
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
        $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