|
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(); |
|
|
|
|
|
|
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
|
|
|
|