Completed
Push — master ( 5b57aa...78681d )
by Vincent
15s queued 11s
created

testSetObjectFieldValueActionWithDateTime()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 45

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 45
rs 9.2
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();
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 testSetObjectFieldValueActionWithDate(): void
128
    {
129
        $object = new Bafoo();
130
        $request = new Request([
131
            'code' => 'sonata.post.admin',
132
            'objectId' => 42,
133
            'field' => 'dateProp',
134
            'value' => '2020-12-12',
135
            'context' => 'list',
136
        ], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_POST, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);
137
138
        $fieldDescription = $this->prophesize(FieldDescriptionInterface::class);
139
        $pool = $this->prophesize(Pool::class);
140
        $translator = $this->prophesize(TranslatorInterface::class);
141
        $propertyAccessor = new PropertyAccessor();
142
        $templateRegistry = $this->prophesize(TemplateRegistryInterface::class);
143
        $container = $this->prophesize(ContainerInterface::class);
144
145
        $this->admin->getObject(42)->willReturn($object);
146
        $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...
147
        $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...
148
        $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...
149
        $this->admin->update($object)->shouldBeCalled();
150
151
        $templateRegistry->getTemplate('base_list_field')->willReturn('admin_template');
152
        $container->get('sonata.post.admin.template_registry')->willReturn($templateRegistry->reveal());
153
        $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...
154
        $this->twig->addExtension(new SonataAdminExtension(
155
            $pool->reveal(),
156
            null,
157
            $translator->reveal(),
158
            $container->reveal()
159
        ));
160
        $fieldDescription->getOption('editable')->willReturn(true);
161
        $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...
162
        $fieldDescription->getType()->willReturn('date');
163
        $fieldDescription->getTemplate()->willReturn('field_template');
164
        $fieldDescription->getValue(Argument::cetera())->willReturn('some value');
165
166
        $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...
167
168
        $response = ($this->action)($request);
169
170
        $this->assertSame(Response::HTTP_OK, $response->getStatusCode());
171
    }
172
173
    public function testSetObjectFieldValueActionWithDateTime(): void
174
    {
175
        $object = new Bafoo();
176
        $request = new Request([
177
            'code' => 'sonata.post.admin',
178
            'objectId' => 42,
179
            'field' => 'datetimeProp',
180
            'value' => '2020-12-12 23:11:23',
181
            'context' => 'list',
182
        ], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_POST, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);
183
184
        $fieldDescription = $this->prophesize(FieldDescriptionInterface::class);
185
        $pool = $this->prophesize(Pool::class);
186
        $translator = $this->prophesize(TranslatorInterface::class);
187
        $propertyAccessor = new PropertyAccessor();
188
        $templateRegistry = $this->prophesize(TemplateRegistryInterface::class);
189
        $container = $this->prophesize(ContainerInterface::class);
190
191
        $this->admin->getObject(42)->willReturn($object);
192
        $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...
193
        $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...
194
        $this->admin->getListFieldDescription('datetimeProp')->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...
195
        $this->admin->update($object)->shouldBeCalled();
196
197
        $templateRegistry->getTemplate('base_list_field')->willReturn('admin_template');
198
        $container->get('sonata.post.admin.template_registry')->willReturn($templateRegistry->reveal());
199
        $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...
200
        $this->twig->addExtension(new SonataAdminExtension(
201
            $pool->reveal(),
202
            null,
203
            $translator->reveal(),
204
            $container->reveal()
205
        ));
206
        $fieldDescription->getOption('editable')->willReturn(true);
207
        $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...
208
        $fieldDescription->getType()->willReturn('datetime');
209
        $fieldDescription->getTemplate()->willReturn('field_template');
210
        $fieldDescription->getValue(Argument::cetera())->willReturn('some value');
211
212
        $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...
213
214
        $response = ($this->action)($request);
215
216
        $this->assertSame(Response::HTTP_OK, $response->getStatusCode());
217
    }
218
219
    public function testSetObjectFieldValueActionOnARelationField(): void
220
    {
221
        $object = new Baz();
222
        $associationObject = new Bar();
223
        $request = new Request([
224
            'code' => 'sonata.post.admin',
225
            'objectId' => 42,
226
            'field' => 'bar',
227
            'value' => 1,
228
            'context' => 'list',
229
        ], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_POST, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);
230
231
        $fieldDescription = $this->prophesize(FieldDescriptionInterface::class);
232
        $modelManager = $this->prophesize(ModelManagerInterface::class);
233
        $translator = $this->prophesize(TranslatorInterface::class);
234
        $propertyAccessor = new PropertyAccessor();
235
        $templateRegistry = $this->prophesize(TemplateRegistryInterface::class);
236
        $container = $this->prophesize(ContainerInterface::class);
237
238
        $this->admin->getObject(42)->willReturn($object);
239
        $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...
240
        $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...
241
        $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...
242
        $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...
243
        $this->admin->update($object)->shouldBeCalled();
244
        $container->get('sonata.post.admin.template_registry')->willReturn($templateRegistry->reveal());
245
        $templateRegistry->getTemplate('base_list_field')->willReturn('admin_template');
246
        $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...
247
        $this->twig->addExtension(new SonataAdminExtension(
248
            $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...
249
            null,
250
            $translator->reveal(),
251
            $container->reveal()
252
        ));
253
        $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...
254
        $fieldDescription->getType()->willReturn('choice');
255
        $fieldDescription->getOption('editable')->willReturn(true);
256
        $fieldDescription->getOption('class')->willReturn(Bar::class);
257
        $fieldDescription->getTargetEntity()->willReturn(Bar::class);
258
        $fieldDescription->getAdmin()->willReturn($this->admin->reveal());
0 ignored issues
show
Bug introduced by
The method reveal() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
259
        $fieldDescription->getTemplate()->willReturn('field_template');
260
        $fieldDescription->getValue(Argument::cetera())->willReturn('some value');
261
        $modelManager->find(\get_class($associationObject), 1)->willReturn($associationObject);
262
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
265
        $response = ($this->action)($request);
266
267
        $this->assertSame(Response::HTTP_OK, $response->getStatusCode());
268
    }
269
270
    public function testSetObjectFieldValueActionWithViolations(): void
271
    {
272
        $bar = new Bar();
273
        $object = new Baz();
274
        $object->setBar($bar);
275
        $request = new Request([
276
            'code' => 'sonata.post.admin',
277
            'objectId' => 42,
278
            'field' => 'bar.enabled',
279
            'value' => 1,
280
            'context' => 'list',
281
        ], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_POST, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);
282
283
        $fieldDescription = $this->prophesize(FieldDescriptionInterface::class);
284
        $propertyAccessor = new PropertyAccessor();
285
286
        $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...
287
        $this->admin->getObject(42)->willReturn($object);
288
        $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...
289
        $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...
290
        $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...
291
            new ConstraintViolation('error1', null, [], null, 'enabled', null),
292
            new ConstraintViolation('error2', null, [], null, 'enabled', null),
293
        ]));
294
        $fieldDescription->getOption('editable')->willReturn(true);
295
        $fieldDescription->getType()->willReturn('boolean');
296
297
        $response = ($this->action)($request);
298
299
        $this->assertSame(Response::HTTP_BAD_REQUEST, $response->getStatusCode());
300
        $this->assertSame(json_encode("error1\nerror2"), $response->getContent());
301
    }
302
303
    public function testSetObjectFieldEditableMultipleValue(): void
304
    {
305
        $object = new StatusMultiple();
306
        $request = new Request([
307
            'code' => 'sonata.post.admin',
308
            'objectId' => 42,
309
            'field' => 'status',
310
            'value' => [1, 2],
311
            'context' => 'list',
312
        ], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_POST, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);
313
314
        $fieldDescription = $this->prophesize(FieldDescriptionInterface::class);
315
        $pool = $this->prophesize(Pool::class);
316
        $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...
317
        $translator = $this->prophesize(TranslatorInterface::class);
318
        $propertyAccessor = new PropertyAccessor();
319
        $templateRegistry = $this->prophesize(TemplateRegistryInterface::class);
320
        $container = $this->prophesize(ContainerInterface::class);
321
322
        $this->admin->getObject(42)->willReturn($object);
323
        $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...
324
        $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...
325
        $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...
326
        $this->admin->update($object)->shouldBeCalled();
327
        $templateRegistry->getTemplate('base_list_field')->willReturn('admin_template');
328
        $container->get('sonata.post.admin.template_registry')->willReturn($templateRegistry->reveal());
329
        $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...
330
        $this->twig->addExtension(new SonataAdminExtension(
331
            $pool->reveal(),
332
            null,
333
            $translator->reveal(),
334
            $container->reveal()
335
        ));
336
        $fieldDescription->getOption('editable')->willReturn(true);
337
        $fieldDescription->getOption('multiple')->willReturn(true);
338
        $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...
339
        $fieldDescription->getType()->willReturn('boolean');
340
        $fieldDescription->getTemplate()->willReturn('field_template');
341
        $fieldDescription->getValue(Argument::cetera())->willReturn(['some value']);
342
343
        $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...
344
345
        $response = ($this->action)($request);
346
347
        $this->assertSame(Response::HTTP_OK, $response->getStatusCode());
348
    }
349
}
350