Failed Conditions
Pull Request — 2.8.x (#8009)
by
unknown
65:18
created

DDC7969Test   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 15
c 1
b 0
f 0
dl 0
loc 31
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A testChildEntityRetrievedFromCache() 0 29 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace tests\Doctrine\Tests\ORM\Functional\Ticket;
6
7
use Doctrine\Tests\Models\Cache\Attraction;
8
use Doctrine\Tests\Models\Cache\Bar;
9
use Doctrine\Tests\ORM\Functional\SecondLevelCacheAbstractTest;
10
11
class DDC7969Test extends SecondLevelCacheAbstractTest
12
{
13
    public function testChildEntityRetrievedFromCache()
14
    {
15
        $this->loadFixturesCountries();
16
        $this->loadFixturesStates();
17
        $this->loadFixturesCities();
18
        $this->loadFixturesAttractions();
19
20
        // Entities are already cached due to fixtures - hence flush before testing
21
        $this->cache->getEntityCacheRegion(Attraction::class)->getCache()->flushAll();
0 ignored issues
show
Bug introduced by
The method getCache() does not exist on Doctrine\ORM\Cache\Region. It seems like you code against a sub-type of Doctrine\ORM\Cache\Region such as Doctrine\ORM\Cache\Region\DefaultRegion or Doctrine\ORM\Cache\Region\UpdateTimestampCache. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

21
        $this->cache->getEntityCacheRegion(Attraction::class)->/** @scrutinizer ignore-call */ getCache()->flushAll();
Loading history...
22
23
        /** @var Bar $bar */
24
        $bar = $this->attractions[0];
25
26
        $repository = $this->_em->getRepository(Bar::class);
27
28
        $this->assertFalse($this->cache->containsEntity(Bar::class, $bar->getId()));
29
30
        $repository->findOneBy([
31
            'name' => $bar->getName(),
32
        ]);
33
34
        $this->assertTrue($this->cache->containsEntity(Bar::class, $bar->getId()));
35
36
        $repository->findOneBy([
37
            'name' => $bar->getName(),
38
        ]);
39
40
        // One hit for entity cache, one hit for query cache
41
        $this->assertEquals(2, $this->secondLevelCacheLogger->getHitCount());
42
    }
43
}
44