1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sonata Project package. |
5
|
|
|
* |
6
|
|
|
* (c) Thomas Rabaix <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sonata\DoctrineORMAdminBundle\Tests\Model; |
13
|
|
|
|
14
|
|
|
use Doctrine\DBAL\Types\Type; |
15
|
|
|
use Doctrine\ORM\Mapping\ClassMetadata; |
16
|
|
|
use Doctrine\ORM\OptimisticLockException; |
17
|
|
|
use Doctrine\ORM\Query; |
18
|
|
|
use Doctrine\ORM\Version; |
19
|
|
|
use Sonata\DoctrineORMAdminBundle\Admin\FieldDescription; |
20
|
|
|
use Sonata\DoctrineORMAdminBundle\Model\ModelManager; |
21
|
|
|
use Sonata\DoctrineORMAdminBundle\Tests\Fixtures\DoctrineType\UuidType; |
22
|
|
|
use Sonata\DoctrineORMAdminBundle\Tests\Fixtures\Entity\AssociatedEntity; |
23
|
|
|
use Sonata\DoctrineORMAdminBundle\Tests\Fixtures\Entity\ContainerEntity; |
24
|
|
|
use Sonata\DoctrineORMAdminBundle\Tests\Fixtures\Entity\Embeddable\EmbeddedEntity; |
25
|
|
|
use Sonata\DoctrineORMAdminBundle\Tests\Fixtures\Entity\UuidEntity; |
26
|
|
|
use Sonata\DoctrineORMAdminBundle\Tests\Fixtures\Entity\VersionedEntity; |
27
|
|
|
use Sonata\DoctrineORMAdminBundle\Tests\Fixtures\Util\NonIntegerIdentifierTestClass; |
28
|
|
|
use Sonata\DoctrineORMAdminBundle\Tests\Helpers\PHPUnit_Framework_TestCase; |
29
|
|
|
|
30
|
|
|
class ModelManagerTest extends PHPUnit_Framework_TestCase |
31
|
|
|
{ |
32
|
|
|
public static function setUpBeforeClass() |
33
|
|
|
{ |
34
|
|
|
if (!Type::hasType('uuid')) { |
35
|
|
|
Type::addType('uuid', 'Sonata\DoctrineORMAdminBundle\Tests\Fixtures\DoctrineType\UuidType'); |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testSortParameters() |
40
|
|
|
{ |
41
|
|
|
$registry = $this->createMock('Symfony\Bridge\Doctrine\RegistryInterface'); |
42
|
|
|
|
43
|
|
|
$manager = new ModelManager($registry); |
44
|
|
|
|
45
|
|
|
$datagrid1 = $this->createMock('Sonata\AdminBundle\Datagrid\Datagrid'); |
46
|
|
|
$datagrid2 = $this->createMock('Sonata\AdminBundle\Datagrid\Datagrid'); |
47
|
|
|
|
48
|
|
|
$field1 = new FieldDescription(); |
49
|
|
|
$field1->setName('field1'); |
50
|
|
|
|
51
|
|
|
$field2 = new FieldDescription(); |
52
|
|
|
$field2->setName('field2'); |
53
|
|
|
|
54
|
|
|
$field3 = new FieldDescription(); |
55
|
|
|
$field3->setName('field3'); |
56
|
|
|
$field3->setOption('sortable', 'field3sortBy'); |
57
|
|
|
|
58
|
|
|
$datagrid1 |
59
|
|
|
->expects($this->any()) |
60
|
|
|
->method('getValues') |
61
|
|
|
->will($this->returnValue(array( |
62
|
|
|
'_sort_by' => $field1, |
63
|
|
|
'_sort_order' => 'ASC', |
64
|
|
|
))); |
65
|
|
|
|
66
|
|
|
$datagrid2 |
67
|
|
|
->expects($this->any()) |
68
|
|
|
->method('getValues') |
69
|
|
|
->will($this->returnValue(array( |
70
|
|
|
'_sort_by' => $field3, |
71
|
|
|
'_sort_order' => 'ASC', |
72
|
|
|
))); |
73
|
|
|
|
74
|
|
|
$parameters = $manager->getSortParameters($field1, $datagrid1); |
75
|
|
|
|
76
|
|
|
$this->assertEquals('DESC', $parameters['filter']['_sort_order']); |
77
|
|
|
$this->assertEquals('field1', $parameters['filter']['_sort_by']); |
78
|
|
|
|
79
|
|
|
$parameters = $manager->getSortParameters($field2, $datagrid1); |
80
|
|
|
|
81
|
|
|
$this->assertEquals('ASC', $parameters['filter']['_sort_order']); |
82
|
|
|
$this->assertEquals('field2', $parameters['filter']['_sort_by']); |
83
|
|
|
|
84
|
|
|
$parameters = $manager->getSortParameters($field3, $datagrid1); |
85
|
|
|
|
86
|
|
|
$this->assertEquals('ASC', $parameters['filter']['_sort_order']); |
87
|
|
|
$this->assertEquals('field3sortBy', $parameters['filter']['_sort_by']); |
88
|
|
|
|
89
|
|
|
$parameters = $manager->getSortParameters($field3, $datagrid2); |
90
|
|
|
|
91
|
|
|
$this->assertEquals('DESC', $parameters['filter']['_sort_order']); |
92
|
|
|
$this->assertEquals('field3sortBy', $parameters['filter']['_sort_by']); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function getVersionDataProvider() |
96
|
|
|
{ |
97
|
|
|
return array( |
98
|
|
|
array(true), |
99
|
|
|
array(false), |
100
|
|
|
); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @dataProvider getVersionDataProvider |
105
|
|
|
*/ |
106
|
|
|
public function testGetVersion($isVersioned) |
107
|
|
|
{ |
108
|
|
|
$object = new VersionedEntity(); |
109
|
|
|
|
110
|
|
|
$modelManager = $this->getMockBuilder('Sonata\DoctrineORMAdminBundle\Model\ModelManager') |
111
|
|
|
->disableOriginalConstructor() |
112
|
|
|
->setMethods(array('getMetadata')) |
113
|
|
|
->getMock(); |
114
|
|
|
|
115
|
|
|
$metadata = $this->getMetadata(get_class($object), $isVersioned); |
116
|
|
|
|
117
|
|
|
$modelManager->expects($this->any()) |
118
|
|
|
->method('getMetadata') |
119
|
|
|
->will($this->returnValue($metadata)); |
120
|
|
|
|
121
|
|
|
if ($isVersioned) { |
122
|
|
|
$object->version = 123; |
123
|
|
|
|
124
|
|
|
$this->assertNotNull($modelManager->getLockVersion($object)); |
125
|
|
|
} else { |
126
|
|
|
$this->assertNull($modelManager->getLockVersion($object)); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function lockDataProvider() |
131
|
|
|
{ |
132
|
|
|
return array( |
133
|
|
|
array(true, false), |
134
|
|
|
array(true, true), |
135
|
|
|
array(false, false), |
136
|
|
|
); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @dataProvider lockDataProvider |
141
|
|
|
*/ |
142
|
|
|
public function testLock($isVersioned, $expectsException) |
143
|
|
|
{ |
144
|
|
|
$object = new VersionedEntity(); |
145
|
|
|
|
146
|
|
|
$em = $this->getMockBuilder('Doctrine\ORM\EntityManager') |
147
|
|
|
->disableOriginalConstructor() |
148
|
|
|
->setMethods(array('lock')) |
149
|
|
|
->getMock(); |
150
|
|
|
|
151
|
|
|
$modelManager = $this->getMockBuilder('Sonata\DoctrineORMAdminBundle\Model\ModelManager') |
152
|
|
|
->disableOriginalConstructor() |
153
|
|
|
->setMethods(array('getMetadata', 'getEntityManager')) |
154
|
|
|
->getMock(); |
155
|
|
|
|
156
|
|
|
$modelManager->expects($this->any()) |
157
|
|
|
->method('getEntityManager') |
158
|
|
|
->will($this->returnValue($em)); |
159
|
|
|
|
160
|
|
|
$metadata = $this->getMetadata(get_class($object), $isVersioned); |
161
|
|
|
|
162
|
|
|
$modelManager->expects($this->any()) |
163
|
|
|
->method('getMetadata') |
164
|
|
|
->will($this->returnValue($metadata)); |
165
|
|
|
|
166
|
|
|
if ($expectsException) { |
167
|
|
|
$em->expects($this->once()) |
168
|
|
|
->method('lock') |
169
|
|
|
->will($this->throwException(OptimisticLockException::lockFailed($object))); |
170
|
|
|
|
171
|
|
|
$this->setExpectedException('Sonata\AdminBundle\Exception\LockException'); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
$modelManager->lock($object, 123); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
public function testGetParentMetadataForProperty() |
178
|
|
|
{ |
179
|
|
|
if (version_compare(Version::VERSION, '2.5') < 0) { |
180
|
|
|
$this->markTestSkipped('Test for embeddables needs to run on Doctrine >= 2.5'); |
181
|
|
|
|
182
|
|
|
return; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
$containerEntityClass = 'Sonata\DoctrineORMAdminBundle\Tests\Fixtures\Entity\ContainerEntity'; |
186
|
|
|
$associatedEntityClass = 'Sonata\DoctrineORMAdminBundle\Tests\Fixtures\Entity\AssociatedEntity'; |
187
|
|
|
$embeddedEntityClass = 'Sonata\DoctrineORMAdminBundle\Tests\Fixtures\Entity\Embeddable\EmbeddedEntity'; |
188
|
|
|
$modelManagerClass = 'Sonata\DoctrineORMAdminBundle\Model\ModelManager'; |
189
|
|
|
|
190
|
|
|
$object = new ContainerEntity(new AssociatedEntity(), new EmbeddedEntity()); |
|
|
|
|
191
|
|
|
|
192
|
|
|
$em = $this->createMock('Doctrine\ORM\EntityManager'); |
193
|
|
|
|
194
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject|ModelManager $modelManager */ |
195
|
|
|
$modelManager = $this->getMockBuilder($modelManagerClass) |
196
|
|
|
->disableOriginalConstructor() |
197
|
|
|
->setMethods(array('getMetadata', 'getEntityManager')) |
198
|
|
|
->getMock(); |
199
|
|
|
|
200
|
|
|
$modelManager->expects($this->any()) |
|
|
|
|
201
|
|
|
->method('getEntityManager') |
202
|
|
|
->will($this->returnValue($em)); |
203
|
|
|
|
204
|
|
|
$containerEntityMetadata = $this->getMetadataForContainerEntity(); |
205
|
|
|
$associatedEntityMetadata = $this->getMetadataForAssociatedEntity(); |
206
|
|
|
$embeddedEntityMetadata = $this->getMetadataForEmbeddedEntity(); |
207
|
|
|
|
208
|
|
|
$modelManager->expects($this->any())->method('getMetadata') |
|
|
|
|
209
|
|
|
->will( |
210
|
|
|
$this->returnValueMap( |
211
|
|
|
array( |
212
|
|
|
array($containerEntityClass, $containerEntityMetadata), |
213
|
|
|
array($embeddedEntityClass, $embeddedEntityMetadata), |
214
|
|
|
array($associatedEntityClass, $associatedEntityMetadata), |
215
|
|
|
) |
216
|
|
|
) |
217
|
|
|
); |
218
|
|
|
|
219
|
|
|
/** @var ClassMetadata $metadata */ |
220
|
|
|
list($metadata, $lastPropertyName) = $modelManager |
221
|
|
|
->getParentMetadataForProperty($containerEntityClass, 'plainField'); |
222
|
|
|
$this->assertEquals($metadata->fieldMappings[$lastPropertyName]['type'], 'integer'); |
223
|
|
|
|
224
|
|
|
list($metadata, $lastPropertyName) = $modelManager |
225
|
|
|
->getParentMetadataForProperty($containerEntityClass, 'associatedEntity.plainField'); |
226
|
|
|
$this->assertEquals($metadata->fieldMappings[$lastPropertyName]['type'], 'string'); |
227
|
|
|
|
228
|
|
|
list($metadata, $lastPropertyName) = $modelManager |
229
|
|
|
->getParentMetadataForProperty($containerEntityClass, 'embeddedEntity.plainField'); |
230
|
|
|
$this->assertEquals($metadata->fieldMappings[$lastPropertyName]['type'], 'boolean'); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
public function getMetadataForEmbeddedEntity() |
234
|
|
|
{ |
235
|
|
|
$metadata = new ClassMetadata('Sonata\DoctrineORMAdminBundle\Tests\Fixtures\Entity\Embeddable\EmbeddedEntity'); |
236
|
|
|
|
237
|
|
|
$metadata->fieldMappings = array( |
238
|
|
|
'plainField' => array( |
239
|
|
|
'fieldName' => 'plainField', |
240
|
|
|
'columnName' => 'plainField', |
241
|
|
|
'type' => 'boolean', |
242
|
|
|
), |
243
|
|
|
); |
244
|
|
|
|
245
|
|
|
return $metadata; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
public function getMetadataForAssociatedEntity() |
249
|
|
|
{ |
250
|
|
|
$metadata = new ClassMetadata('Sonata\DoctrineORMAdminBundle\Tests\Fixtures\Entity\AssociatedEntity'); |
251
|
|
|
|
252
|
|
|
$metadata->fieldMappings = array( |
253
|
|
|
'plainField' => array( |
254
|
|
|
'fieldName' => 'plainField', |
255
|
|
|
'columnName' => 'plainField', |
256
|
|
|
'type' => 'string', |
257
|
|
|
), |
258
|
|
|
); |
259
|
|
|
|
260
|
|
|
return $metadata; |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
public function getMetadataForContainerEntity() |
264
|
|
|
{ |
265
|
|
|
$containerEntityClass = 'Sonata\DoctrineORMAdminBundle\Tests\Fixtures\Entity\ContainerEntity'; |
266
|
|
|
$associatedEntityClass = 'Sonata\DoctrineORMAdminBundle\Tests\Fixtures\Entity\AssociatedEntity'; |
267
|
|
|
$embeddedEntityClass = 'Sonata\DoctrineORMAdminBundle\Tests\Fixtures\Entity\Embeddable\EmbeddedEntity'; |
268
|
|
|
|
269
|
|
|
$metadata = new ClassMetadata($containerEntityClass); |
270
|
|
|
|
271
|
|
|
$metadata->fieldMappings = array( |
272
|
|
|
'plainField' => array( |
273
|
|
|
'fieldName' => 'plainField', |
274
|
|
|
'columnName' => 'plainField', |
275
|
|
|
'type' => 'integer', |
276
|
|
|
), |
277
|
|
|
); |
278
|
|
|
|
279
|
|
|
$metadata->associationMappings['associatedEntity'] = array( |
280
|
|
|
'fieldName' => 'associatedEntity', |
281
|
|
|
'targetEntity' => $associatedEntityClass, |
282
|
|
|
'sourceEntity' => $containerEntityClass, |
283
|
|
|
); |
284
|
|
|
|
285
|
|
|
$metadata->embeddedClasses['embeddedEntity'] = array( |
286
|
|
|
'class' => $embeddedEntityClass, |
287
|
|
|
'columnPrefix' => 'embeddedEntity', |
288
|
|
|
); |
289
|
|
|
|
290
|
|
|
$metadata->inlineEmbeddable('embeddedEntity', $this->getMetadataForEmbeddedEntity()); |
291
|
|
|
|
292
|
|
|
return $metadata; |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
public function testNonIntegerIdentifierType() |
296
|
|
|
{ |
297
|
|
|
$uuid = new NonIntegerIdentifierTestClass('efbcfc4b-8c43-4d42-aa4c-d707e55151ac'); |
298
|
|
|
$entity = new UuidEntity($uuid); |
299
|
|
|
|
300
|
|
|
$meta = $this->createMock('Doctrine\ORM\Mapping\ClassMetadataInfo'); |
301
|
|
|
$meta->expects($this->any()) |
302
|
|
|
->method('getIdentifierValues') |
303
|
|
|
->willReturn(array($entity->getId())); |
304
|
|
|
$meta->expects($this->any()) |
305
|
|
|
->method('getTypeOfField') |
306
|
|
|
->willReturn(UuidType::NAME); |
307
|
|
|
|
308
|
|
|
$mf = $this->createMock('Doctrine\ORM\Mapping\ClassMetadataFactory'); |
309
|
|
|
$mf->expects($this->any()) |
310
|
|
|
->method('getMetadataFor') |
311
|
|
|
->willReturn($meta); |
312
|
|
|
|
313
|
|
|
$platform = $this->createMock('Doctrine\DBAL\Platforms\PostgreSqlPlatform'); |
314
|
|
|
|
315
|
|
|
$conn = $this->createMock('Doctrine\DBAL\Connection'); |
316
|
|
|
$conn->expects($this->any()) |
317
|
|
|
->method('getDatabasePlatform') |
318
|
|
|
->willReturn($platform); |
319
|
|
|
|
320
|
|
|
$em = $this->createMock('Doctrine\ORM\EntityManager'); |
321
|
|
|
$em->expects($this->any()) |
322
|
|
|
->method('getMetadataFactory') |
323
|
|
|
->willReturn($mf); |
324
|
|
|
$em->expects($this->any()) |
325
|
|
|
->method('getConnection') |
326
|
|
|
->willReturn($conn); |
327
|
|
|
|
328
|
|
|
$registry = $this->createMock('Symfony\Bridge\Doctrine\RegistryInterface'); |
329
|
|
|
$registry->expects($this->any()) |
330
|
|
|
->method('getManagerForClass') |
331
|
|
|
->willReturn($em); |
332
|
|
|
|
333
|
|
|
$manager = new ModelManager($registry); |
334
|
|
|
$result = $manager->getIdentifierValues($entity); |
335
|
|
|
|
336
|
|
|
$this->assertEquals($entity->getId()->toString(), $result[0]); |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
public function testAssociationIdentifierType() |
340
|
|
|
{ |
341
|
|
|
$entity = new ContainerEntity(new AssociatedEntity(42), new EmbeddedEntity()); |
342
|
|
|
|
343
|
|
|
$meta = $this->createMock('Doctrine\ORM\Mapping\ClassMetadataInfo'); |
344
|
|
|
$meta->expects($this->any()) |
345
|
|
|
->method('getIdentifierValues') |
346
|
|
|
->willReturn(array($entity->getAssociatedEntity()->getPlainField())); |
347
|
|
|
$meta->expects($this->any()) |
348
|
|
|
->method('getTypeOfField') |
349
|
|
|
->willReturn(null); |
350
|
|
|
|
351
|
|
|
$mf = $this->createMock('Doctrine\ORM\Mapping\ClassMetadataFactory'); |
352
|
|
|
$mf->expects($this->any()) |
353
|
|
|
->method('getMetadataFor') |
354
|
|
|
->willReturn($meta); |
355
|
|
|
|
356
|
|
|
$platform = $this->createMock('Doctrine\DBAL\Platforms\PostgreSqlPlatform'); |
357
|
|
|
|
358
|
|
|
$conn = $this->createMock('Doctrine\DBAL\Connection'); |
359
|
|
|
$conn->expects($this->any()) |
360
|
|
|
->method('getDatabasePlatform') |
361
|
|
|
->willReturn($platform); |
362
|
|
|
|
363
|
|
|
$em = $this->createMock('Doctrine\ORM\EntityManager'); |
364
|
|
|
$em->expects($this->any()) |
365
|
|
|
->method('getMetadataFactory') |
366
|
|
|
->willReturn($mf); |
367
|
|
|
$em->expects($this->any()) |
368
|
|
|
->method('getConnection') |
369
|
|
|
->willReturn($conn); |
370
|
|
|
|
371
|
|
|
$registry = $this->createMock('Symfony\Bridge\Doctrine\RegistryInterface'); |
372
|
|
|
$registry->expects($this->any()) |
373
|
|
|
->method('getManagerForClass') |
374
|
|
|
->willReturn($em); |
375
|
|
|
|
376
|
|
|
$manager = new ModelManager($registry); |
377
|
|
|
$result = $manager->getIdentifierValues($entity); |
378
|
|
|
|
379
|
|
|
$this->assertSame(42, $result[0]); |
380
|
|
|
} |
381
|
|
|
|
382
|
|
|
/** |
383
|
|
|
* [sortBy, sortOrder, isAddOrderBy]. |
384
|
|
|
* |
385
|
|
|
* @return array |
386
|
|
|
*/ |
387
|
|
|
public function getSortableInDataSourceIteratorDataProvider() |
388
|
|
|
{ |
389
|
|
|
return array( |
390
|
|
|
array(null, null, false), |
391
|
|
|
array('', 'ASC', false), |
392
|
|
|
array('field', 'ASC', true), |
393
|
|
|
array('field', null, true), |
394
|
|
|
); |
395
|
|
|
} |
396
|
|
|
|
397
|
|
|
/** |
398
|
|
|
* @dataProvider getSortableInDataSourceIteratorDataProvider |
399
|
|
|
* |
400
|
|
|
* @param string|null $sortBy |
401
|
|
|
* @param string|null $sortOrder |
402
|
|
|
* @param bool $isAddOrderBy |
403
|
|
|
*/ |
404
|
|
|
public function testSortableInDataSourceIterator($sortBy, $sortOrder, $isAddOrderBy) |
405
|
|
|
{ |
406
|
|
|
$datagrid = $this->getMockForAbstractClass('Sonata\AdminBundle\Datagrid\DatagridInterface'); |
407
|
|
|
$configuration = $this->getMockBuilder('Doctrine\ORM\Configuration')->getMock(); |
408
|
|
|
$configuration->expects($this->any()) |
409
|
|
|
->method('getDefaultQueryHints') |
410
|
|
|
->willReturn(array()); |
411
|
|
|
|
412
|
|
|
$em = $this->getMockBuilder('Doctrine\ORM\EntityManager') |
413
|
|
|
->disableOriginalConstructor() |
414
|
|
|
->getMock(); |
415
|
|
|
|
416
|
|
|
$em->expects($this->any()) |
417
|
|
|
->method('getConfiguration') |
418
|
|
|
->willReturn($configuration); |
419
|
|
|
|
420
|
|
|
$queryBuilder = $this->getMockBuilder('Doctrine\ORM\QueryBuilder') |
421
|
|
|
->setConstructorArgs(array($em)) |
422
|
|
|
->getMock(); |
423
|
|
|
$query = new Query($em); |
424
|
|
|
|
425
|
|
|
$proxyQuery = $this->getMockBuilder('Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery') |
426
|
|
|
->setConstructorArgs(array($queryBuilder)) |
427
|
|
|
->setMethods(array('getSortBy', 'getSortOrder')) |
428
|
|
|
->getMock(); |
429
|
|
|
|
430
|
|
|
$proxyQuery->expects($this->any()) |
431
|
|
|
->method('getSortOrder') |
432
|
|
|
->willReturn($sortOrder); |
433
|
|
|
|
434
|
|
|
$proxyQuery->expects($this->any()) |
435
|
|
|
->method('getSortBy') |
436
|
|
|
->willReturn($sortBy); |
437
|
|
|
|
438
|
|
|
$queryBuilder->expects($isAddOrderBy ? $this->atLeastOnce() : $this->never()) |
439
|
|
|
->method('addOrderBy'); |
440
|
|
|
|
441
|
|
|
$queryBuilder->expects($this->any()) |
442
|
|
|
->method('getQuery') |
443
|
|
|
->willReturn($query); |
444
|
|
|
|
445
|
|
|
$datagrid->expects($this->any()) |
446
|
|
|
->method('getQuery') |
447
|
|
|
->willReturn($proxyQuery); |
448
|
|
|
|
449
|
|
|
$registry = $this->getMockBuilder('Symfony\Bridge\Doctrine\RegistryInterface')->getMock(); |
450
|
|
|
$manager = new ModelManager($registry); |
451
|
|
|
$manager->getDataSourceIterator($datagrid, array()); |
452
|
|
|
} |
453
|
|
|
|
454
|
|
|
private function getMetadata($class, $isVersioned) |
455
|
|
|
{ |
456
|
|
|
$metadata = new ClassMetadata($class); |
457
|
|
|
|
458
|
|
|
$metadata->isVersioned = $isVersioned; |
459
|
|
|
|
460
|
|
|
if ($isVersioned) { |
461
|
|
|
$versionField = 'version'; |
462
|
|
|
$metadata->versionField = $versionField; |
463
|
|
|
$metadata->reflFields[$versionField] = new \ReflectionProperty($class, $versionField); |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
return $metadata; |
467
|
|
|
} |
468
|
|
|
} |
469
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.