|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Doctrine\Tests\ORM; |
|
6
|
|
|
|
|
7
|
|
|
use ArrayObject; |
|
8
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
9
|
|
|
use Doctrine\Common\EventManager; |
|
10
|
|
|
use Doctrine\Common\NotifyPropertyChanged; |
|
11
|
|
|
use Doctrine\Common\PropertyChangedListener; |
|
12
|
|
|
use Doctrine\ORM\Annotation as ORM; |
|
13
|
|
|
use Doctrine\ORM\Event\PreFlushEventArgs; |
|
14
|
|
|
use Doctrine\ORM\Events; |
|
15
|
|
|
use Doctrine\ORM\Exception\CommitInsideCommit; |
|
16
|
|
|
use Doctrine\ORM\Mapping\ClassMetadata; |
|
17
|
|
|
use Doctrine\ORM\Mapping\ClassMetadataBuildingContext; |
|
18
|
|
|
use Doctrine\ORM\Mapping\ClassMetadataFactory; |
|
19
|
|
|
use Doctrine\ORM\Mapping\GeneratorType; |
|
20
|
|
|
use Doctrine\ORM\ORMInvalidArgumentException; |
|
21
|
|
|
use Doctrine\ORM\Reflection\RuntimeReflectionService; |
|
22
|
|
|
use Doctrine\ORM\UnitOfWork; |
|
23
|
|
|
use Doctrine\Tests\Mocks\ConnectionMock; |
|
24
|
|
|
use Doctrine\Tests\Mocks\DriverMock; |
|
25
|
|
|
use Doctrine\Tests\Mocks\EntityManagerMock; |
|
26
|
|
|
use Doctrine\Tests\Mocks\EntityPersisterMock; |
|
27
|
|
|
use Doctrine\Tests\Mocks\UnitOfWorkMock; |
|
28
|
|
|
use Doctrine\Tests\Models\CMS\CmsPhonenumber; |
|
29
|
|
|
use Doctrine\Tests\Models\Forum\ForumAvatar; |
|
30
|
|
|
use Doctrine\Tests\Models\Forum\ForumUser; |
|
31
|
|
|
use Doctrine\Tests\Models\GeoNames\City; |
|
32
|
|
|
use Doctrine\Tests\Models\GeoNames\Country; |
|
33
|
|
|
use Doctrine\Tests\OrmTestCase; |
|
34
|
|
|
use InvalidArgumentException; |
|
35
|
|
|
use PHPUnit_Framework_MockObject_MockObject; |
|
36
|
|
|
use RuntimeException; |
|
37
|
|
|
use stdClass; |
|
38
|
|
|
use function count; |
|
39
|
|
|
use function get_class; |
|
40
|
|
|
use function random_int; |
|
41
|
|
|
use function serialize; |
|
42
|
|
|
use function uniqid; |
|
43
|
|
|
use function unserialize; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* UnitOfWork tests. |
|
47
|
|
|
*/ |
|
48
|
|
|
class UnitOfWorkTest extends OrmTestCase |
|
49
|
|
|
{ |
|
50
|
|
|
/** |
|
51
|
|
|
* SUT |
|
52
|
|
|
* |
|
53
|
|
|
* @var UnitOfWorkMock |
|
54
|
|
|
*/ |
|
55
|
|
|
private $unitOfWork; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Provides a sequence mock to the UnitOfWork |
|
59
|
|
|
* |
|
60
|
|
|
* @var ConnectionMock |
|
61
|
|
|
*/ |
|
62
|
|
|
private $connectionMock; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* The EntityManager mock that provides the mock persisters |
|
66
|
|
|
* |
|
67
|
|
|
* @var EntityManagerMock |
|
68
|
|
|
*/ |
|
69
|
|
|
private $emMock; |
|
70
|
|
|
|
|
71
|
|
|
/** @var EventManager */ |
|
72
|
|
|
private $eventManager; |
|
73
|
|
|
|
|
74
|
|
|
/** @var ClassMetadataBuildingContext|PHPUnit_Framework_MockObject_MockObject */ |
|
75
|
|
|
private $metadataBuildingContext; |
|
76
|
|
|
|
|
77
|
|
|
protected function setUp() : void |
|
78
|
|
|
{ |
|
79
|
|
|
parent::setUp(); |
|
80
|
|
|
|
|
81
|
|
|
$this->metadataBuildingContext = new ClassMetadataBuildingContext( |
|
82
|
|
|
$this->createMock(ClassMetadataFactory::class), |
|
83
|
|
|
new RuntimeReflectionService() |
|
84
|
|
|
); |
|
85
|
|
|
|
|
86
|
|
|
$this->eventManager = new EventManager(); |
|
87
|
|
|
$this->connectionMock = new ConnectionMock([], new DriverMock(), null, $this->eventManager); |
|
88
|
|
|
$this->emMock = EntityManagerMock::create($this->connectionMock, null, $this->eventManager); |
|
89
|
|
|
$this->unitOfWork = new UnitOfWorkMock($this->emMock); |
|
90
|
|
|
|
|
91
|
|
|
$this->emMock->setUnitOfWork($this->unitOfWork); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function testRegisterRemovedOnNewEntityIsIgnored() : void |
|
95
|
|
|
{ |
|
96
|
|
|
$user = new ForumUser(); |
|
97
|
|
|
$user->username = 'romanb'; |
|
98
|
|
|
self::assertFalse($this->unitOfWork->isScheduledForDelete($user)); |
|
99
|
|
|
$this->unitOfWork->scheduleForDelete($user); |
|
100
|
|
|
self::assertFalse($this->unitOfWork->isScheduledForDelete($user)); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
|
|
104
|
|
|
/** Operational tests */ |
|
105
|
|
|
public function testSavingSingleEntityWithIdentityColumnForcesInsert() : void |
|
106
|
|
|
{ |
|
107
|
|
|
// Setup fake persister and id generator for identity generation |
|
108
|
|
|
$userPersister = new EntityPersisterMock($this->emMock, $this->emMock->getClassMetadata(ForumUser::class)); |
|
109
|
|
|
$this->unitOfWork->setEntityPersister(ForumUser::class, $userPersister); |
|
110
|
|
|
$userPersister->setMockIdGeneratorType(GeneratorType::IDENTITY); |
|
|
|
|
|
|
111
|
|
|
|
|
112
|
|
|
// Test |
|
113
|
|
|
$user = new ForumUser(); |
|
114
|
|
|
$user->username = 'romanb'; |
|
115
|
|
|
$this->unitOfWork->persist($user); |
|
116
|
|
|
|
|
117
|
|
|
// Check |
|
118
|
|
|
self::assertCount(0, $userPersister->getInserts()); |
|
119
|
|
|
self::assertCount(0, $userPersister->getUpdates()); |
|
120
|
|
|
self::assertCount(0, $userPersister->getDeletes()); |
|
121
|
|
|
self::assertFalse($this->unitOfWork->isInIdentityMap($user)); |
|
122
|
|
|
// should no longer be scheduled for insert |
|
123
|
|
|
self::assertTrue($this->unitOfWork->isScheduledForInsert($user)); |
|
124
|
|
|
|
|
125
|
|
|
// Now lets check whether a subsequent commit() does anything |
|
126
|
|
|
$userPersister->reset(); |
|
127
|
|
|
|
|
128
|
|
|
// Test |
|
129
|
|
|
$this->unitOfWork->commit(); |
|
130
|
|
|
|
|
131
|
|
|
// Check. |
|
132
|
|
|
self::assertCount(1, $userPersister->getInserts()); |
|
133
|
|
|
self::assertCount(0, $userPersister->getUpdates()); |
|
134
|
|
|
self::assertCount(0, $userPersister->getDeletes()); |
|
135
|
|
|
|
|
136
|
|
|
// should have an id |
|
137
|
|
|
self::assertInternalType('numeric', $user->id); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* Tests a scenario where a save() operation is cascaded from a ForumUser |
|
142
|
|
|
* to its associated ForumAvatar, both entities using IDENTITY id generation. |
|
143
|
|
|
*/ |
|
144
|
|
|
public function testCascadedIdentityColumnInsert() : void |
|
145
|
|
|
{ |
|
146
|
|
|
// Setup fake persister and id generator for identity generation |
|
147
|
|
|
//ForumUser |
|
148
|
|
|
$userPersister = new EntityPersisterMock($this->emMock, $this->emMock->getClassMetadata(ForumUser::class)); |
|
149
|
|
|
$this->unitOfWork->setEntityPersister(ForumUser::class, $userPersister); |
|
150
|
|
|
$userPersister->setMockIdGeneratorType(GeneratorType::IDENTITY); |
|
|
|
|
|
|
151
|
|
|
// ForumAvatar |
|
152
|
|
|
$avatarPersister = new EntityPersisterMock($this->emMock, $this->emMock->getClassMetadata(ForumAvatar::class)); |
|
153
|
|
|
$this->unitOfWork->setEntityPersister(ForumAvatar::class, $avatarPersister); |
|
154
|
|
|
$avatarPersister->setMockIdGeneratorType(GeneratorType::IDENTITY); |
|
155
|
|
|
|
|
156
|
|
|
// Test |
|
157
|
|
|
$user = new ForumUser(); |
|
158
|
|
|
$user->username = 'romanb'; |
|
159
|
|
|
$avatar = new ForumAvatar(); |
|
160
|
|
|
$user->avatar = $avatar; |
|
161
|
|
|
$this->unitOfWork->persist($user); // save cascaded to avatar |
|
162
|
|
|
|
|
163
|
|
|
$this->unitOfWork->commit(); |
|
164
|
|
|
|
|
165
|
|
|
self::assertInternalType('numeric', $user->id); |
|
166
|
|
|
self::assertInternalType('numeric', $avatar->id); |
|
167
|
|
|
|
|
168
|
|
|
self::assertCount(1, $userPersister->getInserts()); |
|
169
|
|
|
self::assertCount(0, $userPersister->getUpdates()); |
|
170
|
|
|
self::assertCount(0, $userPersister->getDeletes()); |
|
171
|
|
|
|
|
172
|
|
|
self::assertCount(1, $avatarPersister->getInserts()); |
|
173
|
|
|
self::assertCount(0, $avatarPersister->getUpdates()); |
|
174
|
|
|
self::assertCount(0, $avatarPersister->getDeletes()); |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
public function testChangeTrackingNotify() : void |
|
178
|
|
|
{ |
|
179
|
|
|
$persister = new EntityPersisterMock($this->emMock, $this->emMock->getClassMetadata(NotifyChangedEntity::class)); |
|
180
|
|
|
$this->unitOfWork->setEntityPersister(NotifyChangedEntity::class, $persister); |
|
181
|
|
|
$itemPersister = new EntityPersisterMock($this->emMock, $this->emMock->getClassMetadata(NotifyChangedRelatedItem::class)); |
|
182
|
|
|
$this->unitOfWork->setEntityPersister(NotifyChangedRelatedItem::class, $itemPersister); |
|
183
|
|
|
|
|
184
|
|
|
$entity = new NotifyChangedEntity(); |
|
185
|
|
|
$entity->setData('thedata'); |
|
186
|
|
|
$this->unitOfWork->persist($entity); |
|
187
|
|
|
|
|
188
|
|
|
$this->unitOfWork->commit(); |
|
189
|
|
|
self::assertCount(1, $persister->getInserts()); |
|
190
|
|
|
$persister->reset(); |
|
191
|
|
|
|
|
192
|
|
|
self::assertTrue($this->unitOfWork->isInIdentityMap($entity)); |
|
193
|
|
|
|
|
194
|
|
|
$entity->setData('newdata'); |
|
195
|
|
|
$entity->setTransient('newtransientvalue'); |
|
196
|
|
|
|
|
197
|
|
|
self::assertTrue($this->unitOfWork->isScheduledForDirtyCheck($entity)); |
|
198
|
|
|
|
|
199
|
|
|
self::assertEquals( |
|
200
|
|
|
[ |
|
201
|
|
|
'data' => ['thedata', 'newdata'], |
|
202
|
|
|
'transient' => [null, 'newtransientvalue'], |
|
203
|
|
|
], |
|
204
|
|
|
$this->unitOfWork->getEntityChangeSet($entity) |
|
205
|
|
|
); |
|
206
|
|
|
|
|
207
|
|
|
$item = new NotifyChangedRelatedItem(); |
|
208
|
|
|
$entity->getItems()->add($item); |
|
209
|
|
|
$item->setOwner($entity); |
|
210
|
|
|
$this->unitOfWork->persist($item); |
|
211
|
|
|
|
|
212
|
|
|
$this->unitOfWork->commit(); |
|
213
|
|
|
self::assertCount(1, $itemPersister->getInserts()); |
|
214
|
|
|
$persister->reset(); |
|
215
|
|
|
$itemPersister->reset(); |
|
216
|
|
|
|
|
217
|
|
|
$entity->getItems()->removeElement($item); |
|
218
|
|
|
$item->setOwner(null); |
|
219
|
|
|
self::assertTrue($entity->getItems()->isDirty()); |
|
|
|
|
|
|
220
|
|
|
$this->unitOfWork->commit(); |
|
221
|
|
|
$updates = $itemPersister->getUpdates(); |
|
222
|
|
|
self::assertCount(1, $updates); |
|
223
|
|
|
self::assertSame($updates[0], $item); |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
public function testChangeTrackingNotifyIndividualCommit() : void |
|
227
|
|
|
{ |
|
228
|
|
|
self::markTestIncomplete( |
|
229
|
|
|
'@guilhermeblanco, this test was added directly on master#a16dc65cd206aed67a01a19f01f6318192b826af and' |
|
230
|
|
|
. ' since we do not support committing individual entities I think it is invalid now...' |
|
231
|
|
|
); |
|
232
|
|
|
|
|
233
|
|
|
$persister = new EntityPersisterMock($this->emMock, $this->emMock->getClassMetadata('Doctrine\Tests\ORM\NotifyChangedEntity')); |
|
234
|
|
|
$this->unitOfWork->setEntityPersister('Doctrine\Tests\ORM\NotifyChangedEntity', $persister); |
|
235
|
|
|
$itemPersister = new EntityPersisterMock($this->emMock, $this->emMock->getClassMetadata('Doctrine\Tests\ORM\NotifyChangedRelatedItem')); |
|
236
|
|
|
$this->unitOfWork->setEntityPersister('Doctrine\Tests\ORM\NotifyChangedRelatedItem', $itemPersister); |
|
237
|
|
|
|
|
238
|
|
|
$entity = new NotifyChangedEntity(); |
|
239
|
|
|
$entity->setData('thedata'); |
|
240
|
|
|
|
|
241
|
|
|
$entity2 = new NotifyChangedEntity(); |
|
242
|
|
|
$entity2->setData('thedata'); |
|
243
|
|
|
|
|
244
|
|
|
$this->unitOfWork->persist($entity); |
|
245
|
|
|
$this->unitOfWork->persist($entity2); |
|
246
|
|
|
$this->unitOfWork->commit($entity); |
|
247
|
|
|
$this->unitOfWork->commit(); |
|
248
|
|
|
|
|
249
|
|
|
self::assertEquals(2, count($persister->getInserts())); |
|
250
|
|
|
|
|
251
|
|
|
$persister->reset(); |
|
252
|
|
|
|
|
253
|
|
|
self::assertTrue($this->unitOfWork->isInIdentityMap($entity2)); |
|
254
|
|
|
|
|
255
|
|
|
$entity->setData('newdata'); |
|
256
|
|
|
$entity2->setData('newdata'); |
|
257
|
|
|
|
|
258
|
|
|
$this->unitOfWork->commit($entity); |
|
259
|
|
|
|
|
260
|
|
|
self::assertTrue($this->unitOfWork->isScheduledForDirtyCheck($entity2)); |
|
261
|
|
|
self::assertEquals(['data' => ['thedata', 'newdata']], $this->unitOfWork->getEntityChangeSet($entity2)); |
|
262
|
|
|
self::assertFalse($this->unitOfWork->isScheduledForDirtyCheck($entity)); |
|
263
|
|
|
self::assertEquals([], $this->unitOfWork->getEntityChangeSet($entity)); |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
public function testGetEntityStateOnVersionedEntityWithAssignedIdentifier() : void |
|
267
|
|
|
{ |
|
268
|
|
|
$persister = new EntityPersisterMock($this->emMock, $this->emMock->getClassMetadata(VersionedAssignedIdentifierEntity::class)); |
|
269
|
|
|
$this->unitOfWork->setEntityPersister(VersionedAssignedIdentifierEntity::class, $persister); |
|
270
|
|
|
|
|
271
|
|
|
$e = new VersionedAssignedIdentifierEntity(); |
|
272
|
|
|
$e->id = 42; |
|
273
|
|
|
self::assertEquals(UnitOfWork::STATE_NEW, $this->unitOfWork->getEntityState($e)); |
|
274
|
|
|
self::assertFalse($persister->isExistsCalled()); |
|
275
|
|
|
} |
|
276
|
|
|
|
|
277
|
|
|
public function testGetEntityStateWithAssignedIdentity() : void |
|
278
|
|
|
{ |
|
279
|
|
|
$persister = new EntityPersisterMock($this->emMock, $this->emMock->getClassMetadata(CmsPhonenumber::class)); |
|
280
|
|
|
$this->unitOfWork->setEntityPersister(CmsPhonenumber::class, $persister); |
|
281
|
|
|
|
|
282
|
|
|
$ph = new CmsPhonenumber(); |
|
283
|
|
|
$ph->phonenumber = '12345'; |
|
284
|
|
|
|
|
285
|
|
|
self::assertEquals(UnitOfWork::STATE_NEW, $this->unitOfWork->getEntityState($ph)); |
|
286
|
|
|
self::assertTrue($persister->isExistsCalled()); |
|
287
|
|
|
|
|
288
|
|
|
$persister->reset(); |
|
289
|
|
|
|
|
290
|
|
|
// if the entity is already managed the exists() check should be skipped |
|
291
|
|
|
$this->unitOfWork->registerManaged($ph, ['phonenumber' => '12345'], []); |
|
292
|
|
|
self::assertEquals(UnitOfWork::STATE_MANAGED, $this->unitOfWork->getEntityState($ph)); |
|
293
|
|
|
self::assertFalse($persister->isExistsCalled()); |
|
294
|
|
|
$ph2 = new CmsPhonenumber(); |
|
295
|
|
|
$ph2->phonenumber = '12345'; |
|
296
|
|
|
self::assertEquals(UnitOfWork::STATE_DETACHED, $this->unitOfWork->getEntityState($ph2)); |
|
297
|
|
|
self::assertFalse($persister->isExistsCalled()); |
|
298
|
|
|
} |
|
299
|
|
|
|
|
300
|
|
|
/** |
|
301
|
|
|
* DDC-2086 [GH-484] Prevented 'Undefined index' notice when updating. |
|
302
|
|
|
*/ |
|
303
|
|
|
public function testNoUndefinedIndexNoticeOnScheduleForUpdateWithoutChanges() : void |
|
304
|
|
|
{ |
|
305
|
|
|
// Setup fake persister and id generator |
|
306
|
|
|
$userPersister = new EntityPersisterMock($this->emMock, $this->emMock->getClassMetadata(ForumUser::class)); |
|
307
|
|
|
$userPersister->setMockIdGeneratorType(GeneratorType::IDENTITY); |
|
|
|
|
|
|
308
|
|
|
$this->unitOfWork->setEntityPersister(ForumUser::class, $userPersister); |
|
309
|
|
|
|
|
310
|
|
|
// Create a test user |
|
311
|
|
|
$user = new ForumUser(); |
|
312
|
|
|
$user->name = 'Jasper'; |
|
|
|
|
|
|
313
|
|
|
$this->unitOfWork->persist($user); |
|
314
|
|
|
$this->unitOfWork->commit(); |
|
315
|
|
|
|
|
316
|
|
|
// Schedule user for update without changes |
|
317
|
|
|
$this->unitOfWork->scheduleForUpdate($user); |
|
318
|
|
|
|
|
319
|
|
|
self::assertNotEmpty($this->unitOfWork->getScheduledEntityUpdates()); |
|
320
|
|
|
|
|
321
|
|
|
// This commit should not raise an E_NOTICE |
|
322
|
|
|
$this->unitOfWork->commit(); |
|
323
|
|
|
|
|
324
|
|
|
self::assertEmpty($this->unitOfWork->getScheduledEntityUpdates()); |
|
325
|
|
|
} |
|
326
|
|
|
|
|
327
|
|
|
/** |
|
328
|
|
|
* @group DDC-1984 |
|
329
|
|
|
*/ |
|
330
|
|
|
public function testLockWithoutEntityThrowsException() : void |
|
331
|
|
|
{ |
|
332
|
|
|
$this->expectException(InvalidArgumentException::class); |
|
333
|
|
|
$this->unitOfWork->lock(null, null, null); |
|
334
|
|
|
} |
|
335
|
|
|
|
|
336
|
|
|
/** |
|
337
|
|
|
* @param mixed $invalidValue |
|
338
|
|
|
* |
|
339
|
|
|
* @group DDC-3490 |
|
340
|
|
|
* @dataProvider invalidAssociationValuesDataProvider |
|
341
|
|
|
*/ |
|
342
|
|
|
public function testRejectsPersistenceOfObjectsWithInvalidAssociationValue($invalidValue) : void |
|
343
|
|
|
{ |
|
344
|
|
|
$this->unitOfWork->setEntityPersister( |
|
345
|
|
|
ForumUser::class, |
|
346
|
|
|
new EntityPersisterMock( |
|
347
|
|
|
$this->emMock, |
|
348
|
|
|
$this->emMock->getClassMetadata(ForumUser::class) |
|
349
|
|
|
) |
|
350
|
|
|
); |
|
351
|
|
|
|
|
352
|
|
|
$user = new ForumUser(); |
|
353
|
|
|
$user->username = 'John'; |
|
354
|
|
|
$user->avatar = $invalidValue; |
|
355
|
|
|
|
|
356
|
|
|
$this->expectException(ORMInvalidArgumentException::class); |
|
357
|
|
|
|
|
358
|
|
|
$this->unitOfWork->persist($user); |
|
359
|
|
|
} |
|
360
|
|
|
|
|
361
|
|
|
/** |
|
362
|
|
|
* @param mixed $invalidValue |
|
363
|
|
|
* |
|
364
|
|
|
* @group DDC-3490 |
|
365
|
|
|
* @dataProvider invalidAssociationValuesDataProvider |
|
366
|
|
|
*/ |
|
367
|
|
|
public function testRejectsChangeSetComputationForObjectsWithInvalidAssociationValue($invalidValue) : void |
|
368
|
|
|
{ |
|
369
|
|
|
$metadata = $this->emMock->getClassMetadata(ForumUser::class); |
|
370
|
|
|
|
|
371
|
|
|
$this->unitOfWork->setEntityPersister( |
|
372
|
|
|
ForumUser::class, |
|
373
|
|
|
new EntityPersisterMock($this->emMock, $metadata) |
|
374
|
|
|
); |
|
375
|
|
|
|
|
376
|
|
|
$user = new ForumUser(); |
|
377
|
|
|
|
|
378
|
|
|
$this->unitOfWork->persist($user); |
|
379
|
|
|
|
|
380
|
|
|
$user->username = 'John'; |
|
381
|
|
|
$user->avatar = $invalidValue; |
|
382
|
|
|
|
|
383
|
|
|
$this->expectException(ORMInvalidArgumentException::class); |
|
384
|
|
|
|
|
385
|
|
|
$this->unitOfWork->computeChangeSet($metadata, $user); |
|
386
|
|
|
} |
|
387
|
|
|
|
|
388
|
|
|
/** |
|
389
|
|
|
* @group DDC-3619 |
|
390
|
|
|
* @group 1338 |
|
391
|
|
|
*/ |
|
392
|
|
|
public function testRemovedAndRePersistedEntitiesAreInTheIdentityMapAndAreNotGarbageCollected() : void |
|
393
|
|
|
{ |
|
394
|
|
|
$entity = new ForumUser(); |
|
395
|
|
|
$entity->id = 123; |
|
396
|
|
|
|
|
397
|
|
|
$this->unitOfWork->registerManaged($entity, ['id' => 123], []); |
|
398
|
|
|
self::assertTrue($this->unitOfWork->isInIdentityMap($entity)); |
|
399
|
|
|
|
|
400
|
|
|
$this->unitOfWork->remove($entity); |
|
401
|
|
|
self::assertFalse($this->unitOfWork->isInIdentityMap($entity)); |
|
402
|
|
|
|
|
403
|
|
|
$this->unitOfWork->persist($entity); |
|
404
|
|
|
self::assertTrue($this->unitOfWork->isInIdentityMap($entity)); |
|
405
|
|
|
} |
|
406
|
|
|
|
|
407
|
|
|
/** |
|
408
|
|
|
* @group 5849 |
|
409
|
|
|
* @group 5850 |
|
410
|
|
|
*/ |
|
411
|
|
|
public function testPersistedEntityAndClearManager() : void |
|
412
|
|
|
{ |
|
413
|
|
|
$entity1 = new City(123, 'London'); |
|
414
|
|
|
$entity2 = new Country(456, 'United Kingdom'); |
|
415
|
|
|
|
|
416
|
|
|
$this->unitOfWork->persist($entity1); |
|
417
|
|
|
self::assertTrue($this->unitOfWork->isInIdentityMap($entity1)); |
|
418
|
|
|
|
|
419
|
|
|
$this->unitOfWork->persist($entity2); |
|
420
|
|
|
self::assertTrue($this->unitOfWork->isInIdentityMap($entity2)); |
|
421
|
|
|
|
|
422
|
|
|
$this->unitOfWork->clear(); |
|
423
|
|
|
|
|
424
|
|
|
self::assertFalse($this->unitOfWork->isInIdentityMap($entity1)); |
|
425
|
|
|
self::assertFalse($this->unitOfWork->isInIdentityMap($entity2)); |
|
426
|
|
|
|
|
427
|
|
|
self::assertFalse($this->unitOfWork->isScheduledForInsert($entity1)); |
|
428
|
|
|
self::assertFalse($this->unitOfWork->isScheduledForInsert($entity2)); |
|
429
|
|
|
} |
|
430
|
|
|
|
|
431
|
|
|
/** |
|
432
|
|
|
* @group #5579 |
|
433
|
|
|
*/ |
|
434
|
|
|
public function testEntityChangeSetIsClearedAfterFlush() : void |
|
435
|
|
|
{ |
|
436
|
|
|
$entity1 = new NotifyChangedEntity(); |
|
437
|
|
|
$entity2 = new NotifyChangedEntity(); |
|
438
|
|
|
|
|
439
|
|
|
$entity1->setData('thedata'); |
|
440
|
|
|
$entity2->setData('thedata'); |
|
441
|
|
|
|
|
442
|
|
|
$this->unitOfWork->persist($entity1); |
|
443
|
|
|
$this->unitOfWork->persist($entity2); |
|
444
|
|
|
$this->unitOfWork->commit(); |
|
445
|
|
|
|
|
446
|
|
|
self::assertEmpty($this->unitOfWork->getEntityChangeSet($entity1)); |
|
447
|
|
|
self::assertEmpty($this->unitOfWork->getEntityChangeSet($entity2)); |
|
448
|
|
|
} |
|
449
|
|
|
|
|
450
|
|
|
/** |
|
451
|
|
|
* Data Provider |
|
452
|
|
|
* |
|
453
|
|
|
* @return mixed[][] |
|
454
|
|
|
*/ |
|
455
|
|
|
public function invalidAssociationValuesDataProvider() |
|
456
|
|
|
{ |
|
457
|
|
|
return [ |
|
458
|
|
|
['foo'], |
|
459
|
|
|
[['foo']], |
|
460
|
|
|
[''], |
|
461
|
|
|
[[]], |
|
462
|
|
|
[new stdClass()], |
|
463
|
|
|
[new ArrayCollection()], |
|
464
|
|
|
]; |
|
465
|
|
|
} |
|
466
|
|
|
|
|
467
|
|
|
/** |
|
468
|
|
|
* @param object $entity |
|
469
|
|
|
* @param string $idHash |
|
470
|
|
|
* |
|
471
|
|
|
* @dataProvider entitiesWithValidIdentifiersProvider |
|
472
|
|
|
*/ |
|
473
|
|
|
public function testAddToIdentityMapValidIdentifiers($entity, $idHash) : void |
|
474
|
|
|
{ |
|
475
|
|
|
$this->unitOfWork->persist($entity); |
|
476
|
|
|
$this->unitOfWork->addToIdentityMap($entity); |
|
477
|
|
|
|
|
478
|
|
|
self::assertSame($entity, $this->unitOfWork->getByIdHash($idHash, get_class($entity))); |
|
479
|
|
|
} |
|
480
|
|
|
|
|
481
|
|
|
public function entitiesWithValidIdentifiersProvider() |
|
482
|
|
|
{ |
|
483
|
|
|
$emptyString = new EntityWithStringIdentifier(); |
|
484
|
|
|
|
|
485
|
|
|
$emptyString->id = ''; |
|
486
|
|
|
|
|
487
|
|
|
$nonEmptyString = new EntityWithStringIdentifier(); |
|
488
|
|
|
|
|
489
|
|
|
$nonEmptyString->id = uniqid('id', true); |
|
490
|
|
|
|
|
491
|
|
|
$emptyStrings = new EntityWithCompositeStringIdentifier(); |
|
492
|
|
|
|
|
493
|
|
|
$emptyStrings->id1 = ''; |
|
494
|
|
|
$emptyStrings->id2 = ''; |
|
495
|
|
|
|
|
496
|
|
|
$nonEmptyStrings = new EntityWithCompositeStringIdentifier(); |
|
497
|
|
|
|
|
498
|
|
|
$nonEmptyStrings->id1 = uniqid('id1', true); |
|
499
|
|
|
$nonEmptyStrings->id2 = uniqid('id2', true); |
|
500
|
|
|
|
|
501
|
|
|
$booleanTrue = new EntityWithBooleanIdentifier(); |
|
502
|
|
|
|
|
503
|
|
|
$booleanTrue->id = true; |
|
504
|
|
|
|
|
505
|
|
|
$booleanFalse = new EntityWithBooleanIdentifier(); |
|
506
|
|
|
|
|
507
|
|
|
$booleanFalse->id = false; |
|
508
|
|
|
|
|
509
|
|
|
return [ |
|
510
|
|
|
'empty string, single field' => [$emptyString, ''], |
|
511
|
|
|
'non-empty string, single field' => [$nonEmptyString, $nonEmptyString->id], |
|
512
|
|
|
'empty strings, two fields' => [$emptyStrings, ' '], |
|
513
|
|
|
'non-empty strings, two fields' => [$nonEmptyStrings, $nonEmptyStrings->id1 . ' ' . $nonEmptyStrings->id2], |
|
514
|
|
|
'boolean true' => [$booleanTrue, '1'], |
|
515
|
|
|
'boolean false' => [$booleanFalse, ''], |
|
516
|
|
|
]; |
|
517
|
|
|
} |
|
518
|
|
|
|
|
519
|
|
|
public function testRegisteringAManagedInstanceRequiresANonEmptyIdentifier() : void |
|
520
|
|
|
{ |
|
521
|
|
|
$this->expectException(ORMInvalidArgumentException::class); |
|
522
|
|
|
|
|
523
|
|
|
$this->unitOfWork->registerManaged(new EntityWithBooleanIdentifier(), [], []); |
|
524
|
|
|
} |
|
525
|
|
|
|
|
526
|
|
|
/** |
|
527
|
|
|
* @param object $entity |
|
528
|
|
|
* @param array $identifier |
|
529
|
|
|
* |
|
530
|
|
|
* @dataProvider entitiesWithInvalidIdentifiersProvider |
|
531
|
|
|
*/ |
|
532
|
|
|
public function testAddToIdentityMapInvalidIdentifiers($entity, array $identifier) : void |
|
533
|
|
|
{ |
|
534
|
|
|
$this->expectException(ORMInvalidArgumentException::class); |
|
535
|
|
|
|
|
536
|
|
|
$this->unitOfWork->registerManaged($entity, $identifier, []); |
|
537
|
|
|
} |
|
538
|
|
|
|
|
539
|
|
|
|
|
540
|
|
|
public function entitiesWithInvalidIdentifiersProvider() |
|
541
|
|
|
{ |
|
542
|
|
|
$firstNullString = new EntityWithCompositeStringIdentifier(); |
|
543
|
|
|
|
|
544
|
|
|
$firstNullString->id2 = uniqid('id2', true); |
|
545
|
|
|
|
|
546
|
|
|
$secondNullString = new EntityWithCompositeStringIdentifier(); |
|
547
|
|
|
|
|
548
|
|
|
$secondNullString->id1 = uniqid('id1', true); |
|
549
|
|
|
|
|
550
|
|
|
return [ |
|
551
|
|
|
'null string, single field' => [new EntityWithStringIdentifier(), ['id' => null]], |
|
552
|
|
|
'null strings, two fields' => [new EntityWithCompositeStringIdentifier(), ['id1' => null, 'id2' => null]], |
|
553
|
|
|
'first null string, two fields' => [$firstNullString, ['id1' => null, 'id2' => $firstNullString->id2]], |
|
554
|
|
|
'second null string, two fields' => [$secondNullString, ['id1' => $secondNullString->id1, 'id2' => null]], |
|
555
|
|
|
]; |
|
556
|
|
|
} |
|
557
|
|
|
|
|
558
|
|
|
/** |
|
559
|
|
|
* Unlike next test, this one demonstrates that the problem does |
|
560
|
|
|
* not necessarily reproduce if all the pieces are being flushed together. |
|
561
|
|
|
* |
|
562
|
|
|
* @group DDC-2922 |
|
563
|
|
|
* @group #1521 |
|
564
|
|
|
*/ |
|
565
|
|
|
public function testNewAssociatedEntityPersistenceOfNewEntitiesThroughCascadedAssociationsFirst() : void |
|
566
|
|
|
{ |
|
567
|
|
|
$persister1 = new EntityPersisterMock($this->emMock, $this->emMock->getClassMetadata(CascadePersistedEntity::class)); |
|
568
|
|
|
$persister2 = new EntityPersisterMock($this->emMock, $this->emMock->getClassMetadata(EntityWithCascadingAssociation::class)); |
|
569
|
|
|
$persister3 = new EntityPersisterMock($this->emMock, $this->emMock->getClassMetadata(EntityWithNonCascadingAssociation::class)); |
|
570
|
|
|
|
|
571
|
|
|
$this->unitOfWork->setEntityPersister(CascadePersistedEntity::class, $persister1); |
|
572
|
|
|
$this->unitOfWork->setEntityPersister(EntityWithCascadingAssociation::class, $persister2); |
|
573
|
|
|
$this->unitOfWork->setEntityPersister(EntityWithNonCascadingAssociation::class, $persister3); |
|
574
|
|
|
|
|
575
|
|
|
$cascadePersisted = new CascadePersistedEntity(); |
|
576
|
|
|
$cascading = new EntityWithCascadingAssociation(); |
|
577
|
|
|
$nonCascading = new EntityWithNonCascadingAssociation(); |
|
578
|
|
|
|
|
579
|
|
|
// First we persist and flush a EntityWithCascadingAssociation with |
|
580
|
|
|
// the cascading association not set. Having the "cascading path" involve |
|
581
|
|
|
// a non-new object is important to show that the ORM should be considering |
|
582
|
|
|
// cascades across entity changesets in subsequent flushes. |
|
583
|
|
|
$cascading->cascaded = $cascadePersisted; |
|
584
|
|
|
$nonCascading->cascaded = $cascadePersisted; |
|
|
|
|
|
|
585
|
|
|
|
|
586
|
|
|
$this->unitOfWork->persist($cascading); |
|
587
|
|
|
$this->unitOfWork->persist($nonCascading); |
|
588
|
|
|
$this->unitOfWork->commit(); |
|
589
|
|
|
|
|
590
|
|
|
self::assertCount(1, $persister1->getInserts()); |
|
591
|
|
|
self::assertCount(1, $persister2->getInserts()); |
|
592
|
|
|
self::assertCount(1, $persister3->getInserts()); |
|
593
|
|
|
} |
|
594
|
|
|
|
|
595
|
|
|
/** |
|
596
|
|
|
* This test exhibits the bug describe in the ticket, where an object that |
|
597
|
|
|
* ought to be reachable causes errors. |
|
598
|
|
|
* |
|
599
|
|
|
* @group DDC-2922 |
|
600
|
|
|
* @group #1521 |
|
601
|
|
|
*/ |
|
602
|
|
|
public function testNewAssociatedEntityPersistenceOfNewEntitiesThroughNonCascadedAssociationsFirst() : void |
|
603
|
|
|
{ |
|
604
|
|
|
$persister1 = new EntityPersisterMock($this->emMock, $this->emMock->getClassMetadata(CascadePersistedEntity::class)); |
|
605
|
|
|
$persister2 = new EntityPersisterMock($this->emMock, $this->emMock->getClassMetadata(EntityWithCascadingAssociation::class)); |
|
606
|
|
|
$persister3 = new EntityPersisterMock($this->emMock, $this->emMock->getClassMetadata(EntityWithNonCascadingAssociation::class)); |
|
607
|
|
|
|
|
608
|
|
|
$this->unitOfWork->setEntityPersister(CascadePersistedEntity::class, $persister1); |
|
609
|
|
|
$this->unitOfWork->setEntityPersister(EntityWithCascadingAssociation::class, $persister2); |
|
610
|
|
|
$this->unitOfWork->setEntityPersister(EntityWithNonCascadingAssociation::class, $persister3); |
|
611
|
|
|
|
|
612
|
|
|
$cascadePersisted = new CascadePersistedEntity(); |
|
613
|
|
|
$cascading = new EntityWithCascadingAssociation(); |
|
614
|
|
|
$nonCascading = new EntityWithNonCascadingAssociation(); |
|
615
|
|
|
|
|
616
|
|
|
// First we persist and flush a EntityWithCascadingAssociation with |
|
617
|
|
|
// the cascading association not set. Having the "cascading path" involve |
|
618
|
|
|
// a non-new object is important to show that the ORM should be considering |
|
619
|
|
|
// cascades across entity changesets in subsequent flushes. |
|
620
|
|
|
$cascading->cascaded = null; |
|
621
|
|
|
|
|
622
|
|
|
$this->unitOfWork->persist($cascading); |
|
623
|
|
|
$this->unitOfWork->commit(); |
|
624
|
|
|
|
|
625
|
|
|
self::assertCount(0, $persister1->getInserts()); |
|
626
|
|
|
self::assertCount(1, $persister2->getInserts()); |
|
627
|
|
|
self::assertCount(0, $persister3->getInserts()); |
|
628
|
|
|
|
|
629
|
|
|
// Note that we have NOT directly persisted the CascadePersistedEntity, |
|
630
|
|
|
// and EntityWithNonCascadingAssociation does NOT have a configured |
|
631
|
|
|
// cascade-persist. |
|
632
|
|
|
$nonCascading->nonCascaded = $cascadePersisted; |
|
633
|
|
|
|
|
634
|
|
|
// However, EntityWithCascadingAssociation *does* have a cascade-persist |
|
635
|
|
|
// association, which ought to allow us to save the CascadePersistedEntity |
|
636
|
|
|
// anyway through that connection. |
|
637
|
|
|
$cascading->cascaded = $cascadePersisted; |
|
638
|
|
|
|
|
639
|
|
|
$this->unitOfWork->persist($nonCascading); |
|
640
|
|
|
$this->unitOfWork->commit(); |
|
641
|
|
|
|
|
642
|
|
|
self::assertCount(1, $persister1->getInserts()); |
|
643
|
|
|
self::assertCount(1, $persister2->getInserts()); |
|
644
|
|
|
self::assertCount(1, $persister3->getInserts()); |
|
645
|
|
|
} |
|
646
|
|
|
|
|
647
|
|
|
/** |
|
648
|
|
|
* This test exhibits the bug describe in the ticket, where an object that |
|
649
|
|
|
* ought to be reachable causes errors. |
|
650
|
|
|
* |
|
651
|
|
|
* @group DDC-2922 |
|
652
|
|
|
* @group #1521 |
|
653
|
|
|
*/ |
|
654
|
|
|
public function testPreviousDetectedIllegalNewNonCascadedEntitiesAreCleanedUpOnSubsequentCommits() : void |
|
655
|
|
|
{ |
|
656
|
|
|
$persister1 = new EntityPersisterMock($this->emMock, $this->emMock->getClassMetadata(CascadePersistedEntity::class)); |
|
657
|
|
|
$persister2 = new EntityPersisterMock($this->emMock, $this->emMock->getClassMetadata(EntityWithNonCascadingAssociation::class)); |
|
658
|
|
|
|
|
659
|
|
|
$this->unitOfWork->setEntityPersister(CascadePersistedEntity::class, $persister1); |
|
660
|
|
|
$this->unitOfWork->setEntityPersister(EntityWithNonCascadingAssociation::class, $persister2); |
|
661
|
|
|
|
|
662
|
|
|
$cascadePersisted = new CascadePersistedEntity(); |
|
663
|
|
|
$nonCascading = new EntityWithNonCascadingAssociation(); |
|
664
|
|
|
|
|
665
|
|
|
// We explicitly cause the ORM to detect a non-persisted new entity in the association graph: |
|
666
|
|
|
$nonCascading->nonCascaded = $cascadePersisted; |
|
667
|
|
|
|
|
668
|
|
|
$this->unitOfWork->persist($nonCascading); |
|
669
|
|
|
|
|
670
|
|
|
try { |
|
671
|
|
|
$this->unitOfWork->commit(); |
|
672
|
|
|
|
|
673
|
|
|
self::fail('An exception was supposed to be raised'); |
|
674
|
|
|
} catch (ORMInvalidArgumentException $ignored) { |
|
675
|
|
|
self::assertEmpty($persister1->getInserts()); |
|
676
|
|
|
self::assertEmpty($persister2->getInserts()); |
|
677
|
|
|
} |
|
678
|
|
|
|
|
679
|
|
|
$this->unitOfWork->clear(); |
|
680
|
|
|
$this->unitOfWork->persist(new CascadePersistedEntity()); |
|
681
|
|
|
$this->unitOfWork->commit(); |
|
682
|
|
|
|
|
683
|
|
|
// Persistence operations should just recover normally: |
|
684
|
|
|
self::assertCount(1, $persister1->getInserts()); |
|
685
|
|
|
self::assertCount(0, $persister2->getInserts()); |
|
686
|
|
|
} |
|
687
|
|
|
|
|
688
|
|
|
/** |
|
689
|
|
|
* @group DDC-3120 |
|
690
|
|
|
*/ |
|
691
|
|
|
public function testCanInstantiateInternalPhpClassSubclass() : void |
|
692
|
|
|
{ |
|
693
|
|
|
$classMetadata = new ClassMetadata(MyArrayObjectEntity::class, $this->metadataBuildingContext); |
|
694
|
|
|
|
|
695
|
|
|
self::assertInstanceOf(MyArrayObjectEntity::class, $this->unitOfWork->newInstance($classMetadata)); |
|
696
|
|
|
} |
|
697
|
|
|
|
|
698
|
|
|
/** |
|
699
|
|
|
* @group DDC-3120 |
|
700
|
|
|
*/ |
|
701
|
|
|
public function testCanInstantiateInternalPhpClassSubclassFromUnserializedMetadata() : void |
|
702
|
|
|
{ |
|
703
|
|
|
/** @var ClassMetadata $classMetadata */ |
|
704
|
|
|
$classMetadata = unserialize( |
|
705
|
|
|
serialize( |
|
706
|
|
|
new ClassMetadata(MyArrayObjectEntity::class, $this->metadataBuildingContext) |
|
707
|
|
|
) |
|
708
|
|
|
); |
|
709
|
|
|
|
|
710
|
|
|
$classMetadata->wakeupReflection(new RuntimeReflectionService()); |
|
711
|
|
|
|
|
712
|
|
|
self::assertInstanceOf(MyArrayObjectEntity::class, $this->unitOfWork->newInstance($classMetadata)); |
|
713
|
|
|
} |
|
714
|
|
|
|
|
715
|
|
|
public function testCallCommitInsideCommit() : void |
|
716
|
|
|
{ |
|
717
|
|
|
$listener = new class() |
|
718
|
|
|
{ |
|
719
|
|
|
public function preFlush(PreFlushEventArgs $eventArgs) |
|
720
|
|
|
{ |
|
721
|
|
|
$eventArgs->getEntityManager()->getUnitOfWork()->commit(); |
|
722
|
|
|
} |
|
723
|
|
|
}; |
|
724
|
|
|
|
|
725
|
|
|
$this->expectException(CommitInsideCommit::class); |
|
726
|
|
|
$this->eventManager->addEventListener(Events::preFlush, $listener); |
|
727
|
|
|
$this->unitOfWork->commit(); |
|
728
|
|
|
} |
|
729
|
|
|
|
|
730
|
|
|
public function testCommitWithExceptionClearsInProgressFlag() : void |
|
731
|
|
|
{ |
|
732
|
|
|
$listenerCallCounter = 0; |
|
733
|
|
|
$listener = new class($listenerCallCounter) |
|
|
|
|
|
|
734
|
|
|
{ |
|
735
|
|
|
private $listenerCallCounter; |
|
736
|
|
|
|
|
737
|
|
|
public function __construct(int &$listenerCallCounter) |
|
738
|
|
|
{ |
|
739
|
|
|
$this->listenerCallCounter = &$listenerCallCounter; |
|
740
|
|
|
} |
|
741
|
|
|
|
|
742
|
|
|
public function preFlush(PreFlushEventArgs $eventArgs) |
|
|
|
|
|
|
743
|
|
|
{ |
|
744
|
|
|
$this->listenerCallCounter++; |
|
745
|
|
|
throw new RuntimeException(); |
|
746
|
|
|
} |
|
747
|
|
|
}; |
|
748
|
|
|
|
|
749
|
|
|
$this->eventManager->addEventListener(Events::preFlush, $listener); |
|
750
|
|
|
try { |
|
751
|
|
|
$this->unitOfWork->commit(); |
|
752
|
|
|
} catch (RuntimeException $e) { |
|
|
|
|
|
|
753
|
|
|
} |
|
754
|
|
|
|
|
755
|
|
|
$this->eventManager->removeEventListener(Events::preFlush, $listener); |
|
756
|
|
|
|
|
757
|
|
|
try { |
|
758
|
|
|
$this->unitOfWork->commit(); |
|
759
|
|
|
} catch (CommitInsideCommit $e) { |
|
760
|
|
|
$this->fail('UnitOfWork::$commitInProgress flag must be reset in case of exception during commit process'); |
|
761
|
|
|
} |
|
762
|
|
|
|
|
763
|
|
|
$this->assertEquals(1, $listenerCallCounter); |
|
764
|
|
|
} |
|
765
|
|
|
} |
|
766
|
|
|
|
|
767
|
|
|
/** |
|
768
|
|
|
* @ORM\Entity |
|
769
|
|
|
*/ |
|
770
|
|
|
class NotifyChangedEntity implements NotifyPropertyChanged |
|
771
|
|
|
{ |
|
772
|
|
|
private $listeners = []; |
|
773
|
|
|
/** |
|
774
|
|
|
* @ORM\Id |
|
775
|
|
|
* @ORM\Column(type="integer") |
|
776
|
|
|
* @ORM\GeneratedValue |
|
777
|
|
|
*/ |
|
778
|
|
|
private $id; |
|
779
|
|
|
/** @ORM\Column(type="string") */ |
|
780
|
|
|
private $data; |
|
781
|
|
|
|
|
782
|
|
|
private $transient; // not persisted |
|
783
|
|
|
|
|
784
|
|
|
/** @ORM\OneToMany(targetEntity=NotifyChangedRelatedItem::class, mappedBy="owner") */ |
|
785
|
|
|
private $items; |
|
786
|
|
|
|
|
787
|
|
|
public function __construct() |
|
788
|
|
|
{ |
|
789
|
|
|
$this->items = new ArrayCollection(); |
|
790
|
|
|
} |
|
791
|
|
|
|
|
792
|
|
|
public function getId() |
|
793
|
|
|
{ |
|
794
|
|
|
return $this->id; |
|
795
|
|
|
} |
|
796
|
|
|
|
|
797
|
|
|
public function getItems() |
|
798
|
|
|
{ |
|
799
|
|
|
return $this->items; |
|
800
|
|
|
} |
|
801
|
|
|
|
|
802
|
|
|
public function setTransient($value) |
|
803
|
|
|
{ |
|
804
|
|
|
if ($value !== $this->transient) { |
|
805
|
|
|
$this->onPropertyChanged('transient', $this->transient, $value); |
|
806
|
|
|
$this->transient = $value; |
|
807
|
|
|
} |
|
808
|
|
|
} |
|
809
|
|
|
|
|
810
|
|
|
public function getData() |
|
811
|
|
|
{ |
|
812
|
|
|
return $this->data; |
|
813
|
|
|
} |
|
814
|
|
|
|
|
815
|
|
|
public function setData($data) |
|
816
|
|
|
{ |
|
817
|
|
|
if ($data !== $this->data) { |
|
818
|
|
|
$this->onPropertyChanged('data', $this->data, $data); |
|
819
|
|
|
$this->data = $data; |
|
820
|
|
|
} |
|
821
|
|
|
} |
|
822
|
|
|
|
|
823
|
|
|
public function addPropertyChangedListener(PropertyChangedListener $listener) |
|
824
|
|
|
{ |
|
825
|
|
|
$this->listeners[] = $listener; |
|
826
|
|
|
} |
|
827
|
|
|
|
|
828
|
|
|
protected function onPropertyChanged($propName, $oldValue, $newValue) |
|
829
|
|
|
{ |
|
830
|
|
|
if ($this->listeners) { |
|
|
|
|
|
|
831
|
|
|
foreach ($this->listeners as $listener) { |
|
832
|
|
|
$listener->propertyChanged($this, $propName, $oldValue, $newValue); |
|
833
|
|
|
} |
|
834
|
|
|
} |
|
835
|
|
|
} |
|
836
|
|
|
} |
|
837
|
|
|
|
|
838
|
|
|
/** @ORM\Entity */ |
|
839
|
|
|
class NotifyChangedRelatedItem |
|
840
|
|
|
{ |
|
841
|
|
|
/** |
|
842
|
|
|
* @ORM\Id |
|
843
|
|
|
* @ORM\Column(type="integer") |
|
844
|
|
|
* @ORM\GeneratedValue |
|
845
|
|
|
*/ |
|
846
|
|
|
private $id; |
|
847
|
|
|
|
|
848
|
|
|
/** @ORM\ManyToOne(targetEntity=NotifyChangedEntity::class, inversedBy="items") */ |
|
849
|
|
|
private $owner; |
|
850
|
|
|
|
|
851
|
|
|
public function getId() |
|
852
|
|
|
{ |
|
853
|
|
|
return $this->id; |
|
854
|
|
|
} |
|
855
|
|
|
|
|
856
|
|
|
public function getOwner() |
|
857
|
|
|
{ |
|
858
|
|
|
return $this->owner; |
|
859
|
|
|
} |
|
860
|
|
|
|
|
861
|
|
|
public function setOwner($owner) |
|
862
|
|
|
{ |
|
863
|
|
|
$this->owner = $owner; |
|
864
|
|
|
} |
|
865
|
|
|
} |
|
866
|
|
|
|
|
867
|
|
|
/** @ORM\Entity */ |
|
868
|
|
|
class VersionedAssignedIdentifierEntity |
|
869
|
|
|
{ |
|
870
|
|
|
/** @ORM\Id @ORM\Column(type="integer") */ |
|
871
|
|
|
public $id; |
|
872
|
|
|
/** @ORM\Version @ORM\Column(type="integer") */ |
|
873
|
|
|
public $version; |
|
874
|
|
|
} |
|
875
|
|
|
|
|
876
|
|
|
/** @ORM\Entity */ |
|
877
|
|
|
class EntityWithStringIdentifier |
|
878
|
|
|
{ |
|
879
|
|
|
/** |
|
880
|
|
|
* @ORM\Id @ORM\Column(type="string") |
|
881
|
|
|
* |
|
882
|
|
|
* @var string|null |
|
883
|
|
|
*/ |
|
884
|
|
|
public $id; |
|
885
|
|
|
} |
|
886
|
|
|
|
|
887
|
|
|
/** @ORM\Entity */ |
|
888
|
|
|
class EntityWithBooleanIdentifier |
|
889
|
|
|
{ |
|
890
|
|
|
/** |
|
891
|
|
|
* @ORM\Id @ORM\Column(type="boolean") |
|
892
|
|
|
* |
|
893
|
|
|
* @var bool|null |
|
894
|
|
|
*/ |
|
895
|
|
|
public $id; |
|
896
|
|
|
} |
|
897
|
|
|
|
|
898
|
|
|
/** @ORM\Entity */ |
|
899
|
|
|
class EntityWithCompositeStringIdentifier |
|
900
|
|
|
{ |
|
901
|
|
|
/** |
|
902
|
|
|
* @ORM\Id @ORM\Column(type="string") |
|
903
|
|
|
* |
|
904
|
|
|
* @var string|null |
|
905
|
|
|
*/ |
|
906
|
|
|
public $id1; |
|
907
|
|
|
|
|
908
|
|
|
/** |
|
909
|
|
|
* @ORM\Id @ORM\Column(type="string") |
|
910
|
|
|
* |
|
911
|
|
|
* @var string|null |
|
912
|
|
|
*/ |
|
913
|
|
|
public $id2; |
|
914
|
|
|
} |
|
915
|
|
|
|
|
916
|
|
|
/** @ORM\Entity */ |
|
917
|
|
|
class EntityWithRandomlyGeneratedField |
|
918
|
|
|
{ |
|
919
|
|
|
/** @ORM\Id @ORM\Column(type="string") */ |
|
920
|
|
|
public $id; |
|
921
|
|
|
|
|
922
|
|
|
/** @ORM\Column(type="integer") */ |
|
923
|
|
|
public $generatedField; |
|
924
|
|
|
|
|
925
|
|
|
public function __construct() |
|
926
|
|
|
{ |
|
927
|
|
|
$this->id = uniqid('id', true); |
|
928
|
|
|
$this->generatedField = random_int(0, 100000); |
|
929
|
|
|
} |
|
930
|
|
|
} |
|
931
|
|
|
|
|
932
|
|
|
/** @ORM\Entity */ |
|
933
|
|
|
class CascadePersistedEntity |
|
934
|
|
|
{ |
|
935
|
|
|
/** @ORM\Id @ORM\Column(type="string") @ORM\GeneratedValue(strategy="NONE") */ |
|
936
|
|
|
private $id; |
|
937
|
|
|
|
|
938
|
|
|
public function __construct() |
|
939
|
|
|
{ |
|
940
|
|
|
$this->id = uniqid(self::class, true); |
|
941
|
|
|
} |
|
942
|
|
|
} |
|
943
|
|
|
|
|
944
|
|
|
/** @ORM\Entity */ |
|
945
|
|
|
class EntityWithCascadingAssociation |
|
946
|
|
|
{ |
|
947
|
|
|
/** @ORM\Id @ORM\Column(type="string") @ORM\GeneratedValue(strategy="NONE") */ |
|
948
|
|
|
private $id; |
|
949
|
|
|
|
|
950
|
|
|
/** @ORM\ManyToOne(targetEntity=CascadePersistedEntity::class, cascade={"persist"}) */ |
|
951
|
|
|
public $cascaded; |
|
952
|
|
|
|
|
953
|
|
|
public function __construct() |
|
954
|
|
|
{ |
|
955
|
|
|
$this->id = uniqid(self::class, true); |
|
956
|
|
|
} |
|
957
|
|
|
} |
|
958
|
|
|
|
|
959
|
|
|
/** @ORM\Entity */ |
|
960
|
|
|
class EntityWithNonCascadingAssociation |
|
961
|
|
|
{ |
|
962
|
|
|
/** @ORM\Id @ORM\Column(type="string") @ORM\GeneratedValue(strategy="NONE") */ |
|
963
|
|
|
private $id; |
|
964
|
|
|
|
|
965
|
|
|
/** @ORM\ManyToOne(targetEntity=CascadePersistedEntity::class) */ |
|
966
|
|
|
public $nonCascaded; |
|
967
|
|
|
|
|
968
|
|
|
public function __construct() |
|
969
|
|
|
{ |
|
970
|
|
|
$this->id = uniqid(self::class, true); |
|
971
|
|
|
} |
|
972
|
|
|
} |
|
973
|
|
|
|
|
974
|
|
|
class MyArrayObjectEntity extends ArrayObject |
|
975
|
|
|
{ |
|
976
|
|
|
} |
|
977
|
|
|
|