1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\ORM\Functional; |
4
|
|
|
|
5
|
|
|
use Doctrine\Tests\Models\Cache\Attraction; |
6
|
|
|
use Doctrine\Tests\Models\Cache\AttractionContactInfo; |
7
|
|
|
use Doctrine\Tests\Models\Cache\AttractionInfo; |
8
|
|
|
use Doctrine\Tests\Models\Cache\AttractionLocationInfo; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @group DDC-2183 |
12
|
|
|
*/ |
13
|
|
|
class SecondLevelCacheJoinTableInheritanceTest extends SecondLevelCacheAbstractTest |
14
|
|
|
{ |
15
|
|
|
public function testUseSameRegion() |
16
|
|
|
{ |
17
|
|
|
$infoRegion = $this->cache->getEntityCacheRegion(AttractionInfo::CLASSNAME); |
18
|
|
|
$contactRegion = $this->cache->getEntityCacheRegion(AttractionContactInfo::CLASSNAME); |
19
|
|
|
$locationRegion = $this->cache->getEntityCacheRegion(AttractionLocationInfo::CLASSNAME); |
20
|
|
|
|
21
|
|
|
$this->assertEquals($infoRegion->getName(), $contactRegion->getName()); |
22
|
|
|
$this->assertEquals($infoRegion->getName(), $locationRegion->getName()); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testPutOnPersistJoinTableInheritance() |
26
|
|
|
{ |
27
|
|
|
$this->loadFixturesCountries(); |
28
|
|
|
$this->loadFixturesStates(); |
29
|
|
|
$this->loadFixturesCities(); |
30
|
|
|
$this->loadFixturesAttractions(); |
31
|
|
|
$this->loadFixturesAttractionsInfo(); |
32
|
|
|
|
33
|
|
|
$this->_em->clear(); |
34
|
|
|
|
35
|
|
|
$this->assertTrue($this->cache->containsEntity(AttractionInfo::CLASSNAME, $this->attractionsInfo[0]->getId())); |
36
|
|
|
$this->assertTrue($this->cache->containsEntity(AttractionInfo::CLASSNAME, $this->attractionsInfo[1]->getId())); |
37
|
|
|
$this->assertTrue($this->cache->containsEntity(AttractionInfo::CLASSNAME, $this->attractionsInfo[2]->getId())); |
38
|
|
|
$this->assertTrue($this->cache->containsEntity(AttractionInfo::CLASSNAME, $this->attractionsInfo[3]->getId())); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testJoinTableCountaisRootClass() |
42
|
|
|
{ |
43
|
|
|
$this->loadFixturesCountries(); |
44
|
|
|
$this->loadFixturesStates(); |
45
|
|
|
$this->loadFixturesCities(); |
46
|
|
|
$this->loadFixturesAttractions(); |
47
|
|
|
$this->loadFixturesAttractionsInfo(); |
48
|
|
|
|
49
|
|
|
$this->_em->clear(); |
50
|
|
|
|
51
|
|
|
foreach ($this->attractionsInfo as $info) { |
52
|
|
|
$this->assertTrue($this->cache->containsEntity(AttractionInfo::CLASSNAME, $info->getId())); |
53
|
|
|
$this->assertTrue($this->cache->containsEntity(get_class($info), $info->getId())); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testPutAndLoadJoinTableEntities() |
58
|
|
|
{ |
59
|
|
|
$this->loadFixturesCountries(); |
60
|
|
|
$this->loadFixturesStates(); |
61
|
|
|
$this->loadFixturesCities(); |
62
|
|
|
$this->loadFixturesAttractions(); |
63
|
|
|
$this->loadFixturesAttractionsInfo(); |
64
|
|
|
|
65
|
|
|
$this->_em->clear(); |
66
|
|
|
|
67
|
|
|
$this->cache->evictEntityRegion(AttractionInfo::CLASSNAME); |
68
|
|
|
|
69
|
|
|
$entityId1 = $this->attractionsInfo[0]->getId(); |
70
|
|
|
$entityId2 = $this->attractionsInfo[1]->getId(); |
71
|
|
|
|
72
|
|
|
$this->assertFalse($this->cache->containsEntity(AttractionInfo::CLASSNAME, $entityId1)); |
73
|
|
|
$this->assertFalse($this->cache->containsEntity(AttractionInfo::CLASSNAME, $entityId2)); |
74
|
|
|
$this->assertFalse($this->cache->containsEntity(AttractionContactInfo::CLASSNAME, $entityId1)); |
75
|
|
|
$this->assertFalse($this->cache->containsEntity(AttractionContactInfo::CLASSNAME, $entityId2)); |
76
|
|
|
|
77
|
|
|
$queryCount = $this->getCurrentQueryCount(); |
78
|
|
|
$entity1 = $this->_em->find(AttractionInfo::CLASSNAME, $entityId1); |
79
|
|
|
$entity2 = $this->_em->find(AttractionInfo::CLASSNAME, $entityId2); |
80
|
|
|
|
81
|
|
|
//load entity and relation whit sub classes |
82
|
|
|
$this->assertEquals($queryCount + 4, $this->getCurrentQueryCount()); |
83
|
|
|
|
84
|
|
|
$this->assertTrue($this->cache->containsEntity(AttractionInfo::CLASSNAME, $entityId1)); |
85
|
|
|
$this->assertTrue($this->cache->containsEntity(AttractionInfo::CLASSNAME, $entityId2)); |
86
|
|
|
$this->assertTrue($this->cache->containsEntity(AttractionContactInfo::CLASSNAME, $entityId1)); |
87
|
|
|
$this->assertTrue($this->cache->containsEntity(AttractionContactInfo::CLASSNAME, $entityId2)); |
88
|
|
|
|
89
|
|
|
$this->assertInstanceOf(AttractionInfo::CLASSNAME, $entity1); |
90
|
|
|
$this->assertInstanceOf(AttractionInfo::CLASSNAME, $entity2); |
91
|
|
|
$this->assertInstanceOf(AttractionContactInfo::CLASSNAME, $entity1); |
92
|
|
|
$this->assertInstanceOf(AttractionContactInfo::CLASSNAME, $entity2); |
93
|
|
|
|
94
|
|
|
$this->assertEquals($this->attractionsInfo[0]->getId(), $entity1->getId()); |
95
|
|
|
$this->assertEquals($this->attractionsInfo[0]->getFone(), $entity1->getFone()); |
96
|
|
|
|
97
|
|
|
$this->assertEquals($this->attractionsInfo[1]->getId(), $entity2->getId()); |
98
|
|
|
$this->assertEquals($this->attractionsInfo[1]->getFone(), $entity2->getFone()); |
99
|
|
|
|
100
|
|
|
$this->_em->clear(); |
101
|
|
|
|
102
|
|
|
$queryCount = $this->getCurrentQueryCount(); |
103
|
|
|
$entity3 = $this->_em->find(AttractionInfo::CLASSNAME, $entityId1); |
104
|
|
|
$entity4 = $this->_em->find(AttractionInfo::CLASSNAME, $entityId2); |
105
|
|
|
|
106
|
|
|
$this->assertEquals($queryCount, $this->getCurrentQueryCount()); |
107
|
|
|
|
108
|
|
|
$this->assertInstanceOf(AttractionInfo::CLASSNAME, $entity3); |
109
|
|
|
$this->assertInstanceOf(AttractionInfo::CLASSNAME, $entity4); |
110
|
|
|
$this->assertInstanceOf(AttractionContactInfo::CLASSNAME, $entity3); |
111
|
|
|
$this->assertInstanceOf(AttractionContactInfo::CLASSNAME, $entity4); |
112
|
|
|
|
113
|
|
|
$this->assertNotSame($entity1, $entity3); |
114
|
|
|
$this->assertEquals($entity1->getId(), $entity3->getId()); |
115
|
|
|
$this->assertEquals($entity1->getFone(), $entity3->getFone()); |
116
|
|
|
|
117
|
|
|
$this->assertNotSame($entity2, $entity4); |
118
|
|
|
$this->assertEquals($entity2->getId(), $entity4->getId()); |
119
|
|
|
$this->assertEquals($entity2->getFone(), $entity4->getFone()); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function testQueryCacheFindAllJoinTableEntities() |
123
|
|
|
{ |
124
|
|
|
$this->loadFixturesCountries(); |
125
|
|
|
$this->loadFixturesStates(); |
126
|
|
|
$this->loadFixturesCities(); |
127
|
|
|
$this->loadFixturesAttractions(); |
128
|
|
|
$this->loadFixturesAttractionsInfo(); |
129
|
|
|
$this->evictRegions(); |
130
|
|
|
$this->_em->clear(); |
131
|
|
|
|
132
|
|
|
$queryCount = $this->getCurrentQueryCount(); |
133
|
|
|
$dql = 'SELECT i, a FROM Doctrine\Tests\Models\Cache\AttractionInfo i JOIN i.attraction a'; |
134
|
|
|
$result1 = $this->_em->createQuery($dql) |
135
|
|
|
->setCacheable(true) |
136
|
|
|
->getResult(); |
137
|
|
|
|
138
|
|
|
$this->assertCount(count($this->attractionsInfo), $result1); |
139
|
|
|
$this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); |
140
|
|
|
|
141
|
|
|
$this->_em->clear(); |
142
|
|
|
|
143
|
|
|
$result2 = $this->_em->createQuery($dql) |
144
|
|
|
->setCacheable(true) |
145
|
|
|
->getResult(); |
146
|
|
|
|
147
|
|
|
$this->assertCount(count($this->attractionsInfo), $result2); |
148
|
|
|
$this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); |
149
|
|
|
|
150
|
|
|
foreach ($result2 as $entity) { |
151
|
|
|
$this->assertInstanceOf(AttractionInfo::CLASSNAME, $entity); |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
public function testOneToManyRelationJoinTable() |
156
|
|
|
{ |
157
|
|
|
$this->loadFixturesCountries(); |
158
|
|
|
$this->loadFixturesStates(); |
159
|
|
|
$this->loadFixturesCities(); |
160
|
|
|
$this->loadFixturesAttractions(); |
161
|
|
|
$this->loadFixturesAttractionsInfo(); |
162
|
|
|
$this->evictRegions(); |
163
|
|
|
$this->_em->clear(); |
164
|
|
|
|
165
|
|
|
$entity = $this->_em->find(Attraction::CLASSNAME, $this->attractions[0]->getId()); |
166
|
|
|
|
167
|
|
|
$this->assertInstanceOf(Attraction::CLASSNAME, $entity); |
168
|
|
|
$this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $entity->getInfos()); |
169
|
|
|
$this->assertCount(1, $entity->getInfos()); |
170
|
|
|
|
171
|
|
|
$ownerId = $this->attractions[0]->getId(); |
172
|
|
|
$queryCount = $this->getCurrentQueryCount(); |
173
|
|
|
|
174
|
|
|
$this->assertTrue($this->cache->containsEntity(Attraction::CLASSNAME, $ownerId)); |
175
|
|
|
$this->assertTrue($this->cache->containsCollection(Attraction::CLASSNAME, 'infos', $ownerId)); |
176
|
|
|
|
177
|
|
|
$this->assertInstanceOf(AttractionContactInfo::CLASSNAME, $entity->getInfos()->get(0)); |
178
|
|
|
$this->assertEquals($this->attractionsInfo[0]->getFone(), $entity->getInfos()->get(0)->getFone()); |
179
|
|
|
|
180
|
|
|
$this->_em->clear(); |
181
|
|
|
|
182
|
|
|
$entity = $this->_em->find(Attraction::CLASSNAME, $this->attractions[0]->getId()); |
183
|
|
|
|
184
|
|
|
$this->assertInstanceOf(Attraction::CLASSNAME, $entity); |
185
|
|
|
$this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $entity->getInfos()); |
186
|
|
|
$this->assertCount(1, $entity->getInfos()); |
187
|
|
|
|
188
|
|
|
$this->assertInstanceOf(AttractionContactInfo::CLASSNAME, $entity->getInfos()->get(0)); |
189
|
|
|
$this->assertEquals($this->attractionsInfo[0]->getFone(), $entity->getInfos()->get(0)->getFone()); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
public function testQueryCacheShouldBeEvictedOnTimestampUpdate() |
193
|
|
|
{ |
194
|
|
|
$this->loadFixturesCountries(); |
195
|
|
|
$this->loadFixturesStates(); |
196
|
|
|
$this->loadFixturesCities(); |
197
|
|
|
$this->loadFixturesAttractions(); |
198
|
|
|
$this->loadFixturesAttractionsInfo(); |
199
|
|
|
$this->evictRegions(); |
200
|
|
|
$this->_em->clear(); |
201
|
|
|
|
202
|
|
|
$queryCount = $this->getCurrentQueryCount(); |
203
|
|
|
$dql = 'SELECT attractionInfo FROM Doctrine\Tests\Models\Cache\AttractionInfo attractionInfo'; |
204
|
|
|
|
205
|
|
|
$result1 = $this->_em->createQuery($dql) |
206
|
|
|
->setCacheable(true) |
207
|
|
|
->getResult(); |
208
|
|
|
|
209
|
|
|
$this->assertCount(count($this->attractionsInfo), $result1); |
210
|
|
|
$this->assertEquals($queryCount + 5, $this->getCurrentQueryCount()); |
211
|
|
|
|
212
|
|
|
$contact = new AttractionContactInfo( |
213
|
|
|
'1234-1234', |
214
|
|
|
$this->_em->find(Attraction::class, $this->attractions[5]->getId()) |
215
|
|
|
); |
216
|
|
|
|
217
|
|
|
$this->_em->persist($contact); |
218
|
|
|
$this->_em->flush(); |
219
|
|
|
$this->_em->clear(); |
220
|
|
|
|
221
|
|
|
$queryCount = $this->getCurrentQueryCount(); |
222
|
|
|
|
223
|
|
|
$result2 = $this->_em->createQuery($dql) |
224
|
|
|
->setCacheable(true) |
225
|
|
|
->getResult(); |
226
|
|
|
|
227
|
|
|
$this->assertCount(count($this->attractionsInfo) + 1, $result2); |
228
|
|
|
$this->assertEquals($queryCount + 6, $this->getCurrentQueryCount()); |
229
|
|
|
|
230
|
|
|
foreach ($result2 as $entity) { |
231
|
|
|
$this->assertInstanceOf(AttractionInfo::CLASSNAME, $entity); |
232
|
|
|
} |
233
|
|
|
} |
234
|
|
|
} |
235
|
|
|
|