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