1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Lug package. |
5
|
|
|
* |
6
|
|
|
* (c) Eric GELOEN <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please read the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Lug\Bundle\ResourceBundle\Tests\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Doctrine\ODM\MongoDB\DocumentManager; |
15
|
|
|
use Hateoas\Representation\Factory\PagerfantaFactory; |
16
|
|
|
use Lug\Bundle\GridBundle\Handler\GridHandlerInterface; |
17
|
|
|
use Lug\Bundle\ResourceBundle\DependencyInjection\Configurator\ResolveTargetSubscriberConfigurator; |
18
|
|
|
use Lug\Bundle\ResourceBundle\DependencyInjection\LugResourceExtension; |
19
|
|
|
use Lug\Bundle\ResourceBundle\EventListener\FlashListener; |
20
|
|
|
use Lug\Bundle\ResourceBundle\EventListener\MessageListener; |
21
|
|
|
use Lug\Bundle\ResourceBundle\EventSubscriber\Doctrine\MongoDB\ResourceSubscriber as DoctrineMongoDBResourceSubscriber; |
22
|
|
|
use Lug\Bundle\ResourceBundle\EventSubscriber\Doctrine\ORM\ResourceSubscriber as DoctrineORMResourceSubscriber; |
23
|
|
|
use Lug\Bundle\ResourceBundle\EventSubscriber\RoutingSubscriber; |
24
|
|
|
use Lug\Bundle\ResourceBundle\Form\DataTransformer\BooleanTransformer; |
25
|
|
|
use Lug\Bundle\ResourceBundle\Form\EventSubscriber\CollectionSubscriber; |
26
|
|
|
use Lug\Bundle\ResourceBundle\Form\EventSubscriber\FlashCsrfProtectionSubscriber; |
27
|
|
|
use Lug\Bundle\ResourceBundle\Form\EventSubscriber\XmlHttpRequestSubscriber; |
28
|
|
|
use Lug\Bundle\ResourceBundle\Form\Extension\BooleanExtension; |
29
|
|
|
use Lug\Bundle\ResourceBundle\Form\Extension\CollectionExtension; |
30
|
|
|
use Lug\Bundle\ResourceBundle\Form\Extension\DateExtension; |
31
|
|
|
use Lug\Bundle\ResourceBundle\Form\Extension\DateTimeExtension; |
32
|
|
|
use Lug\Bundle\ResourceBundle\Form\Extension\LabelButtonExtension; |
33
|
|
|
use Lug\Bundle\ResourceBundle\Form\Extension\LabelFormExtension; |
34
|
|
|
use Lug\Bundle\ResourceBundle\Form\Extension\TimeExtension; |
35
|
|
|
use Lug\Bundle\ResourceBundle\Form\Extension\XmlHttpRequestExtension; |
36
|
|
|
use Lug\Bundle\ResourceBundle\Form\FormFactory; |
37
|
|
|
use Lug\Bundle\ResourceBundle\Form\Type\CsrfProtectionType; |
38
|
|
|
use Lug\Bundle\ResourceBundle\Rest\Action\EventSubscriber\ApiActionSubscriber; |
39
|
|
|
use Lug\Bundle\ResourceBundle\Rest\Action\EventSubscriber\ViewActionSubscriber; |
40
|
|
|
use Lug\Bundle\ResourceBundle\Rest\View\EventSubscriber\FormViewSubscriber; |
41
|
|
|
use Lug\Bundle\ResourceBundle\Rest\View\EventSubscriber\GridViewSubscriber; |
42
|
|
|
use Lug\Bundle\ResourceBundle\Rest\View\EventSubscriber\PagerfantaViewSubscriber; |
43
|
|
|
use Lug\Bundle\ResourceBundle\Rest\View\EventSubscriber\ResourceViewSubscriber; |
44
|
|
|
use Lug\Bundle\ResourceBundle\Routing\CachedParameterResolver; |
45
|
|
|
use Lug\Bundle\ResourceBundle\Routing\ParameterResolver; |
46
|
|
|
use Lug\Bundle\ResourceBundle\Security\SecurityChecker; |
47
|
|
|
use Lug\Component\Resource\Form\Type\Doctrine\MongoDB\ResourceChoiceType as DoctrineMongoDBResourceChoiceType; |
48
|
|
|
use Lug\Component\Resource\Form\Type\Doctrine\ORM\ResourceChoiceType as DoctrineORMResourceChoiceType; |
49
|
|
|
use Lug\Component\Resource\Form\Type\ResourceType; |
50
|
|
|
use Lug\Component\Resource\Registry\DomainManagerRegistry; |
51
|
|
|
use Lug\Component\Resource\Registry\FactoryRegistry; |
52
|
|
|
use Lug\Component\Resource\Registry\ManagerRegistry; |
53
|
|
|
use Lug\Component\Resource\Registry\RepositoryRegistry; |
54
|
|
|
use Lug\Component\Resource\Registry\ResourceRegistry; |
55
|
|
|
use Lug\Component\Resource\Repository\Doctrine\MongoDB\RepositoryFactory as DoctrineMongoDBRepositoryFactory; |
56
|
|
|
use Lug\Component\Resource\Repository\Doctrine\ORM\RepositoryFactory as DoctrineORMRepositoryFactory; |
57
|
|
|
use Symfony\Bridge\Doctrine\RegistryInterface; |
58
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
59
|
|
|
use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher; |
60
|
|
|
use Symfony\Component\Form\FormFactoryInterface; |
61
|
|
|
use Symfony\Component\Form\FormRendererInterface; |
62
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
63
|
|
|
use Symfony\Component\HttpFoundation\Session\Session; |
64
|
|
|
use Symfony\Component\PropertyAccess\PropertyAccessorInterface; |
65
|
|
|
use Symfony\Component\Routing\RouterInterface; |
66
|
|
|
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; |
67
|
|
|
use Symfony\Component\Translation\TranslatorInterface; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @author GeLo <[email protected]> |
71
|
|
|
*/ |
72
|
|
|
abstract class AbstractLugResourceExtensionTest extends \PHPUnit_Framework_TestCase |
73
|
|
|
{ |
74
|
|
|
/** |
75
|
|
|
* @var LugResourceExtension |
76
|
|
|
*/ |
77
|
|
|
private $extension; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @var ContainerBuilder |
81
|
|
|
*/ |
82
|
|
|
private $container; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject|AuthorizationCheckerInterface |
86
|
|
|
*/ |
87
|
|
|
private $authorizationChecker; |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject|TranslatorInterface |
91
|
|
|
*/ |
92
|
|
|
private $translator; |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject|PropertyAccessorInterface |
96
|
|
|
*/ |
97
|
|
|
private $propertyAccessor; |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject|Session |
101
|
|
|
*/ |
102
|
|
|
private $session; |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject|FormFactoryInterface |
106
|
|
|
*/ |
107
|
|
|
private $formFactory; |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject|FormRendererInterface |
111
|
|
|
*/ |
112
|
|
|
private $formRenderer; |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject|RegistryInterface |
116
|
|
|
*/ |
117
|
|
|
private $registry; |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject|RouterInterface |
121
|
|
|
*/ |
122
|
|
|
private $router; |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject|RequestStack |
126
|
|
|
*/ |
127
|
|
|
private $requestStack; |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject|GridHandlerInterface |
131
|
|
|
*/ |
132
|
|
|
private $gridHandler; |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* {@inheritdoc} |
136
|
|
|
*/ |
137
|
|
|
protected function setUp() |
138
|
|
|
{ |
139
|
|
|
$this->authorizationChecker = $this->createAuthorizationCheckerMock(); |
140
|
|
|
$this->translator = $this->createTranslatorMock(); |
141
|
|
|
$this->propertyAccessor = $this->createPropertyAccessorMock(); |
142
|
|
|
$this->session = $this->createSessionMock(); |
143
|
|
|
$this->formFactory = $this->createFormFactoryMock(); |
144
|
|
|
$this->formRenderer = $this->createFormRendererMock(); |
145
|
|
|
$this->registry = $this->createRegistryMock(); |
146
|
|
|
$this->router = $this->createRouterMock(); |
147
|
|
|
$this->requestStack = $this->createRequestStackMock(); |
148
|
|
|
$this->gridHandler = $this->createGridHandler(); |
|
|
|
|
149
|
|
|
|
150
|
|
|
$this->extension = new LugResourceExtension(); |
151
|
|
|
$this->container = new ContainerBuilder(); |
152
|
|
|
|
153
|
|
|
$this->container->set('security.authorization_checker', $this->authorizationChecker); |
154
|
|
|
$this->container->set('translator', $this->translator); |
155
|
|
|
$this->container->set('property_accessor', $this->propertyAccessor); |
156
|
|
|
$this->container->set('session', $this->session); |
157
|
|
|
$this->container->set('form.factory', $this->formFactory); |
158
|
|
|
$this->container->set('twig.form.renderer', $this->formRenderer); |
159
|
|
|
$this->container->set('doctrine', $this->registry); |
160
|
|
|
$this->container->set('router', $this->router); |
161
|
|
|
$this->container->set('request_stack', $this->requestStack); |
162
|
|
|
$this->container->set('lug.grid.handler', $this->gridHandler); |
163
|
|
|
|
164
|
|
|
$this->container->registerExtension($this->extension); |
165
|
|
|
$this->container->loadFromExtension($this->extension->getAlias()); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
public function testConfigurator() |
169
|
|
|
{ |
170
|
|
|
$this->compileContainer(); |
171
|
|
|
|
172
|
|
|
$this->assertInstanceOf( |
173
|
|
|
ResolveTargetSubscriberConfigurator::class, |
174
|
|
|
$this->container->get('lug.resource.configurator.resolve_target_entity') |
175
|
|
|
); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
public function testDomain() |
179
|
|
|
{ |
180
|
|
|
$this->compileContainer(); |
181
|
|
|
|
182
|
|
|
$this->assertInstanceOf( |
183
|
|
|
ContainerAwareEventDispatcher::class, |
184
|
|
|
$this->container->get('lug.resource.domain.event_dispatcher') |
185
|
|
|
); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
public function testEventListener() |
189
|
|
|
{ |
190
|
|
|
$this->compileContainer(); |
191
|
|
|
|
192
|
|
|
$this->assertInstanceOf(FlashListener::class, $this->container->get('lug.resource.listener.flash')); |
193
|
|
|
$this->assertInstanceOf(MessageListener::class, $this->container->get('lug.resource.listener.message')); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
public function testEventSubscriber() |
197
|
|
|
{ |
198
|
|
|
$this->compileContainer(); |
199
|
|
|
|
200
|
|
|
$this->assertInstanceOf( |
201
|
|
|
DoctrineORMResourceSubscriber::class, |
202
|
|
|
$this->container->get('lug.resource.subscriber.doctrine.orm') |
203
|
|
|
); |
204
|
|
|
|
205
|
|
|
if (class_exists(DocumentManager::class)) { |
206
|
|
|
$this->assertInstanceOf( |
207
|
|
|
DoctrineMongoDBResourceSubscriber::class, |
208
|
|
|
$this->container->get('lug.resource.subscriber.doctrine.mongodb') |
209
|
|
|
); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
$this->assertInstanceOf(RoutingSubscriber::class, $this->container->get('lug.resource.subscriber.routing')); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
public function testForm() |
216
|
|
|
{ |
217
|
|
|
$this->compileContainer(); |
218
|
|
|
|
219
|
|
|
$this->assertInstanceOf(FormFactory::class, $this->container->get('lug.resource.form.factory')); |
220
|
|
|
|
221
|
|
|
$resourceType = 'lug.resource.form.type.resource'; |
222
|
|
|
$this->assertTrue($this->container->getDefinition($resourceType)->hasTag('form.type')); |
223
|
|
|
$this->assertInstanceOf(ResourceType::class, $this->container->get($resourceType)); |
224
|
|
|
|
225
|
|
|
$doctrineOrmResourceChoiceType = 'lug.resource.form.type.doctrine.orm.resource.choice'; |
226
|
|
|
$this->assertTrue($this->container->getDefinition($doctrineOrmResourceChoiceType)->hasTag('form.type')); |
227
|
|
|
|
228
|
|
|
$this->assertInstanceOf( |
229
|
|
|
DoctrineORMResourceChoiceType::class, |
230
|
|
|
$this->container->get($doctrineOrmResourceChoiceType) |
231
|
|
|
); |
232
|
|
|
|
233
|
|
|
if (class_exists(DocumentManager::class)) { |
234
|
|
|
$doctrineMongoDbResourceChoiceType = 'lug.resource.form.type.doctrine.mongodb.resource.choice'; |
235
|
|
|
$this->assertTrue($this->container->getDefinition($doctrineMongoDbResourceChoiceType)->hasTag('form.type')); |
236
|
|
|
|
237
|
|
|
$this->assertInstanceOf( |
238
|
|
|
DoctrineMongoDBResourceChoiceType::class, |
239
|
|
|
$this->container->get($doctrineMongoDbResourceChoiceType) |
240
|
|
|
); |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
$flashCsrfProtectionSubscriber = 'lug.resource.form.subscriber.flash_csrf_protection'; |
244
|
|
|
|
245
|
|
|
$this->assertInstanceOf( |
246
|
|
|
FlashCsrfProtectionSubscriber::class, |
247
|
|
|
$this->container->get($flashCsrfProtectionSubscriber) |
248
|
|
|
); |
249
|
|
|
|
250
|
|
|
$csrfProtectionType = 'lug.resource.form.type.csrf_protection'; |
251
|
|
|
$this->assertTrue($this->container->getDefinition($csrfProtectionType)->hasTag('form.type')); |
252
|
|
|
$this->assertInstanceOf(CsrfProtectionType::class, $this->container->get($csrfProtectionType)); |
253
|
|
|
|
254
|
|
|
$booleanTransformer = 'lug.resource.form.transformer.boolean'; |
255
|
|
|
$this->assertInstanceOf(BooleanTransformer::class, $this->container->get($booleanTransformer)); |
256
|
|
|
|
257
|
|
|
$booleanExtension = 'lug.resource.form.extension.boolean'; |
258
|
|
|
$this->assertTrue($this->container->getDefinition($booleanExtension)->hasTag('form.type_extension')); |
259
|
|
|
$this->assertInstanceOf(BooleanExtension::class, $this->container->get($booleanExtension)); |
260
|
|
|
|
261
|
|
|
$collectionSubscriber = 'lug.resource.form.subscriber.collection'; |
262
|
|
|
$this->assertInstanceOf(CollectionSubscriber::class, $this->container->get($collectionSubscriber)); |
263
|
|
|
|
264
|
|
|
$collectionExtension = 'lug.resource.form.extension.collection'; |
265
|
|
|
$this->assertTrue($this->container->getDefinition($collectionExtension)->hasTag('form.type_extension')); |
266
|
|
|
$this->assertInstanceOf(CollectionExtension::class, $this->container->get($collectionExtension)); |
267
|
|
|
|
268
|
|
|
$labelFormExtension = 'lug.resource.form.extension.label_form'; |
269
|
|
|
$this->assertTrue($this->container->getDefinition($labelFormExtension)->hasTag('form.type_extension')); |
270
|
|
|
$this->assertInstanceOf(LabelFormExtension::class, $this->container->get($labelFormExtension)); |
271
|
|
|
|
272
|
|
|
$buttonFormExtension = 'lug.resource.form.extension.label_button'; |
273
|
|
|
$this->assertTrue($this->container->getDefinition($buttonFormExtension)->hasTag('form.type_extension')); |
274
|
|
|
$this->assertInstanceOf(LabelButtonExtension::class, $this->container->get($buttonFormExtension)); |
275
|
|
|
|
276
|
|
|
$datetimeExtension = 'lug.resource.form.extension.datetime'; |
277
|
|
|
$this->assertTrue($this->container->getDefinition($datetimeExtension)->hasTag('form.type_extension')); |
278
|
|
|
$this->assertInstanceOf(DateTimeExtension::class, $this->container->get($datetimeExtension)); |
279
|
|
|
|
280
|
|
|
$dateExtension = 'lug.resource.form.extension.date'; |
281
|
|
|
$this->assertTrue($this->container->getDefinition($dateExtension)->hasTag('form.type_extension')); |
282
|
|
|
$this->assertInstanceOf(DateExtension::class, $this->container->get($dateExtension)); |
283
|
|
|
|
284
|
|
|
$timeExtension = 'lug.resource.form.extension.time'; |
285
|
|
|
$this->assertTrue($this->container->getDefinition($timeExtension)->hasTag('form.type_extension')); |
286
|
|
|
$this->assertInstanceOf(TimeExtension::class, $this->container->get($timeExtension)); |
287
|
|
|
|
288
|
|
|
$xmlHttpRequestSubscriber = 'lug.resource.form.subscriber.xml_http_request'; |
289
|
|
|
$this->assertInstanceOf(XmlHttpRequestSubscriber::class, $this->container->get($xmlHttpRequestSubscriber)); |
290
|
|
|
|
291
|
|
|
$xmlHttpRequestExtension = 'lug.resource.form.extension.xml_http_request'; |
292
|
|
|
$this->assertTrue($this->container->getDefinition($xmlHttpRequestExtension)->hasTag('form.type_extension')); |
293
|
|
|
$this->assertInstanceOf(XmlHttpRequestExtension::class, $this->container->get($xmlHttpRequestExtension)); |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
public function testHateoas() |
297
|
|
|
{ |
298
|
|
|
$this->compileContainer(); |
299
|
|
|
|
300
|
|
|
$this->assertInstanceOf( |
301
|
|
|
PagerfantaFactory::class, |
302
|
|
|
$this->container->get('lug.resource.hateoas.pagerfanta_representation') |
303
|
|
|
); |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
public function testRegistry() |
307
|
|
|
{ |
308
|
|
|
$this->compileContainer(); |
309
|
|
|
|
310
|
|
|
$resourceRegistry = 'lug.resource.registry'; |
311
|
|
|
$this->assertTrue($this->container->getDefinition($resourceRegistry)->hasTag('lug.registry')); |
312
|
|
|
$this->assertInstanceOf(ResourceRegistry::class, $this->container->get($resourceRegistry)); |
313
|
|
|
|
314
|
|
|
$factoryRegistry = 'lug.resource.registry.factory'; |
315
|
|
|
$this->assertTrue($this->container->getDefinition($factoryRegistry)->hasTag('lug.registry')); |
316
|
|
|
$this->assertInstanceOf(FactoryRegistry::class, $this->container->get($factoryRegistry)); |
317
|
|
|
|
318
|
|
|
$managerRegistry = 'lug.resource.registry.manager'; |
319
|
|
|
$this->assertTrue($this->container->getDefinition($managerRegistry)->hasTag('lug.registry')); |
320
|
|
|
$this->assertInstanceOf(ManagerRegistry::class, $this->container->get($managerRegistry)); |
321
|
|
|
|
322
|
|
|
$repositoryRegistry = 'lug.resource.registry.repository'; |
323
|
|
|
$this->assertTrue($this->container->getDefinition($repositoryRegistry)->hasTag('lug.registry')); |
324
|
|
|
$this->assertInstanceOf(RepositoryRegistry::class, $this->container->get($repositoryRegistry)); |
325
|
|
|
|
326
|
|
|
$domainManagerRegistry = 'lug.resource.registry.domain_manager'; |
327
|
|
|
$this->assertTrue($this->container->getDefinition($domainManagerRegistry)->hasTag('lug.registry')); |
328
|
|
|
$this->assertInstanceOf(DomainManagerRegistry::class, $this->container->get($domainManagerRegistry)); |
329
|
|
|
} |
330
|
|
|
|
331
|
|
View Code Duplication |
public function testRepository() |
|
|
|
|
332
|
|
|
{ |
333
|
|
|
$this->compileContainer(); |
334
|
|
|
|
335
|
|
|
$this->assertInstanceOf( |
336
|
|
|
DoctrineORMRepositoryFactory::class, |
337
|
|
|
$this->container->get('lug.resource.repository.doctrine.orm.factory') |
338
|
|
|
); |
339
|
|
|
|
340
|
|
|
if (class_exists(DocumentManager::class)) { |
341
|
|
|
$this->assertInstanceOf( |
342
|
|
|
DoctrineMongoDBRepositoryFactory::class, |
343
|
|
|
$this->container->get('lug.resource.repository.doctrine.mongodb.factory') |
344
|
|
|
); |
345
|
|
|
} |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
public function testRest() |
349
|
|
|
{ |
350
|
|
|
$this->compileContainer(); |
351
|
|
|
|
352
|
|
|
$this->assertInstanceOf( |
353
|
|
|
ContainerAwareEventDispatcher::class, |
354
|
|
|
$this->container->get('lug.resource.rest.event_dispatcher') |
355
|
|
|
); |
356
|
|
|
|
357
|
|
|
$tag = 'lug.resource.rest.event_subscriber'; |
358
|
|
|
|
359
|
|
|
$viewActionSubscriber = 'lug.resource.rest.action.subscriber.view'; |
360
|
|
|
$this->assertTrue($this->container->getDefinition($viewActionSubscriber)->hasTag($tag)); |
361
|
|
|
$this->assertInstanceOf(ViewActionSubscriber::class, $this->container->get($viewActionSubscriber)); |
362
|
|
|
|
363
|
|
|
$apiActionSubscriber = 'lug.resource.rest.action.subscriber.api'; |
364
|
|
|
$this->assertTrue($this->container->getDefinition($apiActionSubscriber)->hasTag($tag)); |
365
|
|
|
$this->assertInstanceOf(ApiActionSubscriber::class, $this->container->get($apiActionSubscriber)); |
366
|
|
|
|
367
|
|
|
$formViewSubscriber = 'lug.resource.rest.view.subscriber.form'; |
368
|
|
|
$this->assertTrue($this->container->getDefinition($formViewSubscriber)->hasTag($tag)); |
369
|
|
|
$this->assertInstanceOf(FormViewSubscriber::class, $this->container->get($formViewSubscriber)); |
370
|
|
|
|
371
|
|
|
$gridViewSubscriber = 'lug.resource.rest.view.subscriber.grid'; |
372
|
|
|
$this->assertTrue($this->container->getDefinition($gridViewSubscriber)->hasTag($tag)); |
373
|
|
|
$this->assertInstanceOf(GridViewSubscriber::class, $this->container->get($gridViewSubscriber)); |
374
|
|
|
|
375
|
|
|
$pagerfantaViewSubscriber = 'lug.resource.rest.view.subscriber.pagerfanta'; |
376
|
|
|
$this->assertTrue($this->container->getDefinition($pagerfantaViewSubscriber)->hasTag($tag)); |
377
|
|
|
$this->assertInstanceOf(PagerfantaViewSubscriber::class, $this->container->get($pagerfantaViewSubscriber)); |
378
|
|
|
|
379
|
|
|
$resourceViewSubscriber = 'lug.resource.rest.view.subscriber.resource'; |
380
|
|
|
$this->assertTrue($this->container->getDefinition($resourceViewSubscriber)->hasTag($tag)); |
381
|
|
|
$this->assertInstanceOf(ResourceViewSubscriber::class, $this->container->get($resourceViewSubscriber)); |
382
|
|
|
} |
383
|
|
|
|
384
|
|
|
public function testRouting() |
385
|
|
|
{ |
386
|
|
|
$this->compileContainer(); |
387
|
|
|
|
388
|
|
|
$this->assertInstanceOf( |
389
|
|
|
ParameterResolver::class, |
390
|
|
|
$this->container->get('lug.resource.routing.parameter_resolver.internal') |
391
|
|
|
); |
392
|
|
|
|
393
|
|
|
$this->assertInstanceOf( |
394
|
|
|
CachedParameterResolver::class, |
395
|
|
|
$this->container->get('lug.resource.routing.parameter_resolver') |
396
|
|
|
); |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
public function testSecurity() |
400
|
|
|
{ |
401
|
|
|
$this->compileContainer(); |
402
|
|
|
|
403
|
|
|
$this->assertInstanceOf(SecurityChecker::class, $this->container->get('lug.resource.security.checker')); |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
/** |
407
|
|
|
* @param ContainerBuilder $container |
408
|
|
|
* @param string $configuration |
409
|
|
|
*/ |
410
|
|
|
abstract protected function loadConfiguration(ContainerBuilder $container, $configuration); |
411
|
|
|
|
412
|
|
|
/** |
413
|
|
|
* @param string|null $configuration |
414
|
|
|
*/ |
415
|
|
|
private function compileContainer($configuration = null) |
416
|
|
|
{ |
417
|
|
|
if ($configuration !== null) { |
418
|
|
|
$this->loadConfiguration($this->container, $configuration); |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
$this->container->compile(); |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
/** |
425
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|AuthorizationCheckerInterface |
426
|
|
|
*/ |
427
|
|
|
private function createAuthorizationCheckerMock() |
428
|
|
|
{ |
429
|
|
|
return $this->getMock(AuthorizationCheckerInterface::class); |
|
|
|
|
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
/** |
433
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|TranslatorInterface |
434
|
|
|
*/ |
435
|
|
|
private function createTranslatorMock() |
436
|
|
|
{ |
437
|
|
|
return $this->getMock(TranslatorInterface::class); |
|
|
|
|
438
|
|
|
} |
439
|
|
|
|
440
|
|
|
/** |
441
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|PropertyAccessorInterface |
442
|
|
|
*/ |
443
|
|
|
private function createPropertyAccessorMock() |
444
|
|
|
{ |
445
|
|
|
return $this->getMock(PropertyAccessorInterface::class); |
|
|
|
|
446
|
|
|
} |
447
|
|
|
|
448
|
|
|
/** |
449
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|Session |
450
|
|
|
*/ |
451
|
|
|
private function createSessionMock() |
452
|
|
|
{ |
453
|
|
|
return $this->getMock(Session::class); |
|
|
|
|
454
|
|
|
} |
455
|
|
|
|
456
|
|
|
/** |
457
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|FormFactoryInterface |
458
|
|
|
*/ |
459
|
|
|
private function createFormFactoryMock() |
460
|
|
|
{ |
461
|
|
|
return $this->getMock(FormFactoryInterface::class); |
|
|
|
|
462
|
|
|
} |
463
|
|
|
|
464
|
|
|
/** |
465
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|FormRendererInterface |
466
|
|
|
*/ |
467
|
|
|
private function createFormRendererMock() |
468
|
|
|
{ |
469
|
|
|
return $this->getMock(FormRendererInterface::class); |
|
|
|
|
470
|
|
|
} |
471
|
|
|
|
472
|
|
|
/** |
473
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|RegistryInterface |
474
|
|
|
*/ |
475
|
|
|
private function createRegistryMock() |
476
|
|
|
{ |
477
|
|
|
return $this->getMock(RegistryInterface::class); |
|
|
|
|
478
|
|
|
} |
479
|
|
|
|
480
|
|
|
/** |
481
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|RouterInterface |
482
|
|
|
*/ |
483
|
|
|
private function createRouterMock() |
484
|
|
|
{ |
485
|
|
|
return $this->getMock(RouterInterface::class); |
|
|
|
|
486
|
|
|
} |
487
|
|
|
|
488
|
|
|
/** |
489
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|RequestStack |
490
|
|
|
*/ |
491
|
|
|
private function createRequestStackMock() |
492
|
|
|
{ |
493
|
|
|
return $this->getMock(RequestStack::class); |
|
|
|
|
494
|
|
|
} |
495
|
|
|
|
496
|
|
|
/** |
497
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|GridHandlerInterface |
498
|
|
|
*/ |
499
|
|
|
private function createGridHandler() |
500
|
|
|
{ |
501
|
|
|
return $this->getMock(GridHandlerInterface::class); |
|
|
|
|
502
|
|
|
} |
503
|
|
|
} |
504
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.