Completed
Push — master ( 7c8176...4693d5 )
by Jordi Sala
03:45
created

testappendFormFieldElementAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 53
Code Lines 46

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 53
rs 9.5797
c 2
b 0
f 0
cc 1
eloc 46
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\AdminBundle\Tests\Controller;
15
16
use Doctrine\Common\Persistence\ManagerRegistry;
17
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
18
use Doctrine\Common\Persistence\ObjectManager;
19
use PHPUnit\Framework\TestCase;
20
use Prophecy\Argument;
21
use Sonata\AdminBundle\Admin\AbstractAdmin;
22
use Sonata\AdminBundle\Admin\AdminHelper;
23
use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
24
use Sonata\AdminBundle\Admin\Pool;
25
use Sonata\AdminBundle\Controller\HelperController;
26
use Sonata\AdminBundle\Datagrid\DatagridInterface;
27
use Sonata\AdminBundle\Datagrid\Pager;
28
use Sonata\AdminBundle\Model\ModelManagerInterface;
29
use Sonata\AdminBundle\Tests\Fixtures\Bundle\Entity\Foo;
30
use Sonata\AdminBundle\Twig\Extension\SonataAdminExtension;
31
use Sonata\CoreBundle\Model\Metadata;
32
use Symfony\Bridge\Twig\AppVariable;
33
use Symfony\Bridge\Twig\Command\DebugCommand;
34
use Symfony\Bridge\Twig\Extension\FormExtension;
35
use Symfony\Bridge\Twig\Form\TwigRenderer;
36
use Symfony\Component\DependencyInjection\ContainerInterface;
37
use Symfony\Component\Form\Form;
38
use Symfony\Component\Form\FormBuilder;
39
use Symfony\Component\Form\FormConfigInterface;
40
use Symfony\Component\Form\FormRenderer;
41
use Symfony\Component\Form\FormView;
42
use Symfony\Component\HttpFoundation\Request;
43
use Symfony\Component\HttpFoundation\Response;
44
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
45
use Symfony\Component\PropertyAccess\PropertyAccessor;
46
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
47
use Symfony\Component\Translation\TranslatorInterface;
48
use Symfony\Component\Validator\ConstraintViolation;
49
use Symfony\Component\Validator\ConstraintViolationList;
50
use Symfony\Component\Validator\Validator\ValidatorInterface;
51
use Twig\Environment;
52
use Twig\Template;
53
54
class AdminControllerHelper_Foo
0 ignored issues
show
Coding Style introduced by
This class is not in CamelCase format.

Classes in PHP are usually named in CamelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.

Thus the name database provider becomes DatabaseProvider.

Loading history...
55
{
56
    private $bar;
57
58
    public function getAdminTitle()
59
    {
60
        return 'foo';
61
    }
62
63
    public function setEnabled($value): void
0 ignored issues
show
Unused Code introduced by
The parameter $value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
64
    {
65
    }
66
67
    public function setBar(AdminControllerHelper_Bar $bar): void
68
    {
69
        $this->bar = $bar;
70
    }
71
72
    public function getBar()
73
    {
74
        return $this->bar;
75
    }
76
}
77
78
class AdminControllerHelper_Bar
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style introduced by
This class is not in CamelCase format.

Classes in PHP are usually named in CamelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.

Thus the name database provider becomes DatabaseProvider.

Loading history...
79
{
80
    public function getAdminTitle()
81
    {
82
        return 'bar';
83
    }
84
85
    public function setEnabled($value): void
0 ignored issues
show
Unused Code introduced by
The parameter $value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
86
    {
87
    }
88
89
    public function getEnabled(): void
90
    {
91
    }
92
}
93
94
class HelperControllerTest extends TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
95
{
96
    /**
97
     * {@inheritdoc}
98
     */
99
    protected function setUp(): void
100
    {
101
        $this->pool = $this->prophesize(Pool::class);
102
        $this->twig = $this->prophesize(Environment::class);
103
        $this->helper = $this->prophesize(AdminHelper::class);
104
        $this->validator = $this->prophesize(ValidatorInterface::class);
105
        $this->admin = $this->prophesize(AbstractAdmin::class);
106
107
        $this->pool->getInstance(Argument::any())->willReturn($this->admin->reveal());
108
        $this->admin->setRequest(Argument::type(Request::class))->shouldBeCalled();
109
110
        $this->controller = new HelperController(
111
            $this->twig->reveal(),
112
            $this->pool->reveal(),
113
            $this->helper->reveal(),
114
            $this->validator->reveal()
115
        );
116
    }
117
118
    public function testgetShortObjectDescriptionActionInvalidAdmin(): void
119
    {
120
        $this->expectException(NotFoundHttpException::class);
121
122
        $request = new Request([
123
            'code' => 'sonata.post.admin',
124
            'objectId' => 42,
125
            'uniqid' => 'asdasd123',
126
        ]);
127
128
        $this->pool->getInstance('sonata.post.admin')->willReturn(null);
129
        $this->admin->setRequest(Argument::type(Request::class))->shouldNotBeCalled();
130
131
        $this->controller->getShortObjectDescriptionAction($request);
132
    }
133
134
    public function testgetShortObjectDescriptionActionObjectDoesNotExist(): void
135
    {
136
        $this->expectException(\RuntimeException::class);
137
        $this->expectExceptionMessage('Invalid format');
138
139
        $request = new Request([
140
            'code' => 'sonata.post.admin',
141
            'objectId' => 42,
142
            'uniqid' => 'asdasd123',
143
        ]);
144
145
        $this->admin->setUniqid('asdasd123')->shouldBeCalled();
146
        $this->admin->getObject(42)->willReturn(false);
147
148
        $this->controller->getShortObjectDescriptionAction($request);
149
    }
150
151
    public function testgetShortObjectDescriptionActionEmptyObjectId(): void
152
    {
153
        $request = new Request([
154
            'code' => 'sonata.post.admin',
155
            'objectId' => '',
156
            'uniqid' => 'asdasd123',
157
            '_format' => 'html',
158
        ]);
159
160
        $this->admin->setUniqid('asdasd123')->shouldBeCalled();
161
        $this->admin->getObject(null)->willReturn(false);
162
163
        $response = $this->controller->getShortObjectDescriptionAction($request);
164
165
        $this->assertInstanceOf(Response::class, $response);
166
    }
167
168
    public function testgetShortObjectDescriptionActionObject(): void
169
    {
170
        $request = new Request([
171
            'code' => 'sonata.post.admin',
172
            'objectId' => 42,
173
            'uniqid' => 'asdasd123',
174
            '_format' => 'html',
175
        ]);
176
        $object = new AdminControllerHelper_Foo();
177
178
        $this->admin->setUniqid('asdasd123')->shouldBeCalled();
179
        $this->admin->getObject(42)->willReturn($object);
180
        $this->admin->getTemplate('short_object_description')->willReturn('template');
181
        $this->admin->toString($object)->willReturn('bar');
182
        $this->twig->render('template', [
183
            'admin' => $this->admin->reveal(),
184
            'description' => 'bar',
185
            'object' => $object,
186
            'link_parameters' => [],
187
        ])->willReturn('renderedTemplate');
188
189
        $response = $this->controller->getShortObjectDescriptionAction($request);
190
191
        $this->assertSame('renderedTemplate', $response->getContent());
192
    }
193
194
    public function testsetObjectFieldValueAction(): void
195
    {
196
        $object = new AdminControllerHelper_Foo();
197
        $request = new Request([
198
            'code' => 'sonata.post.admin',
199
            'objectId' => 42,
200
            'field' => 'enabled',
201
            'value' => 1,
202
            'context' => 'list',
203
        ], [], [], [], [], ['REQUEST_METHOD' => 'POST', 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);
204
205
        $fieldDescription = $this->prophesize(FieldDescriptionInterface::class);
206
        $pool = $this->prophesize(Pool::class);
207
        $template = $this->prophesize(Template::class);
208
        $translator = $this->prophesize(TranslatorInterface::class);
209
        $propertyAccessor = new PropertyAccessor();
210
211
        $this->admin->getObject(42)->willReturn($object);
212
        $this->admin->hasAccess('edit', $object)->willReturn(true);
213
        $this->admin->getListFieldDescription('enabled')->willReturn($fieldDescription->reveal());
214
        $this->admin->update($object)->shouldBeCalled();
215
        $this->admin->getTemplate('base_list_field')->willReturn('admin_template');
216
        $this->pool->getPropertyAccessor()->willReturn($propertyAccessor);
217
        $this->twig->getExtension(SonataAdminExtension::class)->willReturn(
218
            new SonataAdminExtension($pool->reveal(), null, $translator->reveal())
219
        );
220
        $this->twig->loadTemplate('admin_template')->willReturn($template->reveal());
221
        $this->twig->isDebug()->willReturn(false);
222
        $fieldDescription->getOption('editable')->willReturn(true);
223
        $fieldDescription->getAdmin()->willReturn($this->admin->reveal());
224
        $fieldDescription->getType()->willReturn('boolean');
225
        $fieldDescription->getTemplate()->willReturn(false);
226
        $fieldDescription->getValue(Argument::cetera())->willReturn('some value');
227
        $this->validator->validate($object)->willReturn(new ConstraintViolationList([]));
228
229
        $response = $this->controller->setObjectFieldValueAction($request);
230
231
        $this->assertEquals(200, $response->getStatusCode());
232
    }
233
234
    public function testappendFormFieldElementAction(): void
235
    {
236
        $object = new AdminControllerHelper_Foo();
237
        $associationObject = new AdminControllerHelper_Bar();
238
        $request = new Request([
239
            'code' => 'sonata.post.admin',
240
            'objectId' => 42,
241
            'field' => 'bar',
242
            'value' => 1,
243
            'context' => 'list',
244
        ], [], [], [], [], ['REQUEST_METHOD' => 'POST', 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);
245
246
        $container = $this->prophesize(ContainerInterface::class);
247
        $fieldDescription = $this->prophesize(FieldDescriptionInterface::class);
248
        $managerRegistry = $this->prophesize(ManagerRegistry::class);
249
        $objectManager = $this->prophesize(ObjectManager::class);
250
        $classMetadata = $this->prophesize(ClassMetadata::class);
251
        $pool = $this->prophesize(Pool::class);
252
        $template = $this->prophesize(Template::class);
253
        $translator = $this->prophesize(TranslatorInterface::class);
254
        $propertyAccessor = new PropertyAccessor();
255
256
        $this->admin->getObject(42)->willReturn($object);
257
        $this->admin->hasAccess('edit', $object)->willReturn(true);
258
        $this->admin->getListFieldDescription('bar')->willReturn($fieldDescription->reveal());
259
        $this->admin->getManagerType()->willReturn('doctrine_orm');
260
        $this->admin->getClass()->willReturn(get_class($object));
261
        $this->admin->update($object)->shouldBeCalled();
262
        $this->admin->getTemplate('base_list_field')->willReturn('admin_template');
263
        $this->validator->validate($object)->willReturn(new ConstraintViolationList([]));
264
        $this->twig->getExtension(SonataAdminExtension::class)->willReturn(
265
            new SonataAdminExtension($pool->reveal(), null, $translator->reveal())
266
        );
267
        $this->twig->loadTemplate('field_template')->willReturn($template->reveal());
268
        $this->twig->isDebug()->willReturn(false);
269
        $this->pool->getContainer()->willReturn($container->reveal());
270
        $this->pool->getPropertyAccessor()->willReturn($propertyAccessor);
271
        $fieldDescription->getType()->willReturn('choice');
272
        $fieldDescription->getOption('editable')->willReturn(true);
273
        $fieldDescription->getOption('class')->willReturn(AdminControllerHelper_Bar::class);
274
        $fieldDescription->getAdmin()->willReturn($this->admin->reveal());
275
        $fieldDescription->getTemplate()->willReturn('field_template');
276
        $fieldDescription->getValue(Argument::cetera())->willReturn('some value');
277
        $container->get('doctrine_orm')->willReturn($managerRegistry->reveal());
278
        $managerRegistry->getManager()->willReturn($objectManager->reveal());
279
        $objectManager->getClassMetadata(get_class($object))->willReturn($classMetadata->reveal());
280
        $objectManager->find(get_class($associationObject), 1)->willReturn($associationObject);
281
        $classMetadata->hasAssociation('bar')->willReturn(true);
282
283
        $response = $this->controller->setObjectFieldValueAction($request);
284
285
        $this->assertEquals(200, $response->getStatusCode());
286
    }
287
288
    public function testRetrieveFormFieldElementAction(): void
289
    {
290
        $object = new AdminControllerHelper_Foo();
291
        $request = new Request([
292
            'code' => 'sonata.post.admin',
293
            'objectId' => 42,
294
            'field' => 'enabled',
295
            'value' => 1,
296
            'context' => 'list',
297
        ], [], [], [], [], ['REQUEST_METHOD' => 'POST']);
298
299
        $modelManager = $this->prophesize(ModelManagerInterface::class);
300
        $formView = new FormView();
301
        $form = $this->prophesize(Form::class);
302
        $formBuilder = $this->prophesize(FormBuilder::class);
303
304
        $renderer = $this->configureFormRenderer();
305
306
        $this->admin->getModelManager()->willReturn($modelManager->reveal());
307
        $this->admin->getClass()->willReturn(get_class($object));
308
        $this->admin->setSubject($object)->shouldBeCalled();
309
        $this->admin->getFormTheme()->willReturn($formView);
310
        $this->admin->getFormBuilder()->willReturn($formBuilder->reveal());
311
        $this->helper->getChildFormView($formView, null)
312
            ->willReturn($formView);
313
        $modelManager->find(get_class($object), 42)->willReturn($object);
314
        $form->setData($object)->shouldBeCalled();
315
        $form->handleRequest($request)->shouldBeCalled();
316
        $form->createView()->willReturn($formView);
317
        $formBuilder->getForm()->willReturn($form->reveal());
318
        $renderer->setTheme($formView, $formView)->shouldBeCalled();
319
        $renderer->searchAndRenderBlock($formView, 'widget')->willReturn('block');
320
321
        $response = $this->controller->retrieveFormFieldElementAction($request);
322
323
        $this->isInstanceOf(Response::class, $response);
324
        $this->assertSame($response->getContent(), 'block');
325
    }
326
327
    public function testSetObjectFieldValueActionWithViolations(): void
328
    {
329
        $bar = new AdminControllerHelper_Bar();
330
        $object = new AdminControllerHelper_Foo();
331
        $object->setBar($bar);
332
        $request = new Request([
333
            'code' => 'sonata.post.admin',
334
            'objectId' => 42,
335
            'field' => 'bar.enabled',
336
            'value' => 1,
337
            'context' => 'list',
338
        ], [], [], [], [], ['REQUEST_METHOD' => 'POST', 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);
339
340
        $fieldDescription = $this->prophesize(FieldDescriptionInterface::class);
341
        $propertyAccessor = new PropertyAccessor();
342
343
        $this->pool->getPropertyAccessor()->willReturn($propertyAccessor);
344
        $this->admin->getObject(42)->willReturn($object);
345
        $this->admin->hasAccess('edit', $object)->willReturn(true);
346
        $this->admin->getListFieldDescription('bar.enabled')->willReturn($fieldDescription->reveal());
347
        $this->validator->validate($bar)->willReturn(new ConstraintViolationList([
348
            new ConstraintViolation('error1', null, [], null, 'enabled', null),
349
            new ConstraintViolation('error2', null, [], null, 'enabled', null),
350
        ]));
351
        $fieldDescription->getOption('editable')->willReturn(true);
352
        $fieldDescription->getType()->willReturn('boolean');
353
354
        $response = $this->controller->setObjectFieldValueAction($request);
355
356
        $this->assertEquals(400, $response->getStatusCode());
357
        $this->assertSame(json_encode("error1\nerror2"), $response->getContent());
358
    }
359
360
    /**
361
     * @exceptionMessage Invalid format
362
     */
363
    public function testRetrieveAutocompleteItemsActionNotGranted(): void
364
    {
365
        $this->expectException(AccessDeniedException::class);
366
367
        $request = new Request([
368
            'admin_code' => 'foo.admin',
369
        ], [], [], [], [], ['REQUEST_METHOD' => 'GET', 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);
370
371
        $this->admin->hasAccess('create')->willReturn(false);
372
        $this->admin->hasAccess('edit')->willReturn(false);
373
374
        $this->controller->retrieveAutocompleteItemsAction($request);
375
    }
376
377
    public function testRetrieveAutocompleteItemsActionDisabledFormelememt(): void
378
    {
379
        $this->expectException(AccessDeniedException::class);
380
        $this->expectExceptionMessage('Autocomplete list can`t be retrieved because the form element is disabled or read_only.');
381
382
        $object = new AdminControllerHelper_Foo();
383
        $request = new Request([
384
            'admin_code' => 'foo.admin',
385
            'field' => 'barField',
386
        ], [], [], [], [], ['REQUEST_METHOD' => 'GET', 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);
387
388
        $fieldDescription = $this->prophesize(FieldDescriptionInterface::class);
389
390
        $this->configureFormConfig('barField', true);
391
392
        $this->admin->getNewInstance()->willReturn($object);
393
        $this->admin->setSubject($object)->shouldBeCalled();
394
        $this->admin->hasAccess('create')->willReturn(true);
395
        $this->admin->getFormFieldDescriptions()->willReturn(null);
396
        $this->admin->getFormFieldDescription('barField')->willReturn($fieldDescription->reveal());
397
398
        $fieldDescription->getTargetEntity()->willReturn(Foo::class);
399
        $fieldDescription->getName()->willReturn('barField');
400
401
        $this->controller->retrieveAutocompleteItemsAction($request);
402
    }
403
404
    public function testRetrieveAutocompleteItemsTooShortSearchString(): void
405
    {
406
        $object = new AdminControllerHelper_Foo();
407
        $request = new Request([
408
            'admin_code' => 'foo.admin',
409
            'field' => 'barField',
410
            'q' => 'so',
411
        ], [], [], [], [], ['REQUEST_METHOD' => 'GET', 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);
412
413
        $targetAdmin = $this->prophesize(AbstractAdmin::class);
414
        $fieldDescription = $this->prophesize(FieldDescriptionInterface::class);
415
416
        $this->configureFormConfig('barField');
417
418
        $this->admin->getNewInstance()->willReturn($object);
419
        $this->admin->setSubject($object)->shouldBeCalled();
420
        $this->admin->hasAccess('create')->willReturn(true);
421
        $this->admin->getFormFieldDescription('barField')->willReturn($fieldDescription->reveal());
422
        $this->admin->getFormFieldDescriptions()->willReturn(null);
423
        $targetAdmin->checkAccess('list')->shouldBeCalled();
424
        $fieldDescription->getTargetEntity()->willReturn(Foo::class);
425
        $fieldDescription->getName()->willReturn('barField');
426
        $fieldDescription->getAssociationAdmin()->willReturn($targetAdmin->reveal());
427
428
        $response = $this->controller->retrieveAutocompleteItemsAction($request);
429
430
        $this->isInstanceOf(Response::class, $response);
431
        $this->assertSame('application/json', $response->headers->get('Content-Type'));
432
        $this->assertSame('{"status":"KO","message":"Too short search string."}', $response->getContent());
433
    }
434
435
    public function testRetrieveAutocompleteItems(): void
436
    {
437
        $entity = new Foo();
438
        $request = new Request([
439
            'admin_code' => 'foo.admin',
440
            'field' => 'barField',
441
            'q' => 'sonata',
442
        ], [], [], [], [], ['REQUEST_METHOD' => 'GET', 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);
443
444
        $targetAdmin = $this->prophesize(AbstractAdmin::class);
445
        $datagrid = $this->prophesize(DatagridInterface::class);
446
        $metadata = $this->prophesize(Metadata::class);
447
        $pager = $this->prophesize(Pager::class);
448
        $fieldDescription = $this->prophesize(FieldDescriptionInterface::class);
449
450
        $this->configureFormConfig('barField');
451
452
        $this->admin->getNewInstance()->willReturn($entity);
453
        $this->admin->setSubject($entity)->shouldBeCalled();
454
        $this->admin->hasAccess('create')->willReturn(true);
455
        $this->admin->getFormFieldDescription('barField')->willReturn($fieldDescription->reveal());
456
        $this->admin->getFormFieldDescriptions()->willReturn(null);
457
        $this->admin->id($entity)->willReturn(123);
458
        $targetAdmin->checkAccess('list')->shouldBeCalled();
459
        $targetAdmin->setPersistFilters(false)->shouldBeCalled();
460
        $targetAdmin->getDatagrid()->willReturn($datagrid->reveal());
461
        $targetAdmin->getObjectMetadata($entity)->willReturn($metadata->reveal());
462
        $metadata->getTitle()->willReturn('FOO');
463
        $datagrid->hasFilter('foo')->willReturn(true);
464
        $datagrid->setValue('foo', null, 'sonata')->shouldBeCalled();
465
        $datagrid->setValue('_per_page', null, 10)->shouldBeCalled();
466
        $datagrid->setValue('_page', null, 1)->shouldBeCalled();
467
        $datagrid->buildPager()->willReturn(null);
468
        $datagrid->getPager()->willReturn($pager->reveal());
469
        $pager->getResults()->willReturn([$entity]);
470
        $pager->isLastPage()->willReturn(true);
471
        $fieldDescription->getTargetEntity()->willReturn(Foo::class);
472
        $fieldDescription->getName()->willReturn('barField');
473
        $fieldDescription->getAssociationAdmin()->willReturn($targetAdmin->reveal());
474
475
        $response = $this->controller->retrieveAutocompleteItemsAction($request);
476
477
        $this->isInstanceOf(Response::class, $response);
478
        $this->assertSame('application/json', $response->headers->get('Content-Type'));
479
        $this->assertSame('{"status":"OK","more":false,"items":[{"id":123,"label":"FOO"}]}', $response->getContent());
480
    }
481
482
    private function configureFormConfig($field, $disabled = false): void
483
    {
484
        $form = $this->prophesize(Form::class);
485
        $formType = $this->prophesize(Form::class);
486
        $formConfig = $this->prophesize(FormConfigInterface::class);
487
488
        $this->admin->getForm()->willReturn($form->reveal());
489
        $form->get($field)->willReturn($formType->reveal());
490
        $formType->getConfig()->willReturn($formConfig->reveal());
491
        $formConfig->getAttribute('disabled')->willReturn($disabled);
492
        $formConfig->getAttribute('property')->willReturn('foo');
493
        $formConfig->getAttribute('callback')->willReturn(null);
494
        $formConfig->getAttribute('minimum_input_length')->willReturn(3);
495
        $formConfig->getAttribute('items_per_page')->willReturn(10);
496
        $formConfig->getAttribute('req_param_name_page_number')->willReturn('_page');
497
        $formConfig->getAttribute('to_string_callback')->willReturn(null);
498
        $formConfig->getAttribute('target_admin_access_action')->willReturn('list');
499
    }
500
501
    private function configureFormRenderer()
502
    {
503
        $runtime = $this->prophesize(FormRenderer::class);
504
505
        // Remove the condition when dropping sf < 3.2
506
        if (!method_exists(AppVariable::class, 'getToken')) {
507
            $extension = $this->prophesize(FormExtension::class);
508
509
            $this->twig->getExtension(FormExtension::class)->willReturn($extension->reveal());
510
            $extension->initRuntime($this->twig->reveal())->shouldBeCalled();
511
            $extension->renderer = $runtime->reveal();
512
513
            return $runtime;
514
        }
515
516
        // Remove the condition when dropping sf < 3.4
517
        if (!method_exists(DebugCommand::class, 'getLoaderPaths')) {
518
            $twigRuntime = $this->prophesize(TwigRenderer::class);
519
520
            $this->twig->getRuntime(TwigRenderer::class)->willReturn($twigRuntime->reveal());
521
            $twigRuntime->setEnvironment($this->twig->reveal())->shouldBeCalled();
522
523
            return $twigRuntime;
524
        }
525
526
        $this->twig->getRuntime(FormRenderer::class)->willReturn($runtime->reveal());
527
528
        return $runtime;
529
    }
530
}
531