Passed
Pull Request — 2.6 (#7750)
by
unknown
10:46
created

Issue7735Test::evictRegions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nop 0
dl 0
loc 5
rs 10
nc 1
1
<?php
2
3
namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5
use Doctrine\Tests\Models\Issue7735\Car;
6
use Doctrine\Tests\Models\Issue7735\Engine;
7
use Doctrine\Tests\Models\Issue7735\Power;
8
use Doctrine\Tests\OrmFunctionalTestCase;
9
10
class Issue7735Test extends OrmFunctionalTestCase
11
{
12
13
    protected const DEFAULT_CACHE_REGION_LIFE_TIME = 1;
14
15
    /**
16
     * @var \Doctrine\ORM\Cache
17
     */
18
    protected $cache;
19
20
    public function setUp()
21
    {
22
        $this->enableSecondLevelCache();
23
        $this->useModelSet('issue7735');
24
        parent::setUp();
25
        $this->cache = $this->_em->getCache();
26
27
28
        $engine = new Engine('turbo');
29
        $power = new Power(100, 110, $engine);
30
        $car = new Car('white', $engine);
31
32
        $this->_em->persist($car);
33
        $this->_em->persist($power);
34
        $this->_em->persist($engine);
35
36
        $this->_em->flush();
37
        $this->_em->clear();
38
        $this->evictRegions();
39
40
    }
41
42
    public function testFindByReturnsCachedEntity()
43
    {
44
        for ($i = 1000000; $i > 0; $i--) {
45
            $carRepository = $this->_em->getRepository(Car::class);
46
            $car = $carRepository->find(1);
47
            $engine = $car->getEngine();
48
            $power = $engine->getPower();
0 ignored issues
show
Unused Code introduced by
The assignment to $power is dead and can be removed.
Loading history...
49
            $model = $engine->getModel();
50
            $this->assertNotEmpty($model);
51
            $this->_em->clear();
52
        }
53
    }
54
55
    private function evictRegions()
56
    {
57
        $this->cache->evictQueryRegions();
58
        $this->cache->evictEntityRegions();
59
        $this->cache->evictCollectionRegions();
60
    }
61
}
62