Completed
Push — master ( 78d40f...28dfb2 )
by Jordi Sala
02:47
created

testSetObjectFieldValueAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 44
rs 9.216
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\Action;
15
16
use PHPUnit\Framework\TestCase;
17
use Prophecy\Argument;
18
use Sonata\AdminBundle\Action\GetShortObjectDescriptionAction;
19
use Sonata\AdminBundle\Action\SetObjectFieldValueAction;
20
use Sonata\AdminBundle\Admin\AbstractAdmin;
21
use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
22
use Sonata\AdminBundle\Admin\Pool;
23
use Sonata\AdminBundle\Model\ModelManagerInterface;
24
use Sonata\AdminBundle\Templating\TemplateRegistryInterface;
25
use Sonata\AdminBundle\Twig\Extension\SonataAdminExtension;
26
use Symfony\Component\DependencyInjection\ContainerInterface;
27
use Symfony\Component\HttpFoundation\Request;
28
use Symfony\Component\HttpFoundation\Response;
29
use Symfony\Component\PropertyAccess\PropertyAccessor;
30
use Symfony\Component\Validator\ConstraintViolation;
31
use Symfony\Component\Validator\ConstraintViolationList;
32
use Symfony\Component\Validator\Validator\ValidatorInterface;
33
use Symfony\Contracts\Translation\TranslatorInterface;
34
use Twig\Environment;
35
use Twig\Loader\ArrayLoader;
36
37
final class SetObjectFieldValueActionTest extends TestCase
38
{
39
    /**
40
     * @var Pool
41
     */
42
    private $pool;
43
44
    /**
45
     * @var Environment
46
     */
47
    private $twig;
48
49
    /**
50
     * @var GetShortObjectDescriptionAction
51
     */
52
    private $action;
53
54
    /**
55
     * @var AbstractAdmin
56
     */
57
    private $admin;
58
59
    /**
60
     * @var ValidatorInterface
61
     */
62
    private $validator;
63
64
    protected function setUp(): void
65
    {
66
        $this->twig = new Environment(new ArrayLoader([
67
            'admin_template' => 'renderedTemplate',
68
            'field_template' => 'renderedTemplate',
69
        ]));
70
        $this->pool = $this->prophesize(Pool::class);
71
        $this->admin = $this->prophesize(AbstractAdmin::class);
72
        $this->pool->getInstance(Argument::any())->willReturn($this->admin->reveal());
73
        $this->admin->setRequest(Argument::type(Request::class))->shouldBeCalled();
74
        $this->validator = $this->prophesize(ValidatorInterface::class);
75
        $this->action = new SetObjectFieldValueAction(
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Sonata\AdminBundle\...s->validator->reveal()) of type object<Sonata\AdminBundl...ObjectFieldValueAction> is incompatible with the declared type object<Sonata\AdminBundl...bjectDescriptionAction> of property $action.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
76
            $this->twig,
77
            $this->pool->reveal(),
78
            $this->validator->reveal()
79
        );
80
    }
81
82
    public function testSetObjectFieldValueAction(): void
83
    {
84
        $object = new Foo();
85
        $request = new Request([
86
            'code' => 'sonata.post.admin',
87
            'objectId' => 42,
88
            'field' => 'enabled',
89
            'value' => 1,
90
            'context' => 'list',
91
        ], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_POST, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);
92
93
        $fieldDescription = $this->prophesize(FieldDescriptionInterface::class);
94
        $pool = $this->prophesize(Pool::class);
95
        $translator = $this->prophesize(TranslatorInterface::class);
96
        $propertyAccessor = new PropertyAccessor();
97
        $templateRegistry = $this->prophesize(TemplateRegistryInterface::class);
98
        $container = $this->prophesize(ContainerInterface::class);
99
100
        $this->admin->getObject(42)->willReturn($object);
101
        $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...
102
        $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...
103
        $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...
104
        $this->admin->update($object)->shouldBeCalled();
0 ignored issues
show
Documentation introduced by
$object is of type object<Sonata\AdminBundle\Tests\Action\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...
105
        $templateRegistry->getTemplate('base_list_field')->willReturn('admin_template');
106
        $container->get('sonata.post.admin.template_registry')->willReturn($templateRegistry->reveal());
107
        $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...
108
        $this->twig->addExtension(new SonataAdminExtension(
109
            $pool->reveal(),
110
            null,
111
            $translator->reveal(),
112
            $container->reveal()
113
        ));
114
        $fieldDescription->getOption('editable')->willReturn(true);
115
        $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...
116
        $fieldDescription->getType()->willReturn('boolean');
117
        $fieldDescription->getTemplate()->willReturn('field_template');
118
        $fieldDescription->getValue(Argument::cetera())->willReturn('some value');
119
120
        $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...
121
122
        $response = ($this->action)($request);
123
124
        $this->assertSame(Response::HTTP_OK, $response->getStatusCode());
125
    }
126
127
    public function getTimeZones(): iterable
128
    {
129
        $default = new \DateTimeZone(date_default_timezone_get());
130
        $custom = new \DateTimeZone('Europe/Rome');
131
132
        return [
133
            'empty timezone' => [null, $default],
134
            'disabled timezone' => [false, $default],
135
            'default timezone by name' => [$default->getName(), $default],
136
            'default timezone by object' => [$default, $default],
137
            'custom timezone by name' => [$custom->getName(), $custom],
138
            'custom timezone by object' => [$custom, $custom],
139
        ];
140
    }
141
142
    /**
143
     * @dataProvider getTimeZones
144
     */
145
    public function testSetObjectFieldValueActionWithDate($timezone, \DateTimeZone $expectedTimezone): void
146
    {
147
        $object = new Bafoo();
148
        $request = new Request([
149
            'code' => 'sonata.post.admin',
150
            'objectId' => 42,
151
            'field' => 'dateProp',
152
            'value' => '2020-12-12',
153
            'context' => 'list',
154
        ], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_POST, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);
155
156
        $fieldDescription = $this->prophesize(FieldDescriptionInterface::class);
157
        $pool = $this->prophesize(Pool::class);
158
        $translator = $this->prophesize(TranslatorInterface::class);
159
        $propertyAccessor = new PropertyAccessor();
160
        $templateRegistry = $this->prophesize(TemplateRegistryInterface::class);
161
        $container = $this->prophesize(ContainerInterface::class);
162
163
        $this->admin->getObject(42)->willReturn($object);
164
        $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...
165
        $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...
166
        $this->admin->getListFieldDescription('dateProp')->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...
167
        $this->admin->update($object)->shouldBeCalled();
0 ignored issues
show
Documentation introduced by
$object is of type object<Sonata\AdminBundle\Tests\Action\Bafoo>, 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...
168
169
        $templateRegistry->getTemplate('base_list_field')->willReturn('admin_template');
170
        $container->get('sonata.post.admin.template_registry')->willReturn($templateRegistry->reveal());
171
        $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...
172
        $this->twig->addExtension(new SonataAdminExtension(
173
            $pool->reveal(),
174
            null,
175
            $translator->reveal(),
176
            $container->reveal()
177
        ));
178
        $fieldDescription->getOption('editable')->willReturn(true);
179
        $fieldDescription->getOption('timezone')->willReturn($timezone);
180
        $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...
181
        $fieldDescription->getType()->willReturn('date');
182
        $fieldDescription->getTemplate()->willReturn('field_template');
183
        $fieldDescription->getValue(Argument::cetera())->willReturn('some value');
184
185
        $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...
186
187
        $response = ($this->action)($request);
188
189
        $this->assertSame(Response::HTTP_OK, $response->getStatusCode());
190
191
        $defaultTimezone = new \DateTimeZone(date_default_timezone_get());
192
        $expectedDate = new \DateTime($request->query->get('value'), $expectedTimezone);
193
        $expectedDate->setTimezone($defaultTimezone);
194
195
        $this->assertInstanceOf(\DateTime::class, $object->getDateProp());
196
        $this->assertSame($expectedDate->format('Y-m-d'), $object->getDateProp()->format('Y-m-d'));
197
        $this->assertSame($defaultTimezone->getName(), $object->getDateProp()->getTimezone()->getName());
198
    }
199
200
    public function testSetObjectFieldValueActionOnARelationField(): void
201
    {
202
        $object = new Baz();
203
        $associationObject = new Bar();
204
        $request = new Request([
205
            'code' => 'sonata.post.admin',
206
            'objectId' => 42,
207
            'field' => 'bar',
208
            'value' => 1,
209
            'context' => 'list',
210
        ], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_POST, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);
211
212
        $fieldDescription = $this->prophesize(FieldDescriptionInterface::class);
213
        $modelManager = $this->prophesize(ModelManagerInterface::class);
214
        $translator = $this->prophesize(TranslatorInterface::class);
215
        $propertyAccessor = new PropertyAccessor();
216
        $templateRegistry = $this->prophesize(TemplateRegistryInterface::class);
217
        $container = $this->prophesize(ContainerInterface::class);
218
219
        $this->admin->getObject(42)->willReturn($object);
220
        $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...
221
        $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...
222
        $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...
223
        $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...
224
        $this->admin->update($object)->shouldBeCalled();
0 ignored issues
show
Documentation introduced by
$object is of type object<Sonata\AdminBundle\Tests\Action\Baz>, 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...
225
        $container->get('sonata.post.admin.template_registry')->willReturn($templateRegistry->reveal());
226
        $templateRegistry->getTemplate('base_list_field')->willReturn('admin_template');
227
        $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...
228
        $this->twig->addExtension(new SonataAdminExtension(
229
            $this->pool->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...
230
            null,
231
            $translator->reveal(),
232
            $container->reveal()
233
        ));
234
        $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...
235
        $fieldDescription->getType()->willReturn('choice');
236
        $fieldDescription->getOption('editable')->willReturn(true);
237
        $fieldDescription->getOption('class')->willReturn(Bar::class);
238
        $fieldDescription->getTargetModel()->willReturn(Bar::class);
239
        $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...
240
        $fieldDescription->getTemplate()->willReturn('field_template');
241
        $fieldDescription->getValue(Argument::cetera())->willReturn('some value');
242
        $modelManager->find(\get_class($associationObject), 1)->willReturn($associationObject);
243
244
        $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...
245
246
        $response = ($this->action)($request);
247
248
        $this->assertSame(Response::HTTP_OK, $response->getStatusCode());
249
    }
250
251
    public function testSetObjectFieldValueActionWithViolations(): void
252
    {
253
        $bar = new Bar();
254
        $object = new Baz();
255
        $object->setBar($bar);
256
        $request = new Request([
257
            'code' => 'sonata.post.admin',
258
            'objectId' => 42,
259
            'field' => 'bar.enabled',
260
            'value' => 1,
261
            'context' => 'list',
262
        ], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_POST, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);
263
264
        $fieldDescription = $this->prophesize(FieldDescriptionInterface::class);
265
        $propertyAccessor = new PropertyAccessor();
266
267
        $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...
268
        $this->admin->getObject(42)->willReturn($object);
269
        $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...
270
        $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...
271
        $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...
272
            new ConstraintViolation('error1', null, [], null, 'enabled', null),
273
            new ConstraintViolation('error2', null, [], null, 'enabled', null),
274
        ]));
275
        $fieldDescription->getOption('editable')->willReturn(true);
276
        $fieldDescription->getType()->willReturn('boolean');
277
278
        $response = ($this->action)($request);
279
280
        $this->assertSame(Response::HTTP_BAD_REQUEST, $response->getStatusCode());
281
        $this->assertSame(json_encode("error1\nerror2"), $response->getContent());
282
    }
283
284
    public function testSetObjectFieldEditableMultipleValue(): void
285
    {
286
        $object = new StatusMultiple();
287
        $request = new Request([
288
            'code' => 'sonata.post.admin',
289
            'objectId' => 42,
290
            'field' => 'status',
291
            'value' => [1, 2],
292
            'context' => 'list',
293
        ], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_POST, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);
294
295
        $fieldDescription = $this->prophesize(FieldDescriptionInterface::class);
296
        $pool = $this->prophesize(Pool::class);
297
        $template = $this->prophesize(Template::class);
0 ignored issues
show
Unused Code introduced by
$template is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
298
        $translator = $this->prophesize(TranslatorInterface::class);
299
        $propertyAccessor = new PropertyAccessor();
300
        $templateRegistry = $this->prophesize(TemplateRegistryInterface::class);
301
        $container = $this->prophesize(ContainerInterface::class);
302
303
        $this->admin->getObject(42)->willReturn($object);
304
        $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...
305
        $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...
306
        $this->admin->getListFieldDescription('status')->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...
307
        $this->admin->update($object)->shouldBeCalled();
0 ignored issues
show
Documentation introduced by
$object is of type object<Sonata\AdminBundl...\Action\StatusMultiple>, 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...
308
        $templateRegistry->getTemplate('base_list_field')->willReturn('admin_template');
309
        $container->get('sonata.post.admin.template_registry')->willReturn($templateRegistry->reveal());
310
        $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...
311
        $this->twig->addExtension(new SonataAdminExtension(
312
            $pool->reveal(),
313
            null,
314
            $translator->reveal(),
315
            $container->reveal()
316
        ));
317
        $fieldDescription->getOption('editable')->willReturn(true);
318
        $fieldDescription->getOption('multiple')->willReturn(true);
319
        $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...
320
        $fieldDescription->getType()->willReturn('boolean');
321
        $fieldDescription->getTemplate()->willReturn('field_template');
322
        $fieldDescription->getValue(Argument::cetera())->willReturn(['some value']);
323
324
        $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...
325
326
        $response = ($this->action)($request);
327
328
        $this->assertSame(Response::HTTP_OK, $response->getStatusCode());
329
    }
330
}
331