Completed
Push — master ( 9c198b...7695bb )
by Marko
12s
created

testRetrieveAutocompleteItemsComplexProperty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 9.536
c 0
b 0
f 0
cc 1
nc 1
nop 0
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 PHPUnit\Framework\TestCase;
17
use Prophecy\Argument;
18
use Sonata\AdminBundle\Admin\AbstractAdmin;
19
use Sonata\AdminBundle\Admin\AdminHelper;
20
use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
21
use Sonata\AdminBundle\Admin\Pool;
22
use Sonata\AdminBundle\Controller\HelperController;
23
use Sonata\AdminBundle\Datagrid\DatagridInterface;
24
use Sonata\AdminBundle\Datagrid\Pager;
25
use Sonata\AdminBundle\Model\ModelManagerInterface;
26
use Sonata\AdminBundle\Templating\TemplateRegistryInterface;
27
use Sonata\AdminBundle\Tests\Fixtures\Bundle\Entity\Foo;
28
use Sonata\AdminBundle\Tests\Fixtures\Filter\FooFilter;
29
use Sonata\AdminBundle\Twig\Extension\SonataAdminExtension;
30
use Sonata\CoreBundle\Model\Metadata;
31
use Symfony\Bridge\Twig\AppVariable;
32
use Symfony\Bridge\Twig\Command\DebugCommand;
33
use Symfony\Bridge\Twig\Extension\FormExtension;
34
use Symfony\Bridge\Twig\Form\TwigRenderer;
35
use Symfony\Component\DependencyInjection\ContainerInterface;
36
use Symfony\Component\Form\Form;
37
use Symfony\Component\Form\FormConfigInterface;
38
use Symfony\Component\Form\FormRenderer;
39
use Symfony\Component\Form\FormView;
40
use Symfony\Component\HttpFoundation\Request;
41
use Symfony\Component\HttpFoundation\Response;
42
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
43
use Symfony\Component\PropertyAccess\PropertyAccessor;
44
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
45
use Symfony\Component\Translation\TranslatorInterface;
46
use Symfony\Component\Validator\ConstraintViolation;
47
use Symfony\Component\Validator\ConstraintViolationList;
48
use Symfony\Component\Validator\Validator\ValidatorInterface;
49
use Twig\Environment;
50
use Twig\Template;
51
use Twig\TemplateWrapper;
52
53
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...
54
{
55
    private $bar;
56
57
    public function getAdminTitle()
58
    {
59
        return 'foo';
60
    }
61
62
    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...
63
    {
64
    }
65
66
    public function setBar(AdminControllerHelper_Bar $bar): void
67
    {
68
        $this->bar = $bar;
69
    }
70
71
    public function getBar()
72
    {
73
        return $this->bar;
74
    }
75
}
76
77
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...
78
{
79
    public function getAdminTitle()
80
    {
81
        return 'bar';
82
    }
83
84
    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...
85
    {
86
    }
87
88
    public function getEnabled(): void
89
    {
90
    }
91
}
92
93
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...
94
{
95
    /**
96
     * @var Pool
97
     */
98
    private $pool;
99
100
    /**
101
     * @var Environment
102
     */
103
    private $twig;
104
105
    /**
106
     * @var AdminHelper
107
     */
108
    private $helper;
109
110
    /**
111
     * @var ValidatorInterface
112
     */
113
    private $validator;
114
115
    /**
116
     * @var AbstractAdmin
117
     */
118
    private $admin;
119
120
    /**
121
     * @var HelperController
122
     */
123
    private $controller;
124
125
    /**
126
     * {@inheritdoc}
127
     */
128
    protected function setUp(): void
129
    {
130
        $this->pool = $this->prophesize(Pool::class);
131
        $this->twig = $this->prophesize(Environment::class);
132
        $this->helper = $this->prophesize(AdminHelper::class);
133
        $this->validator = $this->prophesize(ValidatorInterface::class);
134
        $this->admin = $this->prophesize(AbstractAdmin::class);
135
136
        $this->pool->getInstance(Argument::any())->willReturn($this->admin->reveal());
137
        $this->admin->setRequest(Argument::type(Request::class))->shouldBeCalled();
138
139
        $this->controller = new HelperController(
140
            $this->twig->reveal(),
141
            $this->pool->reveal(),
142
            $this->helper->reveal(),
143
            $this->validator->reveal()
144
        );
145
    }
146
147
    public function testgetShortObjectDescriptionActionInvalidAdmin(): void
148
    {
149
        $this->expectException(NotFoundHttpException::class);
150
151
        $request = new Request([
152
            'code' => 'sonata.post.admin',
153
            'objectId' => 42,
154
            'uniqid' => 'asdasd123',
155
        ]);
156
157
        $this->pool->getInstance('sonata.post.admin')->willReturn(null);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
158
        $this->admin->setRequest(Argument::type(Request::class))->shouldNotBeCalled();
0 ignored issues
show
Bug introduced by
The method shouldNotBeCalled cannot be called on $this->admin->setRequest...dation\Request::class)) (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
159
160
        $this->controller->getShortObjectDescriptionAction($request);
161
    }
162
163
    public function testgetShortObjectDescriptionActionObjectDoesNotExist(): void
164
    {
165
        $this->expectException(\RuntimeException::class);
166
        $this->expectExceptionMessage('Invalid format');
167
168
        $request = new Request([
169
            'code' => 'sonata.post.admin',
170
            'objectId' => 42,
171
            'uniqid' => 'asdasd123',
172
        ]);
173
174
        $this->admin->setUniqid('asdasd123')->shouldBeCalled();
0 ignored issues
show
Bug introduced by
The method shouldBeCalled cannot be called on $this->admin->setUniqid('asdasd123') (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
175
        $this->admin->getObject(42)->willReturn(false);
176
177
        $this->controller->getShortObjectDescriptionAction($request);
178
    }
179
180
    public function testgetShortObjectDescriptionActionEmptyObjectId(): void
181
    {
182
        $request = new Request([
183
            'code' => 'sonata.post.admin',
184
            'objectId' => '',
185
            'uniqid' => 'asdasd123',
186
            '_format' => 'html',
187
        ]);
188
189
        $this->admin->setUniqid('asdasd123')->shouldBeCalled();
0 ignored issues
show
Bug introduced by
The method shouldBeCalled cannot be called on $this->admin->setUniqid('asdasd123') (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
190
        $this->admin->getObject(null)->willReturn(false);
191
192
        $response = $this->controller->getShortObjectDescriptionAction($request);
193
194
        $this->assertInstanceOf(Response::class, $response);
195
    }
196
197
    public function testgetShortObjectDescriptionActionObject(): void
198
    {
199
        $request = new Request([
200
            'code' => 'sonata.post.admin',
201
            'objectId' => 42,
202
            'uniqid' => 'asdasd123',
203
            '_format' => 'html',
204
        ]);
205
        $object = new AdminControllerHelper_Foo();
206
207
        $this->admin->setUniqid('asdasd123')->shouldBeCalled();
0 ignored issues
show
Bug introduced by
The method shouldBeCalled cannot be called on $this->admin->setUniqid('asdasd123') (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
208
        $this->admin->getObject(42)->willReturn($object);
209
        $this->admin->getTemplate('short_object_description')->willReturn('template');
0 ignored issues
show
Bug introduced by
The method willReturn cannot be called on $this->admin->getTemplat...rt_object_description') (of type null|string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
Deprecated Code introduced by
The method Sonata\AdminBundle\Admin...actAdmin::getTemplate() has been deprecated with message: since 3.34, will be dropped in 4.0. Use TemplateRegistry services instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
210
        $this->admin->toString($object)->willReturn('bar');
0 ignored issues
show
Bug introduced by
The method willReturn cannot be called on $this->admin->toString($object) (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
211
        $this->twig->render('template', [
0 ignored issues
show
Bug introduced by
The method willReturn cannot be called on $this->twig->render('tem...arameters' => array())) (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
212
            'admin' => $this->admin->reveal(),
0 ignored issues
show
Bug introduced by
The method reveal() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
213
            'description' => 'bar',
214
            'object' => $object,
215
            'link_parameters' => [],
216
        ])->willReturn('renderedTemplate');
217
218
        $response = $this->controller->getShortObjectDescriptionAction($request);
219
220
        $this->assertSame('renderedTemplate', $response->getContent());
221
    }
222
223
    public function testsetObjectFieldValueAction(): void
224
    {
225
        $object = new AdminControllerHelper_Foo();
226
        $request = new Request([
227
            'code' => 'sonata.post.admin',
228
            'objectId' => 42,
229
            'field' => 'enabled',
230
            'value' => 1,
231
            'context' => 'list',
232
        ], [], [], [], [], ['REQUEST_METHOD' => 'POST', 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);
233
234
        $fieldDescription = $this->prophesize(FieldDescriptionInterface::class);
235
        $pool = $this->prophesize(Pool::class);
236
        $template = $this->prophesize(Template::class);
237
        $translator = $this->prophesize(TranslatorInterface::class);
238
        $propertyAccessor = new PropertyAccessor();
239
        $templateRegistry = $this->prophesize(TemplateRegistryInterface::class);
240
        $container = $this->prophesize(ContainerInterface::class);
241
242
        $this->admin->getObject(42)->willReturn($object);
243
        $this->admin->getCode()->willReturn('sonata.post.admin');
0 ignored issues
show
Bug introduced by
The method willReturn cannot be called on $this->admin->getCode() (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
244
        $this->admin->hasAccess('edit', $object)->willReturn(true);
0 ignored issues
show
Bug introduced by
The method willReturn cannot be called on $this->admin->hasAccess('edit', $object) (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
245
        $this->admin->getListFieldDescription('enabled')->willReturn($fieldDescription->reveal());
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sonata\AdminBundl...ldDescriptionInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
246
        $this->admin->update($object)->shouldBeCalled();
247
        // NEXT_MAJOR: Remove this line
248
        $this->admin->getTemplate('base_list_field')->willReturn('admin_template');
0 ignored issues
show
Bug introduced by
The method willReturn cannot be called on $this->admin->getTemplate('base_list_field') (of type null|string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
Deprecated Code introduced by
The method Sonata\AdminBundle\Admin...actAdmin::getTemplate() has been deprecated with message: since 3.34, will be dropped in 4.0. Use TemplateRegistry services instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
249
        $templateRegistry->getTemplate('base_list_field')->willReturn('admin_template');
250
        $container->get('sonata.post.admin.template_registry')->willReturn($templateRegistry->reveal());
251
        $this->pool->getPropertyAccessor()->willReturn($propertyAccessor);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Symfony\Component...pertyAccessorInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
252
        $this->twig->getExtension(SonataAdminExtension::class)->willReturn(
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Twig_ExtensionInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
253
            new SonataAdminExtension($pool->reveal(), null, $translator->reveal(), $container->reveal())
254
        );
255
        $this->twig->load('admin_template')->willReturn(new TemplateWrapper($this->twig->reveal(), $template->reveal()));
0 ignored issues
show
Bug introduced by
The method reveal() does not seem to exist on object<Twig\Environment>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method willReturn() does not seem to exist on object<Twig_TemplateWrapper>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
256
        $this->twig->isDebug()->willReturn(false);
0 ignored issues
show
Bug introduced by
The method willReturn cannot be called on $this->twig->isDebug() (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
257
        $fieldDescription->getOption('editable')->willReturn(true);
258
        $fieldDescription->getAdmin()->willReturn($this->admin->reveal());
0 ignored issues
show
Bug introduced by
The method reveal() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
259
        $fieldDescription->getType()->willReturn('boolean');
260
        $fieldDescription->getTemplate()->willReturn(false);
261
        $fieldDescription->getValue(Argument::cetera())->willReturn('some value');
262
        $this->validator->validate($object)->willReturn(new ConstraintViolationList([]));
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Symfony\Component...ViolationListInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
263
264
        $response = $this->controller->setObjectFieldValueAction($request);
265
266
        $this->assertEquals(200, $response->getStatusCode());
267
    }
268
269
    public function testappendFormFieldElementAction(): void
270
    {
271
        $object = new AdminControllerHelper_Foo();
272
        $associationObject = new AdminControllerHelper_Bar();
273
        $request = new Request([
274
            'code' => 'sonata.post.admin',
275
            'objectId' => 42,
276
            'field' => 'bar',
277
            'value' => 1,
278
            'context' => 'list',
279
        ], [], [], [], [], ['REQUEST_METHOD' => 'POST', 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);
280
281
        $fieldDescription = $this->prophesize(FieldDescriptionInterface::class);
282
        $modelManager = $this->prophesize(ModelManagerInterface::class);
283
        $template = $this->prophesize(Template::class);
284
        $translator = $this->prophesize(TranslatorInterface::class);
285
        $propertyAccessor = new PropertyAccessor();
286
        $templateRegistry = $this->prophesize(TemplateRegistryInterface::class);
287
        $container = $this->prophesize(ContainerInterface::class);
288
289
        $this->admin->getObject(42)->willReturn($object);
290
        $this->admin->getCode()->willReturn('sonata.post.admin');
0 ignored issues
show
Bug introduced by
The method willReturn cannot be called on $this->admin->getCode() (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
291
        $this->admin->hasAccess('edit', $object)->willReturn(true);
0 ignored issues
show
Bug introduced by
The method willReturn cannot be called on $this->admin->hasAccess('edit', $object) (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
292
        $this->admin->getListFieldDescription('bar')->willReturn($fieldDescription->reveal());
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sonata\AdminBundl...ldDescriptionInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
293
        $this->admin->getClass()->willReturn(get_class($object));
0 ignored issues
show
Bug introduced by
The method willReturn cannot be called on $this->admin->getClass() (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
294
        $this->admin->update($object)->shouldBeCalled();
295
        $container->get('sonata.post.admin.template_registry')->willReturn($templateRegistry->reveal());
296
        // NEXT_MAJOR: Remove this line
297
        $this->admin->getTemplate('base_list_field')->willReturn('admin_template');
0 ignored issues
show
Bug introduced by
The method willReturn cannot be called on $this->admin->getTemplate('base_list_field') (of type null|string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
Deprecated Code introduced by
The method Sonata\AdminBundle\Admin...actAdmin::getTemplate() has been deprecated with message: since 3.34, will be dropped in 4.0. Use TemplateRegistry services instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
298
        $templateRegistry->getTemplate('base_list_field')->willReturn('admin_template');
299
        $this->admin->getModelManager()->willReturn($modelManager->reveal());
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sonata\AdminBundl...\ModelManagerInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
300
        $this->validator->validate($object)->willReturn(new ConstraintViolationList([]));
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Symfony\Component...ViolationListInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
301
        $this->twig->getExtension(SonataAdminExtension::class)->willReturn(
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Twig_ExtensionInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
302
            new SonataAdminExtension($this->pool->reveal(), null, $translator->reveal(), $container->reveal())
0 ignored issues
show
Bug introduced by
The method reveal() does not seem to exist on object<Sonata\AdminBundle\Admin\Pool>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
303
        );
304
        $this->twig->load('field_template')->willReturn(new TemplateWrapper($this->twig->reveal(), $template->reveal()));
0 ignored issues
show
Bug introduced by
The method reveal() does not seem to exist on object<Twig\Environment>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method willReturn() does not seem to exist on object<Twig_TemplateWrapper>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
305
        $this->twig->isDebug()->willReturn(false);
0 ignored issues
show
Bug introduced by
The method willReturn cannot be called on $this->twig->isDebug() (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
306
        $this->pool->getPropertyAccessor()->willReturn($propertyAccessor);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Symfony\Component...pertyAccessorInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
307
        $fieldDescription->getType()->willReturn('choice');
308
        $fieldDescription->getOption('editable')->willReturn(true);
309
        $fieldDescription->getOption('class')->willReturn(AdminControllerHelper_Bar::class);
310
        $fieldDescription->getTargetEntity()->willReturn(AdminControllerHelper_Bar::class);
311
        $fieldDescription->getAdmin()->willReturn($this->admin->reveal());
0 ignored issues
show
Bug introduced by
The method reveal() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
312
        $fieldDescription->getTemplate()->willReturn('field_template');
313
        $fieldDescription->getValue(Argument::cetera())->willReturn('some value');
314
        $modelManager->find(get_class($associationObject), 1)->willReturn($associationObject);
315
316
        $response = $this->controller->setObjectFieldValueAction($request);
317
318
        $this->assertEquals(200, $response->getStatusCode());
319
    }
320
321
    public function testRetrieveFormFieldElementAction(): void
322
    {
323
        $object = new AdminControllerHelper_Foo();
324
        $request = new Request([
325
            'code' => 'sonata.post.admin',
326
            'objectId' => 42,
327
            'field' => 'enabled',
328
            'value' => 1,
329
            'context' => 'list',
330
        ], [], [], [], [], ['REQUEST_METHOD' => 'POST']);
331
332
        $modelManager = $this->prophesize(ModelManagerInterface::class);
333
        $formView = new FormView();
334
        $form = $this->prophesize(Form::class);
335
336
        $renderer = $this->configureFormRenderer();
337
338
        $this->admin->getObject(42)->willReturn($object);
339
        $this->admin->getClass()->willReturn(get_class($object));
0 ignored issues
show
Bug introduced by
The method willReturn cannot be called on $this->admin->getClass() (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
340
        $this->admin->setSubject($object)->shouldBeCalled();
0 ignored issues
show
Bug introduced by
The method shouldBeCalled cannot be called on $this->admin->setSubject($object) (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
341
        $this->admin->getFormTheme()->willReturn($formView);
0 ignored issues
show
Bug introduced by
The method willReturn cannot be called on $this->admin->getFormTheme() (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
342
        $this->helper->appendFormFieldElement($this->admin->reveal(), $object, null)->willReturn([
0 ignored issues
show
Bug introduced by
The method reveal() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method willReturn cannot be called on $this->helper->appendFor...eveal(), $object, null) (of type array<integer,null|objec...Form\\FormInterface>"}>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
343
            $this->prophesize(FieldDescriptionInterface::class),
344
            $form->reveal(),
345
        ]);
346
        $this->helper->getChildFormView($formView, null)
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Symfony\Component\Form\FormView>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
347
            ->willReturn($formView);
348
        $modelManager->find(get_class($object), 42)->willReturn($object);
349
        $form->createView()->willReturn($formView);
350
        $renderer->setTheme($formView, $formView)->shouldBeCalled();
351
        $renderer->searchAndRenderBlock($formView, 'widget')->willReturn('block');
352
353
        $response = $this->controller->appendFormFieldElementAction($request);
354
355
        $this->isInstanceOf(Response::class, $response);
356
        $this->assertSame($response->getContent(), 'block');
357
    }
358
359
    public function testSetObjectFieldValueActionWithViolations(): void
360
    {
361
        $bar = new AdminControllerHelper_Bar();
362
        $object = new AdminControllerHelper_Foo();
363
        $object->setBar($bar);
364
        $request = new Request([
365
            'code' => 'sonata.post.admin',
366
            'objectId' => 42,
367
            'field' => 'bar.enabled',
368
            'value' => 1,
369
            'context' => 'list',
370
        ], [], [], [], [], ['REQUEST_METHOD' => 'POST', 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);
371
372
        $fieldDescription = $this->prophesize(FieldDescriptionInterface::class);
373
        $propertyAccessor = new PropertyAccessor();
374
375
        $this->pool->getPropertyAccessor()->willReturn($propertyAccessor);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Symfony\Component...pertyAccessorInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
376
        $this->admin->getObject(42)->willReturn($object);
377
        $this->admin->hasAccess('edit', $object)->willReturn(true);
0 ignored issues
show
Bug introduced by
The method willReturn cannot be called on $this->admin->hasAccess('edit', $object) (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
378
        $this->admin->getListFieldDescription('bar.enabled')->willReturn($fieldDescription->reveal());
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sonata\AdminBundl...ldDescriptionInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
379
        $this->validator->validate($bar)->willReturn(new ConstraintViolationList([
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Symfony\Component...ViolationListInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
380
            new ConstraintViolation('error1', null, [], null, 'enabled', null),
381
            new ConstraintViolation('error2', null, [], null, 'enabled', null),
382
        ]));
383
        $fieldDescription->getOption('editable')->willReturn(true);
384
        $fieldDescription->getType()->willReturn('boolean');
385
386
        $response = $this->controller->setObjectFieldValueAction($request);
387
388
        $this->assertEquals(400, $response->getStatusCode());
389
        $this->assertSame(json_encode("error1\nerror2"), $response->getContent());
390
    }
391
392
    /**
393
     * @exceptionMessage Invalid format
394
     */
395
    public function testRetrieveAutocompleteItemsActionNotGranted(): void
396
    {
397
        $this->expectException(AccessDeniedException::class);
398
399
        $request = new Request([
400
            'admin_code' => 'foo.admin',
401
        ], [], [], [], [], ['REQUEST_METHOD' => 'GET', 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);
402
403
        $this->admin->hasAccess('create')->willReturn(false);
0 ignored issues
show
Bug introduced by
The method willReturn cannot be called on $this->admin->hasAccess('create') (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
404
        $this->admin->hasAccess('edit')->willReturn(false);
0 ignored issues
show
Bug introduced by
The method willReturn cannot be called on $this->admin->hasAccess('edit') (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
405
406
        $this->controller->retrieveAutocompleteItemsAction($request);
407
    }
408
409
    public function testRetrieveAutocompleteItemsActionDisabledFormelememt(): void
410
    {
411
        $this->expectException(AccessDeniedException::class);
412
        $this->expectExceptionMessage('Autocomplete list can`t be retrieved because the form element is disabled or read_only.');
413
414
        $object = new AdminControllerHelper_Foo();
415
        $request = new Request([
416
            'admin_code' => 'foo.admin',
417
            'field' => 'barField',
418
        ], [], [], [], [], ['REQUEST_METHOD' => 'GET', 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);
419
420
        $fieldDescription = $this->prophesize(FieldDescriptionInterface::class);
421
422
        $this->configureFormConfig('barField', true);
423
424
        $this->admin->getNewInstance()->willReturn($object);
425
        $this->admin->setSubject($object)->shouldBeCalled();
0 ignored issues
show
Bug introduced by
The method shouldBeCalled cannot be called on $this->admin->setSubject($object) (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
426
        $this->admin->hasAccess('create')->willReturn(true);
0 ignored issues
show
Bug introduced by
The method willReturn cannot be called on $this->admin->hasAccess('create') (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
427
        $this->admin->getFormFieldDescriptions()->willReturn(null);
0 ignored issues
show
Bug introduced by
The method willReturn cannot be called on $this->admin->getFormFieldDescriptions() (of type array<integer,object<Son...dDescriptionInterface>>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
428
        $this->admin->getFormFieldDescription('barField')->willReturn($fieldDescription->reveal());
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sonata\AdminBundl...ldDescriptionInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
429
430
        $fieldDescription->getTargetEntity()->willReturn(Foo::class);
431
        $fieldDescription->getName()->willReturn('barField');
432
433
        $this->controller->retrieveAutocompleteItemsAction($request);
434
    }
435
436
    public function testRetrieveAutocompleteItemsTooShortSearchString(): void
437
    {
438
        $object = new AdminControllerHelper_Foo();
439
        $request = new Request([
440
            'admin_code' => 'foo.admin',
441
            'field' => 'barField',
442
            'q' => 'so',
443
        ], [], [], [], [], ['REQUEST_METHOD' => 'GET', 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);
444
445
        $targetAdmin = $this->prophesize(AbstractAdmin::class);
446
        $fieldDescription = $this->prophesize(FieldDescriptionInterface::class);
447
448
        $this->configureFormConfig('barField');
449
450
        $this->admin->getNewInstance()->willReturn($object);
451
        $this->admin->setSubject($object)->shouldBeCalled();
0 ignored issues
show
Bug introduced by
The method shouldBeCalled cannot be called on $this->admin->setSubject($object) (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
452
        $this->admin->hasAccess('create')->willReturn(true);
0 ignored issues
show
Bug introduced by
The method willReturn cannot be called on $this->admin->hasAccess('create') (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
453
        $this->admin->getFormFieldDescription('barField')->willReturn($fieldDescription->reveal());
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sonata\AdminBundl...ldDescriptionInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
454
        $this->admin->getFormFieldDescriptions()->willReturn(null);
0 ignored issues
show
Bug introduced by
The method willReturn cannot be called on $this->admin->getFormFieldDescriptions() (of type array<integer,object<Son...dDescriptionInterface>>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
455
        $targetAdmin->checkAccess('list')->shouldBeCalled();
456
        $fieldDescription->getTargetEntity()->willReturn(Foo::class);
457
        $fieldDescription->getName()->willReturn('barField');
458
        $fieldDescription->getAssociationAdmin()->willReturn($targetAdmin->reveal());
459
460
        $response = $this->controller->retrieveAutocompleteItemsAction($request);
461
462
        $this->isInstanceOf(Response::class, $response);
463
        $this->assertSame('application/json', $response->headers->get('Content-Type'));
464
        $this->assertSame('{"status":"KO","message":"Too short search string."}', $response->getContent());
465
    }
466
467
    public function testRetrieveAutocompleteItems(): void
468
    {
469
        $request = new Request([
470
            'admin_code' => 'foo.admin',
471
            'field' => 'barField',
472
            'q' => 'sonata',
473
        ], [], [], [], [], ['REQUEST_METHOD' => 'GET', 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);
474
475
        $this->configureFormConfig('barField');
476
477
        $datagrid = $this->configureAutocompleteItemsDatagrid();
478
        $filter = new FooFilter();
479
        $filter->initialize('foo');
480
481
        $datagrid->hasFilter('foo')->willReturn(true);
482
        $datagrid->getFilter('foo')->willReturn($filter);
483
        $datagrid->setValue('foo', null, 'sonata')->shouldBeCalled();
484
485
        $response = $this->controller->retrieveAutocompleteItemsAction($request);
486
487
        $this->isInstanceOf(Response::class, $response);
488
        $this->assertSame('application/json', $response->headers->get('Content-Type'));
489
        $this->assertSame('{"status":"OK","more":false,"items":[{"id":123,"label":"FOO"}]}', $response->getContent());
490
    }
491
492
    public function testRetrieveAutocompleteItemsComplexPropertyArray(): void
493
    {
494
        $request = new Request([
495
            'admin_code' => 'foo.admin',
496
            'field' => 'barField',
497
            'q' => 'sonata',
498
        ], [], [], [], [], ['REQUEST_METHOD' => 'GET', 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);
499
500
        $this->configureFormConfigComplexPropertyArray('barField');
501
        $datagrid = $this->configureAutocompleteItemsDatagrid();
502
503
        $filter = new FooFilter();
504
        $filter->initialize('entity.property');
505
506
        $datagrid->hasFilter('entity.property')->willReturn(true);
507
        $datagrid->getFilter('entity.property')->willReturn($filter);
508
        $filter2 = new FooFilter();
509
        $filter2->initialize('entity2.property2');
510
511
        $datagrid->hasFilter('entity2.property2')->willReturn(true);
512
        $datagrid->getFilter('entity2.property2')->willReturn($filter2);
513
514
        $datagrid->setValue('entity__property', null, 'sonata')->shouldBeCalled();
515
        $datagrid->setValue('entity2__property2', null, 'sonata')->shouldBeCalled();
516
517
        $response = $this->controller->retrieveAutocompleteItemsAction($request);
518
519
        $this->isInstanceOf(Response::class, $response);
520
        $this->assertSame('application/json', $response->headers->get('Content-Type'));
521
        $this->assertSame('{"status":"OK","more":false,"items":[{"id":123,"label":"FOO"}]}', $response->getContent());
522
    }
523
524
    public function testRetrieveAutocompleteItemsComplexProperty(): void
525
    {
526
        $request = new Request([
527
            'admin_code' => 'foo.admin',
528
            'field' => 'barField',
529
            'q' => 'sonata',
530
        ], [], [], [], [], ['REQUEST_METHOD' => 'GET', 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);
531
532
        $this->configureFormConfigComplexProperty('barField');
533
        $datagrid = $this->configureAutocompleteItemsDatagrid();
534
535
        $filter = new FooFilter();
536
        $filter->initialize('entity.property');
537
538
        $datagrid->hasFilter('entity.property')->willReturn(true);
539
        $datagrid->getFilter('entity.property')->willReturn($filter);
540
        $datagrid->setValue('entity__property', null, 'sonata')->shouldBeCalled();
541
542
        $response = $this->controller->retrieveAutocompleteItemsAction($request);
543
544
        $this->isInstanceOf(Response::class, $response);
545
        $this->assertSame('application/json', $response->headers->get('Content-Type'));
546
        $this->assertSame('{"status":"OK","more":false,"items":[{"id":123,"label":"FOO"}]}', $response->getContent());
547
    }
548
549
    private function configureAutocompleteItemsDatagrid()
550
    {
551
        $entity = new Foo();
552
553
        $targetAdmin = $this->prophesize(AbstractAdmin::class);
554
        $datagrid = $this->prophesize(DatagridInterface::class);
555
        $metadata = $this->prophesize(Metadata::class);
556
        $pager = $this->prophesize(Pager::class);
557
        $fieldDescription = $this->prophesize(FieldDescriptionInterface::class);
558
559
        $this->admin->getNewInstance()->willReturn($entity);
560
        $this->admin->setSubject($entity)->shouldBeCalled();
0 ignored issues
show
Bug introduced by
The method shouldBeCalled cannot be called on $this->admin->setSubject($entity) (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
561
        $this->admin->hasAccess('create')->willReturn(true);
0 ignored issues
show
Bug introduced by
The method willReturn cannot be called on $this->admin->hasAccess('create') (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
562
        $this->admin->getFormFieldDescription('barField')->willReturn($fieldDescription->reveal());
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sonata\AdminBundl...ldDescriptionInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
563
        $this->admin->getFormFieldDescriptions()->willReturn(null);
0 ignored issues
show
Bug introduced by
The method willReturn cannot be called on $this->admin->getFormFieldDescriptions() (of type array<integer,object<Son...dDescriptionInterface>>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
564
        $this->admin->id($entity)->willReturn(123);
0 ignored issues
show
Bug introduced by
The method willReturn cannot be called on $this->admin->id($entity) (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
565
        $targetAdmin->checkAccess('list')->shouldBeCalled();
566
        $targetAdmin->setFilterPersister(null)->shouldBeCalled();
567
        $targetAdmin->getDatagrid()->willReturn($datagrid->reveal());
568
        $targetAdmin->getObjectMetadata($entity)->willReturn($metadata->reveal());
569
        $metadata->getTitle()->willReturn('FOO');
570
571
        $datagrid->setValue('_per_page', null, 10)->shouldBeCalled();
572
        $datagrid->setValue('_page', null, 1)->shouldBeCalled();
573
        $datagrid->buildPager()->willReturn(null);
574
        $datagrid->getPager()->willReturn($pager->reveal());
575
        $pager->getResults()->willReturn([$entity]);
576
        $pager->isLastPage()->willReturn(true);
577
        $fieldDescription->getTargetEntity()->willReturn(Foo::class);
578
        $fieldDescription->getName()->willReturn('barField');
579
        $fieldDescription->getAssociationAdmin()->willReturn($targetAdmin->reveal());
580
581
        return $datagrid;
582
    }
583
584
    private function configureFormConfig($field, $disabled = false): void
585
    {
586
        $form = $this->prophesize(Form::class);
587
        $formType = $this->prophesize(Form::class);
588
        $formConfig = $this->prophesize(FormConfigInterface::class);
589
590
        $this->admin->getForm()->willReturn($form->reveal());
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Symfony\Component\Form\Form>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
591
        $form->get($field)->willReturn($formType->reveal());
592
        $formType->getConfig()->willReturn($formConfig->reveal());
593
        $formConfig->getAttribute('disabled')->willReturn($disabled);
594
        $formConfig->getAttribute('property')->willReturn('foo');
595
        $formConfig->getAttribute('callback')->willReturn(null);
596
        $formConfig->getAttribute('minimum_input_length')->willReturn(3);
597
        $formConfig->getAttribute('items_per_page')->willReturn(10);
598
        $formConfig->getAttribute('req_param_name_page_number')->willReturn('_page');
599
        $formConfig->getAttribute('to_string_callback')->willReturn(null);
600
        $formConfig->getAttribute('target_admin_access_action')->willReturn('list');
601
    }
602
603
    private function configureFormConfigComplexProperty($field): void
604
    {
605
        $form = $this->prophesize(Form::class);
606
        $formType = $this->prophesize(Form::class);
607
        $formConfig = $this->prophesize(FormConfigInterface::class);
608
609
        $this->admin->getForm()->willReturn($form->reveal());
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Symfony\Component\Form\Form>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
610
        $form->get($field)->willReturn($formType->reveal());
611
        $formType->getConfig()->willReturn($formConfig->reveal());
612
        $formConfig->getAttribute('disabled')->willReturn(false);
613
        $formConfig->getAttribute('property')->willReturn('entity.property');
614
        $formConfig->getAttribute('callback')->willReturn(null);
615
        $formConfig->getAttribute('minimum_input_length')->willReturn(3);
616
        $formConfig->getAttribute('items_per_page')->willReturn(10);
617
        $formConfig->getAttribute('req_param_name_page_number')->willReturn('_page');
618
        $formConfig->getAttribute('to_string_callback')->willReturn(null);
619
        $formConfig->getAttribute('target_admin_access_action')->willReturn('list');
620
    }
621
622
    private function configureFormConfigComplexPropertyArray($field): void
623
    {
624
        $form = $this->prophesize(Form::class);
625
        $formType = $this->prophesize(Form::class);
626
        $formConfig = $this->prophesize(FormConfigInterface::class);
627
628
        $this->admin->getForm()->willReturn($form->reveal());
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Symfony\Component\Form\Form>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
629
        $form->get($field)->willReturn($formType->reveal());
630
        $formType->getConfig()->willReturn($formConfig->reveal());
631
        $formConfig->getAttribute('disabled')->willReturn(false);
632
        $formConfig->getAttribute('property')->willReturn(['entity.property', 'entity2.property2']);
633
        $formConfig->getAttribute('callback')->willReturn(null);
634
        $formConfig->getAttribute('minimum_input_length')->willReturn(3);
635
        $formConfig->getAttribute('items_per_page')->willReturn(10);
636
        $formConfig->getAttribute('req_param_name_page_number')->willReturn('_page');
637
        $formConfig->getAttribute('to_string_callback')->willReturn(null);
638
        $formConfig->getAttribute('target_admin_access_action')->willReturn('list');
639
    }
640
641
    private function configureFormRenderer()
642
    {
643
        $runtime = $this->prophesize(FormRenderer::class);
644
645
        // Remove the condition when dropping sf < 3.2
646
        if (!method_exists(AppVariable::class, 'getToken')) {
647
            $extension = $this->prophesize(FormExtension::class);
648
649
            $this->twig->getExtension(FormExtension::class)->willReturn($extension->reveal());
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Twig_ExtensionInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
650
            $extension->initRuntime($this->twig->reveal())->shouldBeCalled();
0 ignored issues
show
Bug introduced by
The method reveal() does not seem to exist on object<Twig\Environment>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
651
            $extension->renderer = $runtime->reveal();
652
653
            return $runtime;
654
        }
655
656
        // Remove the condition when dropping sf < 3.4
657
        if (!method_exists(DebugCommand::class, 'getLoaderPaths')) {
658
            $twigRuntime = $this->prophesize(TwigRenderer::class);
659
660
            $this->twig->getRuntime(TwigRenderer::class)->willReturn($twigRuntime->reveal());
661
            $twigRuntime->setEnvironment($this->twig->reveal())->shouldBeCalled();
0 ignored issues
show
Bug introduced by
The method reveal() does not seem to exist on object<Twig\Environment>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
662
663
            return $twigRuntime;
664
        }
665
666
        $this->twig->getRuntime(FormRenderer::class)->willReturn($runtime->reveal());
667
668
        return $runtime;
669
    }
670
}
671