1
|
|
|
<?php |
2
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket\Issue7735; |
3
|
|
|
|
4
|
|
|
use Doctrine\Common\Cache\ArrayCache; |
5
|
|
|
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver; |
6
|
|
|
use Doctrine\DBAL\Driver\Connection; |
7
|
|
|
use Doctrine\DBAL\Logging\DebugStack; |
8
|
|
|
use Doctrine\ORM\Cache\CacheConfiguration; |
9
|
|
|
use Doctrine\ORM\Cache\DefaultCacheFactory; |
10
|
|
|
use Doctrine\ORM\Cache\Logging\StatisticsCacheLogger; |
11
|
|
|
use Doctrine\ORM\Configuration; |
12
|
|
|
use Doctrine\ORM\EntityManager; |
13
|
|
|
use Doctrine\ORM\Tools\DebugUnitOfWorkListener; |
14
|
|
|
use Doctrine\Tests\EventListener\CacheMetadataListener; |
15
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class Issue7735Test |
19
|
|
|
* @package Doctrine\Tests\ORM\Functional\Ticket\Issue7735 |
20
|
|
|
*/ |
21
|
|
|
class Issue7735Test extends OrmFunctionalTestCase |
22
|
|
|
{ |
23
|
|
|
protected const DEFAULT_CACHE_REGION_LIFE_TIME = 1; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var \Doctrine\ORM\Cache |
27
|
|
|
*/ |
28
|
|
|
protected $cache; |
29
|
|
|
|
30
|
|
|
public function setUp() |
31
|
|
|
{ |
32
|
|
|
$this->enableSecondLevelCache(); |
33
|
|
|
$this->useModelSet('issue7735'); |
34
|
|
|
parent::setUp(); |
35
|
|
|
$this->cache = $this->_em->getCache(); |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
$engine = new Engine('turbo'); |
39
|
|
|
$power = new Power($engine); |
40
|
|
|
$car = new Car($engine); |
41
|
|
|
|
42
|
|
|
$this->_em->persist($car); |
43
|
|
|
$this->_em->persist($power); |
44
|
|
|
$this->_em->persist($engine); |
45
|
|
|
|
46
|
|
|
$this->_em->flush(); |
47
|
|
|
$this->_em->clear(); |
48
|
|
|
$this->evictRegions(); |
49
|
|
|
|
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testFindByReturnsCachedEntity() |
53
|
|
|
{ |
54
|
|
|
for ($i = 1000000; $i > 0; $i--) { |
55
|
|
|
$carRepository = $this->_em->getRepository(Car::class); |
56
|
|
|
$car = $carRepository->find(1); |
57
|
|
|
$engine = $car->getEngine(); |
58
|
|
|
$power = $engine->getPower(); |
|
|
|
|
59
|
|
|
$model = $engine->getModel(); |
60
|
|
|
$this->assertNotEmpty($model); |
61
|
|
|
$this->_em->clear(); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
private function evictRegions() |
66
|
|
|
{ |
67
|
|
|
$this->cache->evictQueryRegions(); |
68
|
|
|
$this->cache->evictEntityRegions(); |
69
|
|
|
$this->cache->evictCollectionRegions(); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|