Completed
Pull Request — master (#6194)
by Vincent
05:04
created

testSetObjectFieldValueActionOnARelationField()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 52

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 52
rs 9.0472
c 0
b 0
f 0
cc 1
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 PHPUnit\Framework\TestCase;
17
use Prophecy\Argument;
18
use Prophecy\Prophecy\ObjectProphecy;
19
use Sonata\AdminBundle\Admin\AbstractAdmin;
20
use Sonata\AdminBundle\Admin\AdminHelper;
21
use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
22
use Sonata\AdminBundle\Admin\Pool;
23
use Sonata\AdminBundle\Controller\HelperController;
24
use Sonata\AdminBundle\Datagrid\DatagridInterface;
25
use Sonata\AdminBundle\Datagrid\Pager;
26
use Sonata\AdminBundle\Model\ModelManagerInterface;
27
use Sonata\AdminBundle\Object\MetadataInterface;
28
use Sonata\AdminBundle\Templating\TemplateRegistryInterface;
29
use Sonata\AdminBundle\Tests\Fixtures\Bundle\Entity\Foo;
30
use Sonata\AdminBundle\Tests\Fixtures\Filter\FooFilter;
31
use Sonata\AdminBundle\Twig\Extension\SonataAdminExtension;
32
use Symfony\Component\DependencyInjection\ContainerInterface;
33
use Symfony\Component\Form\Form;
34
use Symfony\Component\Form\FormBuilder;
35
use Symfony\Component\Form\FormConfigInterface;
36
use Symfony\Component\Form\FormRenderer;
37
use Symfony\Component\Form\FormView;
38
use Symfony\Component\HttpFoundation\Request;
39
use Symfony\Component\HttpFoundation\Response;
40
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
41
use Symfony\Component\PropertyAccess\PropertyAccessor;
42
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
43
use Symfony\Component\Validator\ConstraintViolation;
44
use Symfony\Component\Validator\ConstraintViolationList;
45
use Symfony\Component\Validator\Validator\ValidatorInterface;
46
use Symfony\Contracts\Translation\TranslatorInterface;
47
use Twig\Environment;
48
use Twig\Template;
49
use Twig\TemplateWrapper;
50
51
/**
52
 * @group legacy
53
 */
54
class HelperControllerTest extends TestCase
55
{
56
    /**
57
     * @var Pool
58
     */
59
    private $pool;
60
61
    /**
62
     * @var Environment
63
     */
64
    private $twig;
65
66
    /**
67
     * @var AdminHelper
68
     */
69
    private $helper;
70
71
    /**
72
     * @var ValidatorInterface
73
     */
74
    private $validator;
75
76
    /**
77
     * @var AbstractAdmin
78
     */
79
    private $admin;
80
81
    /**
82
     * @var HelperController
83
     */
84
    private $controller;
85
86
    /**
87
     * {@inheritdoc}
88
     */
89
    protected function setUp(): void
90
    {
91
        $this->pool = $this->prophesize(Pool::class);
92
        $this->twig = $this->prophesize(Environment::class);
93
        $this->helper = $this->prophesize(AdminHelper::class);
94
        $this->validator = $this->prophesize(ValidatorInterface::class);
95
        $this->admin = $this->prophesize(AbstractAdmin::class);
96
97
        $this->pool->getInstance(Argument::any())->willReturn($this->admin->reveal());
98
        $this->admin->setRequest(Argument::type(Request::class))->shouldBeCalled();
99
100
        $this->controller = new HelperController(
0 ignored issues
show
Deprecated Code introduced by
The class Sonata\AdminBundle\Controller\HelperController has been deprecated with message: since sonata-project/admin-bundle 3.38.0, to be removed in 4.0. Use actions inside Sonata\AdminBundle\Action instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
101
            $this->twig->reveal(),
102
            $this->pool->reveal(),
103
            $this->helper->reveal(),
104
            $this->validator->reveal()
105
        );
106
    }
107
108
    public function testGetShortObjectDescriptionActionInvalidAdmin(): void
109
    {
110
        $this->expectException(NotFoundHttpException::class);
111
112
        $request = new Request([
113
            'code' => 'sonata.post.admin',
114
            'objectId' => 42,
115
            'uniqid' => 'asdasd123',
116
        ]);
117
118
        $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...
119
        $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...
120
121
        $this->controller->getShortObjectDescriptionAction($request);
122
    }
123
124
    public function testGetShortObjectDescriptionActionObjectDoesNotExist(): void
125
    {
126
        $this->expectException(\RuntimeException::class);
127
        $this->expectExceptionMessage('Invalid format');
128
129
        $request = new Request([
130
            'code' => 'sonata.post.admin',
131
            'objectId' => 42,
132
            'uniqid' => 'asdasd123',
133
        ]);
134
135
        $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...
136
        $this->admin->getObject(42)->willReturn(false);
137
138
        $this->controller->getShortObjectDescriptionAction($request);
139
    }
140
141
    public function testGetShortObjectDescriptionActionEmptyObjectId(): void
142
    {
143
        $request = new Request([
144
            'code' => 'sonata.post.admin',
145
            'objectId' => '',
146
            'uniqid' => 'asdasd123',
147
            '_format' => 'html',
148
        ]);
149
150
        $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...
151
        $this->admin->getObject(null)->willReturn(false);
152
153
        $response = $this->controller->getShortObjectDescriptionAction($request);
154
155
        $this->assertInstanceOf(Response::class, $response);
156
    }
157
158
    public function testGetShortObjectDescriptionActionObject(): void
159
    {
160
        $request = new Request([
161
            'code' => 'sonata.post.admin',
162
            'objectId' => 42,
163
            'uniqid' => 'asdasd123',
164
            '_format' => 'html',
165
        ]);
166
        $object = new AdminControllerHelper_Foo();
167
168
        $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...
169
        $this->admin->getObject(42)->willReturn($object);
170
        $this->admin->getTemplate('short_object_description')->willReturn('template');
0 ignored issues
show
Bug introduced by
The method getTemplate() does not exist on Sonata\AdminBundle\Admin\AbstractAdmin. Did you maybe mean getTemplateRegistry()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
171
        $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...
172
        $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...
173
            '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...
174
            'description' => 'bar',
175
            'object' => $object,
176
            'link_parameters' => [],
177
        ])->willReturn('renderedTemplate');
178
179
        $response = $this->controller->getShortObjectDescriptionAction($request);
180
181
        $this->assertSame('renderedTemplate', $response->getContent());
182
    }
183
184
    public function testSetObjectFieldValueAction(): void
185
    {
186
        $object = new AdminControllerHelper_Foo();
187
        $request = new Request([
188
            'code' => 'sonata.post.admin',
189
            'objectId' => 42,
190
            'field' => 'enabled',
191
            'value' => 1,
192
            'context' => 'list',
193
        ], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_POST, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);
194
195
        $fieldDescription = $this->prophesize(FieldDescriptionInterface::class);
196
        $pool = $this->prophesize(Pool::class);
197
        $template = $this->prophesize(Template::class);
198
        $template->render(Argument::cetera())->willReturn('some value');
199
        $translator = $this->prophesize(TranslatorInterface::class);
200
        $propertyAccessor = new PropertyAccessor();
201
        $templateRegistry = $this->prophesize(TemplateRegistryInterface::class);
202
        $container = $this->prophesize(ContainerInterface::class);
203
204
        $this->admin->getObject(42)->willReturn($object);
205
        $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...
206
        $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...
207
        $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...
208
        $this->admin->update($object)->shouldBeCalled();
0 ignored issues
show
Documentation introduced by
$object is of type object<Sonata\AdminBundl...inControllerHelper_Foo>, but the function expects a object<Sonata\AdminBundle\Admin\object>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
209
        // NEXT_MAJOR: Remove this line
210
        $this->admin->getTemplate('base_list_field')->willReturn('admin_template');
0 ignored issues
show
Bug introduced by
The method getTemplate() does not exist on Sonata\AdminBundle\Admin\AbstractAdmin. Did you maybe mean getTemplateRegistry()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
211
        $templateRegistry->getTemplate('base_list_field')->willReturn('admin_template');
212
        $container->get('sonata.post.admin.template_registry')->willReturn($templateRegistry->reveal());
213
        $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...
214
        $this->twig->getExtension(SonataAdminExtension::class)->willReturn(
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Twig\Extension\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...
215
            new SonataAdminExtension($pool->reveal(), null, $translator->reveal(), $container->reveal())
216
        );
217
        $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...
218
        $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...
219
        $fieldDescription->getOption('editable')->willReturn(true);
220
        $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...
221
        $fieldDescription->getType()->willReturn('boolean');
222
        $fieldDescription->getTemplate()->willReturn(false);
223
        $fieldDescription->getValue(Argument::cetera())->willReturn('some value');
224
        $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...
225
226
        $response = $this->controller->setObjectFieldValueAction($request);
227
228
        $this->assertSame(Response::HTTP_OK, $response->getStatusCode());
229
    }
230
231
    public function testSetObjectFieldValueActionOnARelationField(): void
232
    {
233
        $object = new AdminControllerHelper_Foo();
234
        $associationObject = new AdminControllerHelper_Bar();
235
        $request = new Request([
236
            'code' => 'sonata.post.admin',
237
            'objectId' => 42,
238
            'field' => 'bar',
239
            'value' => 1,
240
            'context' => 'list',
241
        ], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_POST, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);
242
243
        $fieldDescription = $this->prophesize(FieldDescriptionInterface::class);
244
        $modelManager = $this->prophesize(ModelManagerInterface::class);
245
        $template = $this->prophesize(Template::class);
246
        $template->render(Argument::cetera())->willReturn('some value');
247
        $translator = $this->prophesize(TranslatorInterface::class);
248
        $propertyAccessor = new PropertyAccessor();
249
        $templateRegistry = $this->prophesize(TemplateRegistryInterface::class);
250
        $container = $this->prophesize(ContainerInterface::class);
251
252
        $this->admin->getObject(42)->willReturn($object);
253
        $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...
254
        $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...
255
        $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...
256
        $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...
257
        $this->admin->update($object)->shouldBeCalled();
0 ignored issues
show
Documentation introduced by
$object is of type object<Sonata\AdminBundl...inControllerHelper_Foo>, but the function expects a object<Sonata\AdminBundle\Admin\object>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
258
        $container->get('sonata.post.admin.template_registry')->willReturn($templateRegistry->reveal());
259
        // NEXT_MAJOR: Remove this line
260
        $this->admin->getTemplate('base_list_field')->willReturn('admin_template');
0 ignored issues
show
Bug introduced by
The method getTemplate() does not exist on Sonata\AdminBundle\Admin\AbstractAdmin. Did you maybe mean getTemplateRegistry()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
261
        $templateRegistry->getTemplate('base_list_field')->willReturn('admin_template');
262
        $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...
263
        $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...
264
        $this->twig->getExtension(SonataAdminExtension::class)->willReturn(
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Twig\Extension\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...
265
            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...
266
        );
267
        $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...
268
        $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...
269
        $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...
270
        $fieldDescription->getType()->willReturn('choice');
271
        $fieldDescription->getOption('editable')->willReturn(true);
272
        $fieldDescription->getOption('class')->willReturn(AdminControllerHelper_Bar::class);
273
        $fieldDescription->getTargetModel()->willReturn(AdminControllerHelper_Bar::class);
274
        $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...
275
        $fieldDescription->getTemplate()->willReturn('field_template');
276
        $fieldDescription->getValue(Argument::cetera())->willReturn('some value');
277
        $modelManager->find(\get_class($associationObject), 1)->willReturn($associationObject);
278
279
        $response = $this->controller->setObjectFieldValueAction($request);
280
281
        $this->assertSame(Response::HTTP_OK, $response->getStatusCode());
282
    }
283
284
    public function testAppendFormFieldElementAction(): void
285
    {
286
        $object = new AdminControllerHelper_Foo();
287
        $request = new Request([
288
            'code' => 'sonata.post.admin',
289
            'objectId' => 42,
290
            'field' => 'enabled',
291
            'value' => 1,
292
            'context' => 'list',
293
        ], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_POST]);
294
295
        $modelManager = $this->prophesize(ModelManagerInterface::class);
296
        $formView = new FormView();
297
        $form = $this->prophesize(Form::class);
298
299
        $renderer = $this->configureFormRenderer();
300
301
        $this->admin->getObject(42)->willReturn($object);
302
        $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...
303
        $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...
304
        $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<integer,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...
305
        $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...
Documentation introduced by
$object is of type object<Sonata\AdminBundl...inControllerHelper_Foo>, but the function expects a object<Sonata\AdminBundle\Admin\object>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Bug introduced by
The method willReturn cannot be called on $this->helper->appendFor...eveal(), $object, null) (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...
306
            $this->prophesize(FieldDescriptionInterface::class),
307
            $form->reveal(),
308
        ]);
309
        $this->helper->getChildFormView($formView, null)
310
            ->willReturn($formView);
311
        $modelManager->find(\get_class($object), 42)->willReturn($object);
312
        $form->createView()->willReturn($formView);
313
        $renderer->setTheme($formView, $formView)->shouldBeCalled();
314
        $renderer->searchAndRenderBlock($formView, 'widget')->willReturn('block');
315
316
        $response = $this->controller->appendFormFieldElementAction($request);
317
318
        $this->assertInstanceOf(Response::class, $response);
319
        $this->assertSame($response->getContent(), 'block');
320
    }
321
322
    public function testRetrieveFormFieldElementAction(): void
323
    {
324
        $object = new AdminControllerHelper_Foo();
325
        $request = new Request([
326
            'code' => 'sonata.post.admin',
327
            'objectId' => 42,
328
            'field' => 'enabled',
329
            'value' => 1,
330
            'context' => 'list',
331
        ], [], [], [], [], ['REQUEST_METHOD' => 'POST']);
332
333
        $modelManager = $this->prophesize(ModelManagerInterface::class);
334
        $formView = new FormView();
335
        $form = $this->prophesize(Form::class);
336
        $formBuilder = $this->prophesize(FormBuilder::class);
337
338
        $renderer = $this->configureFormRenderer();
339
340
        $this->admin->getObject(42)->willReturn($object);
341
        $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...
342
        $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...
343
        $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<integer,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...
344
        $this->admin->getFormBuilder()->willReturn($formBuilder->reveal());
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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...
345
        $this->helper->getChildFormView($formView, null)
346
            ->willReturn($formView);
347
        $modelManager->find(\get_class($object), 42)->willReturn($object);
348
        $form->setData($object)->shouldBeCalled();
349
        $form->handleRequest($request)->shouldBeCalled();
350
        $form->createView()->willReturn($formView);
351
        $formBuilder->getForm()->willReturn($form->reveal());
352
        $renderer->setTheme($formView, $formView)->shouldBeCalled();
353
        $renderer->searchAndRenderBlock($formView, 'widget')->willReturn('block');
354
355
        $response = $this->controller->retrieveFormFieldElementAction($request);
356
357
        $this->assertInstanceOf(Response::class, $response);
358
        $this->assertSame($response->getContent(), 'block');
359
    }
360
361
    public function testSetObjectFieldValueActionWithViolations(): void
362
    {
363
        $bar = new AdminControllerHelper_Bar();
364
        $object = new AdminControllerHelper_Foo();
365
        $object->setBar($bar);
366
        $request = new Request([
367
            'code' => 'sonata.post.admin',
368
            'objectId' => 42,
369
            'field' => 'bar.enabled',
370
            'value' => 1,
371
            'context' => 'list',
372
        ], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_POST, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);
373
374
        $fieldDescription = $this->prophesize(FieldDescriptionInterface::class);
375
        $propertyAccessor = new PropertyAccessor();
376
377
        $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...
378
        $this->admin->getObject(42)->willReturn($object);
379
        $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...
380
        $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...
381
        $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...
382
            new ConstraintViolation('error1', null, [], null, 'enabled', null),
383
            new ConstraintViolation('error2', null, [], null, 'enabled', null),
384
        ]));
385
        $fieldDescription->getOption('editable')->willReturn(true);
386
        $fieldDescription->getType()->willReturn('boolean');
387
388
        $response = $this->controller->setObjectFieldValueAction($request);
389
390
        $this->assertSame(Response::HTTP_BAD_REQUEST, $response->getStatusCode());
391
        $this->assertSame(json_encode("error1\nerror2"), $response->getContent());
392
    }
393
394
    public function testRetrieveAutocompleteItemsActionNotGranted(): void
395
    {
396
        $this->expectException(AccessDeniedException::class);
397
398
        $request = new Request([
399
            'admin_code' => 'foo.admin',
400
        ], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_GET, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);
401
402
        $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...
403
        $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...
404
405
        $this->controller->retrieveAutocompleteItemsAction($request);
406
    }
407
408
    public function testRetrieveAutocompleteItemsActionDisabledFormelememt(): void
409
    {
410
        $this->expectException(AccessDeniedException::class);
411
        $this->expectExceptionMessage('Autocomplete list can`t be retrieved because the form element is disabled or read_only.');
412
413
        $object = new AdminControllerHelper_Foo();
414
        $request = new Request([
415
            'admin_code' => 'foo.admin',
416
            'field' => 'barField',
417
        ], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_GET, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);
418
419
        $fieldDescription = $this->prophesize(FieldDescriptionInterface::class);
420
421
        $this->configureFormConfig('barField', true);
422
423
        $this->admin->getNewInstance()->willReturn($object);
424
        $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...
425
        $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...
426
        $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...
427
        $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...
428
429
        $fieldDescription->getTargetModel()->willReturn(Foo::class);
430
        $fieldDescription->getName()->willReturn('barField');
431
432
        $this->controller->retrieveAutocompleteItemsAction($request);
433
    }
434
435
    public function testRetrieveAutocompleteItemsTooShortSearchString(): void
436
    {
437
        $object = new AdminControllerHelper_Foo();
438
        $request = new Request([
439
            'admin_code' => 'foo.admin',
440
            'field' => 'barField',
441
            'q' => 'so',
442
        ], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_GET, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);
443
444
        $targetAdmin = $this->prophesize(AbstractAdmin::class);
445
        $fieldDescription = $this->prophesize(FieldDescriptionInterface::class);
446
447
        $this->configureFormConfig('barField');
448
449
        $this->admin->getNewInstance()->willReturn($object);
450
        $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...
451
        $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...
452
        $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...
453
        $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...
454
        $targetAdmin->checkAccess('list')->willReturn(null);
455
        $fieldDescription->getTargetModel()->willReturn(Foo::class);
456
        $fieldDescription->getName()->willReturn('barField');
457
        $fieldDescription->getAssociationAdmin()->willReturn($targetAdmin->reveal());
458
459
        $response = $this->controller->retrieveAutocompleteItemsAction($request);
460
461
        $this->assertInstanceOf(Response::class, $response);
462
        $this->assertSame('application/json', $response->headers->get('Content-Type'));
463
        $this->assertSame('{"status":"KO","message":"Too short search string."}', $response->getContent());
464
    }
465
466
    public function testRetrieveAutocompleteItems(): void
467
    {
468
        $request = new Request([
469
            'admin_code' => 'foo.admin',
470
            'field' => 'barField',
471
            'q' => 'sonata',
472
        ], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_GET, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);
473
474
        $this->configureFormConfig('barField');
475
476
        $datagrid = $this->configureAutocompleteItemsDatagrid();
477
        $filter = new FooFilter();
478
        $filter->initialize('foo');
479
480
        $datagrid->hasFilter('foo')->willReturn(true);
481
        $datagrid->getFilter('foo')->willReturn($filter);
482
        $datagrid->setValue('foo', null, 'sonata')->shouldBeCalled();
483
484
        $response = $this->controller->retrieveAutocompleteItemsAction($request);
485
486
        $this->assertInstanceOf(Response::class, $response);
487
        $this->assertSame('application/json', $response->headers->get('Content-Type'));
488
        $this->assertSame('{"status":"OK","more":false,"items":[{"id":123,"label":"FOO"}]}', $response->getContent());
489
    }
490
491
    public function testRetrieveAutocompleteItemsComplexPropertyArray(): void
492
    {
493
        $request = new Request([
494
            'admin_code' => 'foo.admin',
495
            'field' => 'barField',
496
            'q' => 'sonata',
497
        ], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_GET, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);
498
499
        $this->configureFormConfigComplexPropertyArray('barField');
500
        $datagrid = $this->configureAutocompleteItemsDatagrid();
501
502
        $filter = new FooFilter();
503
        $filter->initialize('entity.property');
504
505
        $datagrid->hasFilter('entity.property')->willReturn(true);
506
        $datagrid->getFilter('entity.property')->willReturn($filter);
507
        $filter2 = new FooFilter();
508
        $filter2->initialize('entity2.property2');
509
510
        $datagrid->hasFilter('entity2.property2')->willReturn(true);
511
        $datagrid->getFilter('entity2.property2')->willReturn($filter2);
512
513
        $datagrid->setValue('entity__property', null, 'sonata')->shouldBeCalled();
514
        $datagrid->setValue('entity2__property2', null, 'sonata')->shouldBeCalled();
515
516
        $response = $this->controller->retrieveAutocompleteItemsAction($request);
517
518
        $this->assertInstanceOf(Response::class, $response);
519
        $this->assertSame('application/json', $response->headers->get('Content-Type'));
520
        $this->assertSame('{"status":"OK","more":false,"items":[{"id":123,"label":"FOO"}]}', $response->getContent());
521
    }
522
523
    public function testRetrieveAutocompleteItemsComplexProperty(): void
524
    {
525
        $request = new Request([
526
            'admin_code' => 'foo.admin',
527
            'field' => 'barField',
528
            'q' => 'sonata',
529
        ], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_GET, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);
530
531
        $this->configureFormConfigComplexProperty('barField');
532
        $datagrid = $this->configureAutocompleteItemsDatagrid();
533
534
        $filter = new FooFilter();
535
        $filter->initialize('entity.property');
536
537
        $datagrid->hasFilter('entity.property')->willReturn(true);
538
        $datagrid->getFilter('entity.property')->willReturn($filter);
539
        $datagrid->setValue('entity__property', null, 'sonata')->shouldBeCalled();
540
541
        $response = $this->controller->retrieveAutocompleteItemsAction($request);
542
543
        $this->assertInstanceOf(Response::class, $response);
544
        $this->assertSame('application/json', $response->headers->get('Content-Type'));
545
        $this->assertSame('{"status":"OK","more":false,"items":[{"id":123,"label":"FOO"}]}', $response->getContent());
546
    }
547
548
    private function configureAutocompleteItemsDatagrid(): ObjectProphecy
549
    {
550
        $model = new Foo();
551
552
        $targetAdmin = $this->prophesize(AbstractAdmin::class);
553
        $datagrid = $this->prophesize(DatagridInterface::class);
554
        $metadata = $this->prophesize(MetadataInterface::class);
555
        $pager = $this->prophesize(Pager::class);
556
        $fieldDescription = $this->prophesize(FieldDescriptionInterface::class);
557
558
        $this->admin->getNewInstance()->willReturn($model);
559
        $this->admin->setSubject($model)->shouldBeCalled();
0 ignored issues
show
Bug introduced by
The method shouldBeCalled cannot be called on $this->admin->setSubject($model) (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...
560
        $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...
561
        $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...
562
        $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...
563
        $this->admin->id($model)->willReturn(123);
0 ignored issues
show
Bug introduced by
The method willReturn cannot be called on $this->admin->id($model) (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...
564
        $targetAdmin->checkAccess('list')->shouldBeCalled();
565
        $targetAdmin->setFilterPersister(null)->shouldBeCalled();
566
        $targetAdmin->getDatagrid()->willReturn($datagrid->reveal());
567
        $targetAdmin->getObjectMetadata($model)->willReturn($metadata->reveal());
568
        $metadata->getTitle()->willReturn('FOO');
569
570
        $datagrid->setValue('_per_page', null, 10)->shouldBeCalled();
571
        $datagrid->setValue('_page', null, 1)->shouldBeCalled();
572
        $datagrid->buildPager()->willReturn(null);
573
        $datagrid->getPager()->willReturn($pager->reveal());
574
        $pager->getResults()->willReturn([$model]);
575
        $pager->isLastPage()->willReturn(true);
576
        $fieldDescription->getTargetModel()->willReturn(Foo::class);
577
        $fieldDescription->getName()->willReturn('barField');
578
        $fieldDescription->getAssociationAdmin()->willReturn($targetAdmin->reveal());
579
580
        return $datagrid;
581
    }
582
583
    private function configureFormConfig(string $field, bool $disabled = false): void
584
    {
585
        $form = $this->prophesize(Form::class);
586
        $formType = $this->prophesize(Form::class);
587
        $formConfig = $this->prophesize(FormConfigInterface::class);
588
589
        $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...
590
        $form->get($field)->willReturn($formType->reveal());
591
        $formType->getConfig()->willReturn($formConfig->reveal());
592
        $formConfig->getAttribute('disabled')->willReturn($disabled);
593
        $formConfig->getAttribute('property')->willReturn('foo');
594
        $formConfig->getAttribute('callback')->willReturn(null);
595
        $formConfig->getAttribute('minimum_input_length')->willReturn(3);
596
        $formConfig->getAttribute('items_per_page')->willReturn(10);
597
        $formConfig->getAttribute('req_param_name_page_number')->willReturn('_page');
598
        $formConfig->getAttribute('to_string_callback')->willReturn(null);
599
        $formConfig->getAttribute('target_admin_access_action')->willReturn('list');
600
    }
601
602
    private function configureFormConfigComplexProperty(string $field): void
603
    {
604
        $form = $this->prophesize(Form::class);
605
        $formType = $this->prophesize(Form::class);
606
        $formConfig = $this->prophesize(FormConfigInterface::class);
607
608
        $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...
609
        $form->get($field)->willReturn($formType->reveal());
610
        $formType->getConfig()->willReturn($formConfig->reveal());
611
        $formConfig->getAttribute('disabled')->willReturn(false);
612
        $formConfig->getAttribute('property')->willReturn('entity.property');
613
        $formConfig->getAttribute('callback')->willReturn(null);
614
        $formConfig->getAttribute('minimum_input_length')->willReturn(3);
615
        $formConfig->getAttribute('items_per_page')->willReturn(10);
616
        $formConfig->getAttribute('req_param_name_page_number')->willReturn('_page');
617
        $formConfig->getAttribute('to_string_callback')->willReturn(null);
618
        $formConfig->getAttribute('target_admin_access_action')->willReturn('list');
619
    }
620
621
    private function configureFormConfigComplexPropertyArray(string $field): void
622
    {
623
        $form = $this->prophesize(Form::class);
624
        $formType = $this->prophesize(Form::class);
625
        $formConfig = $this->prophesize(FormConfigInterface::class);
626
627
        $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...
628
        $form->get($field)->willReturn($formType->reveal());
629
        $formType->getConfig()->willReturn($formConfig->reveal());
630
        $formConfig->getAttribute('disabled')->willReturn(false);
631
        $formConfig->getAttribute('property')->willReturn(['entity.property', 'entity2.property2']);
632
        $formConfig->getAttribute('callback')->willReturn(null);
633
        $formConfig->getAttribute('minimum_input_length')->willReturn(3);
634
        $formConfig->getAttribute('items_per_page')->willReturn(10);
635
        $formConfig->getAttribute('req_param_name_page_number')->willReturn('_page');
636
        $formConfig->getAttribute('to_string_callback')->willReturn(null);
637
        $formConfig->getAttribute('target_admin_access_action')->willReturn('list');
638
    }
639
640
    private function configureFormRenderer()
641
    {
642
        $runtime = $this->prophesize(FormRenderer::class);
643
644
        $this->twig->getRuntime(FormRenderer::class)->willReturn($runtime->reveal());
645
646
        return $runtime;
647
    }
648
}
649