Issues (655)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

tests/Action/SetObjectFieldValueActionTest.php (42 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
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
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->hasListFieldDescription('enabled')->willReturn(true);
0 ignored issues
show
The method willReturn cannot be called on $this->admin->hasListFieldDescription('enabled') (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...
104
        $this->admin->getListFieldDescription('enabled')->willReturn($fieldDescription->reveal());
0 ignored issues
show
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...
105
        $this->admin->update($object)->shouldBeCalled();
0 ignored issues
show
$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...
106
        $templateRegistry->getTemplate('base_list_field')->willReturn('admin_template');
107
        $container->get('sonata.post.admin.template_registry')->willReturn($templateRegistry->reveal());
108
        $this->pool->getPropertyAccessor()->willReturn($propertyAccessor);
0 ignored issues
show
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...
109
        $this->twig->addExtension(new SonataAdminExtension(
110
            $pool->reveal(),
111
            $translator->reveal(),
112
            $container->reveal()
113
        ));
114
        $fieldDescription->getOption('editable')->willReturn(true);
115
        $fieldDescription->getAdmin()->willReturn($this->admin->reveal());
0 ignored issues
show
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
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
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
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->hasListFieldDescription('dateProp')->willReturn(true);
0 ignored issues
show
The method willReturn cannot be called on $this->admin->hasListFieldDescription('dateProp') (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...
167
        $this->admin->getListFieldDescription('dateProp')->willReturn($fieldDescription->reveal());
0 ignored issues
show
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...
168
        $this->admin->update($object)->shouldBeCalled();
0 ignored issues
show
$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...
169
170
        $templateRegistry->getTemplate('base_list_field')->willReturn('admin_template');
171
        $container->get('sonata.post.admin.template_registry')->willReturn($templateRegistry->reveal());
172
        $this->pool->getPropertyAccessor()->willReturn($propertyAccessor);
0 ignored issues
show
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...
173
        $this->twig->addExtension(new SonataAdminExtension(
174
            $pool->reveal(),
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
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
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
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
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->hasListFieldDescription('bar')->willReturn(true);
0 ignored issues
show
The method willReturn cannot be called on $this->admin->hasListFieldDescription('bar') (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...
223
        $this->admin->getListFieldDescription('bar')->willReturn($fieldDescription->reveal());
0 ignored issues
show
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...
224
        $this->admin->getClass()->willReturn(\get_class($object));
0 ignored issues
show
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...
225
        $this->admin->update($object)->shouldBeCalled();
0 ignored issues
show
$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...
226
        $container->get('sonata.post.admin.template_registry')->willReturn($templateRegistry->reveal());
227
        $templateRegistry->getTemplate('base_list_field')->willReturn('admin_template');
228
        $this->admin->getModelManager()->willReturn($modelManager->reveal());
0 ignored issues
show
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...
229
        $this->twig->addExtension(new SonataAdminExtension(
230
            $this->pool->reveal(),
0 ignored issues
show
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...
231
            $translator->reveal(),
232
            $container->reveal()
233
        ));
234
        $this->pool->getPropertyAccessor()->willReturn($propertyAccessor);
0 ignored issues
show
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
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
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
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
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->hasListFieldDescription('bar.enabled')->willReturn(true);
0 ignored issues
show
The method willReturn cannot be called on $this->admin->hasListFie...cription('bar.enabled') (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...
271
        $this->admin->getListFieldDescription('bar.enabled')->willReturn($fieldDescription->reveal());
0 ignored issues
show
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...
272
        $this->validator->validate($bar)->willReturn(new ConstraintViolationList([
0 ignored issues
show
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...
273
            new ConstraintViolation('error1', null, [], null, 'enabled', null),
274
            new ConstraintViolation('error2', null, [], null, 'enabled', null),
275
        ]));
276
        $fieldDescription->getOption('editable')->willReturn(true);
277
        $fieldDescription->getType()->willReturn('boolean');
278
279
        $response = ($this->action)($request);
280
281
        $this->assertSame(Response::HTTP_BAD_REQUEST, $response->getStatusCode());
282
        $this->assertSame(json_encode("error1\nerror2"), $response->getContent());
283
    }
284
285
    public function testSetObjectFieldEditableMultipleValue(): void
286
    {
287
        $object = new StatusMultiple();
288
        $request = new Request([
289
            'code' => 'sonata.post.admin',
290
            'objectId' => 42,
291
            'field' => 'status',
292
            'value' => [1, 2],
293
            'context' => 'list',
294
        ], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_POST, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);
295
296
        $fieldDescription = $this->prophesize(FieldDescriptionInterface::class);
297
        $pool = $this->prophesize(Pool::class);
298
        $template = $this->prophesize(Template::class);
0 ignored issues
show
$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...
299
        $translator = $this->prophesize(TranslatorInterface::class);
300
        $propertyAccessor = new PropertyAccessor();
301
        $templateRegistry = $this->prophesize(TemplateRegistryInterface::class);
302
        $container = $this->prophesize(ContainerInterface::class);
303
304
        $this->admin->getObject(42)->willReturn($object);
305
        $this->admin->getCode()->willReturn('sonata.post.admin');
0 ignored issues
show
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...
306
        $this->admin->hasAccess('edit', $object)->willReturn(true);
0 ignored issues
show
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...
307
        $this->admin->hasListFieldDescription('status')->willReturn(true);
0 ignored issues
show
The method willReturn cannot be called on $this->admin->hasListFieldDescription('status') (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...
308
        $this->admin->getListFieldDescription('status')->willReturn($fieldDescription->reveal());
0 ignored issues
show
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...
309
        $this->admin->update($object)->shouldBeCalled();
0 ignored issues
show
$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...
310
        $templateRegistry->getTemplate('base_list_field')->willReturn('admin_template');
311
        $container->get('sonata.post.admin.template_registry')->willReturn($templateRegistry->reveal());
312
        $this->pool->getPropertyAccessor()->willReturn($propertyAccessor);
0 ignored issues
show
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...
313
        $this->twig->addExtension(new SonataAdminExtension(
314
            $pool->reveal(),
315
            $translator->reveal(),
316
            $container->reveal()
317
        ));
318
        $fieldDescription->getOption('editable')->willReturn(true);
319
        $fieldDescription->getOption('multiple')->willReturn(true);
320
        $fieldDescription->getAdmin()->willReturn($this->admin->reveal());
0 ignored issues
show
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...
321
        $fieldDescription->getType()->willReturn('boolean');
322
        $fieldDescription->getTemplate()->willReturn('field_template');
323
        $fieldDescription->getValue(Argument::cetera())->willReturn(['some value']);
324
325
        $this->validator->validate($object)->willReturn(new ConstraintViolationList([]));
0 ignored issues
show
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...
326
327
        $response = ($this->action)($request);
328
329
        $this->assertSame(Response::HTTP_OK, $response->getStatusCode());
330
    }
331
}
332