1
|
|
|
<?php |
2
|
|
|
namespace Doctrine\Tests\Functional\Ticket; |
3
|
|
|
|
4
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* @group #6217 |
8
|
|
|
*/ |
9
|
|
|
final class GH6217Test extends OrmFunctionalTestCase |
10
|
|
|
{ |
11
|
|
View Code Duplication |
public function setUp() : void |
12
|
|
|
{ |
13
|
|
|
$this->enableSecondLevelCache(); |
14
|
|
|
|
15
|
|
|
parent::setUp(); |
16
|
|
|
|
17
|
|
|
$this->_schemaTool->createSchema([ |
18
|
|
|
$this->_em->getClassMetadata(GH6217AssociatedEntity::class), |
19
|
|
|
$this->_em->getClassMetadata(GH6217FetchedEntity::class), |
20
|
|
|
]); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function testLoadingOfSecondLevelCacheOnEagerAssociations() : void |
24
|
|
|
{ |
25
|
|
|
$lazy = new GH6217AssociatedEntity(); |
26
|
|
|
$eager = new GH6217AssociatedEntity(); |
27
|
|
|
$fetched = new GH6217FetchedEntity($lazy, $eager); |
28
|
|
|
|
29
|
|
|
$this->_em->persist($eager); |
30
|
|
|
$this->_em->persist($lazy); |
31
|
|
|
$this->_em->persist($fetched); |
32
|
|
|
$this->_em->flush(); |
33
|
|
|
$this->_em->clear(); |
34
|
|
|
|
35
|
|
|
$repository = $this->_em->getRepository(GH6217FetchedEntity::class); |
36
|
|
|
$filters = ['eager' => $eager->id]; |
37
|
|
|
|
38
|
|
|
self::assertCount(1, $repository->findBy($filters)); |
39
|
|
|
$queryCount = $this->getCurrentQueryCount(); |
40
|
|
|
|
41
|
|
|
/* @var $found GH6217FetchedEntity[] */ |
42
|
|
|
$found = $repository->findBy($filters); |
43
|
|
|
|
44
|
|
|
self::assertCount(1, $found); |
45
|
|
|
self::assertInstanceOf(GH6217FetchedEntity::class, $found[0]); |
46
|
|
|
self::assertSame($lazy->id, $found[0]->lazy->id); |
47
|
|
|
self::assertSame($eager->id, $found[0]->eager->id); |
48
|
|
|
self::assertEquals($queryCount, $this->getCurrentQueryCount(), 'No queries were executed in `findBy`'); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** @Entity @Cache(usage="NONSTRICT_READ_WRITE") */ |
53
|
|
|
class GH6217AssociatedEntity |
54
|
|
|
{ |
55
|
|
|
/** @Id @Column(type="string") @GeneratedValue(strategy="NONE") */ |
56
|
|
|
public $id; |
57
|
|
|
|
58
|
|
|
public function __construct() |
59
|
|
|
{ |
60
|
|
|
$this->id = uniqid(self::class, true); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** @Entity @Cache(usage="NONSTRICT_READ_WRITE") */ |
65
|
|
|
class GH6217FetchedEntity |
66
|
|
|
{ |
67
|
|
|
/** @Id @Cache("NONSTRICT_READ_WRITE") @ManyToOne(targetEntity=GH6217AssociatedEntity::class) */ |
68
|
|
|
public $lazy; |
69
|
|
|
|
70
|
|
|
/** @Id @Cache("NONSTRICT_READ_WRITE") @ManyToOne(targetEntity=GH6217AssociatedEntity::class, fetch="EAGER") */ |
71
|
|
|
public $eager; |
72
|
|
|
|
73
|
|
|
public function __construct(GH6217AssociatedEntity $lazy, GH6217AssociatedEntity $eager) |
74
|
|
|
{ |
75
|
|
|
$this->lazy = $lazy; |
76
|
|
|
$this->eager = $eager; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|