Completed
Push — 3.x ( b80d34...688a7c )
by Christian
03:36
created

testBatchActionActionWithDisabledCsrfProtection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 37
rs 9.328
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\AdminBundle\Tests\Controller;
15
16
use PHPUnit\Framework\TestCase;
17
use Psr\Log\LoggerInterface;
18
use Sonata\AdminBundle\Admin\AbstractAdmin;
19
use Sonata\AdminBundle\Admin\FieldDescriptionCollection;
20
use Sonata\AdminBundle\Admin\Pool;
21
use Sonata\AdminBundle\Controller\CRUDController;
22
use Sonata\AdminBundle\Datagrid\DatagridInterface;
23
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
24
use Sonata\AdminBundle\Exception\LockException;
25
use Sonata\AdminBundle\Exception\ModelManagerException;
26
use Sonata\AdminBundle\Export\Exporter as SonataExporter;
27
use Sonata\AdminBundle\Model\AuditManager;
28
use Sonata\AdminBundle\Model\AuditReaderInterface;
29
use Sonata\AdminBundle\Model\ModelManagerInterface;
30
use Sonata\AdminBundle\Security\Acl\Permission\AdminPermissionMap;
31
use Sonata\AdminBundle\Security\Handler\AclSecurityHandler;
32
use Sonata\AdminBundle\Templating\TemplateRegistryInterface;
33
use Sonata\AdminBundle\Tests\Fixtures\Admin\PostAdmin;
34
use Sonata\AdminBundle\Tests\Fixtures\Controller\BatchAdminController;
35
use Sonata\AdminBundle\Tests\Fixtures\Controller\PreCRUDController;
36
use Sonata\AdminBundle\Util\AdminObjectAclData;
37
use Sonata\AdminBundle\Util\AdminObjectAclManipulator;
38
use Sonata\Exporter\Exporter;
39
use Sonata\Exporter\Source\SourceIteratorInterface;
40
use Sonata\Exporter\Writer\JsonWriter;
41
use Symfony\Bridge\Twig\Extension\FormExtension;
42
use Symfony\Bridge\Twig\Form\TwigRenderer;
43
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
44
use Symfony\Bundle\FrameworkBundle\Templating\DelegatingEngine;
45
use Symfony\Component\DependencyInjection\ContainerInterface;
46
use Symfony\Component\Form\Form;
47
use Symfony\Component\Form\FormBuilderInterface;
48
use Symfony\Component\Form\FormError;
49
use Symfony\Component\Form\FormInterface;
50
use Symfony\Component\Form\FormRenderer;
51
use Symfony\Component\Form\FormView;
52
use Symfony\Component\HttpFoundation\JsonResponse;
53
use Symfony\Component\HttpFoundation\RedirectResponse;
54
use Symfony\Component\HttpFoundation\Request;
55
use Symfony\Component\HttpFoundation\RequestStack;
56
use Symfony\Component\HttpFoundation\Response;
57
use Symfony\Component\HttpFoundation\Session\Session;
58
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
59
use Symfony\Component\HttpFoundation\StreamedResponse;
60
use Symfony\Component\HttpKernel\Exception\HttpException;
61
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
62
use Symfony\Component\HttpKernel\KernelInterface;
63
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
64
use Symfony\Component\Security\Csrf\CsrfToken;
65
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
66
use Symfony\Component\Translation\TranslatorInterface;
67
use Twig\Environment;
68
69
/**
70
 * Test for CRUDController.
71
 *
72
 * @author Andrej Hudec <[email protected]>
73
 *
74
 * @group legacy
75
 */
76
class CRUDControllerTest extends TestCase
77
{
78
    /**
79
     * @var CRUDController
80
     */
81
    private $controller;
82
83
    /**
84
     * @var Request
85
     */
86
    private $request;
87
88
    /**
89
     * @var AbstractAdmin
90
     */
91
    private $admin;
92
93
    /**
94
     * @var TemplateRegistryInterface
95
     */
96
    private $templateRegistry;
97
98
    /**
99
     * @var Pool
100
     */
101
    private $pool;
102
103
    /**
104
     * @var array
105
     */
106
    private $parameters;
107
108
    /**
109
     * @var Session
110
     */
111
    private $session;
112
113
    /**
114
     * @var AuditManager
115
     */
116
    private $auditManager;
117
118
    /**
119
     * @var ContainerInterface
120
     */
121
    private $container;
122
123
    /**
124
     * @var AdminObjectAclManipulator
125
     */
126
    private $adminObjectAclManipulator;
127
128
    /**
129
     * @var string
130
     */
131
    private $template;
132
133
    /**
134
     * @var array
135
     */
136
    private $protectedTestedMethods;
137
138
    /**
139
     * @var CsrfTokenManagerInterface
140
     */
141
    private $csrfProvider;
142
143
    /**
144
     * @var KernelInterface
145
     */
146
    private $kernel;
147
148
    /**
149
     * @var TranslatorInterface
150
     */
151
    private $translator;
152
153
    /**
154
     * @var FormBuilderInterface
155
     */
156
    private $formBuilder;
157
158
    /**
159
     * {@inheritdoc}
160
     */
161
    protected function setUp(): void
162
    {
163
        $this->container = $this->createMock(ContainerInterface::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\Symfo...tainerInterface::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Symfony\Component...ion\ContainerInterface> of property $container.

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...
164
165
        $this->request = new Request();
166
        $this->pool = new Pool($this->container, 'title', 'logo.png');
0 ignored issues
show
Documentation introduced by
$this->container is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...ion\ContainerInterface>.

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...
167
        $this->pool->setAdminServiceIds(['foo.admin']);
168
        $this->request->attributes->set('_sonata_admin', 'foo.admin');
169
        $this->admin = $this->getMockBuilder(AbstractAdmin::class)
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getMockBuilder(\S...onstructor()->getMock() of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Sonata\AdminBundle\Admin\AbstractAdmin> of property $admin.

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...
170
            ->disableOriginalConstructor()
171
            ->getMock();
172
        $this->translator = $this->createMock(TranslatorInterface::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\Symfo...slatorInterface::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Symfony\Component...on\TranslatorInterface> of property $translator.

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...
173
        $this->parameters = [];
174
        $this->template = '';
175
176
        $this->formBuilder = $this->createMock(FormBuilderInterface::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\Symfo...uilderInterface::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Symfony\Component...m\FormBuilderInterface> of property $formBuilder.

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...
177
        $this->admin->expects($this->any())
178
            ->method('getFormBuilder')
179
            ->willReturn($this->formBuilder);
180
181
        $this->templateRegistry = $this->prophesize(TemplateRegistryInterface::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->prophesize(\Sonat...gistryInterface::class) of type object<Prophecy\Prophecy\ObjectProphecy> is incompatible with the declared type object<Sonata\AdminBundl...plateRegistryInterface> of property $templateRegistry.

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...
182
183
        $templating = $this->getMockBuilder(DelegatingEngine::class)
184
            ->setConstructorArgs([$this->container, []])
185
            ->getMock();
186
187
        $templatingRenderReturnCallback = $this->returnCallback(function (
188
            $view,
189
            array $parameters = [],
190
            Response $response = null
191
        ) {
192
            $this->template = $view;
193
194
            if (null === $response) {
195
                $response = new Response();
196
            }
197
198
            $this->parameters = $parameters;
199
200
            return $response;
201
        });
202
203
        // SF < 3.3.10 BC
204
        $templating->expects($this->any())
205
            ->method('renderResponse')
206
            ->will($templatingRenderReturnCallback);
207
208
        $templating->expects($this->any())
209
            ->method('render')
210
            ->will($templatingRenderReturnCallback);
211
212
        $this->session = new Session(new MockArraySessionStorage());
213
214
        $twig = $this->getMockBuilder(Environment::class)
215
            ->disableOriginalConstructor()
216
            ->getMock();
217
218
        $twig->expects($this->any())
219
            ->method('getExtension')
220
            ->willReturnCallback(function ($name) {
221
                switch ($name) {
222
                    case FormExtension::class:
223
                        return new FormExtension($this->createMock(TwigRenderer::class));
0 ignored issues
show
Unused Code introduced by
The call to FormExtension::__construct() has too many arguments starting with $this->createMock(\Symfo...rm\TwigRenderer::class).

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
224
                }
225
            });
226
227
        $twig->expects($this->any())
228
            ->method('getRuntime')
229
            ->willReturnCallback(function ($name) {
230
                switch ($name) {
231
                    case TwigRenderer::class:
232
                        return $this->createMock(TwigRenderer::class);
233
                    case FormRenderer::class:
234
                        return $this->createMock(FormRenderer::class);
235
                }
236
            });
237
238
        // NEXT_MAJOR : require sonata/exporter ^1.7 and remove conditional
239
        if (class_exists(Exporter::class)) {
240
            $exporter = new Exporter([new JsonWriter('/tmp/sonataadmin/export.json')]);
241
        } else {
242
            $exporter = $this->createMock(SonataExporter::class);
243
244
            $exporter->expects($this->any())
245
                ->method('getResponse')
246
                ->willReturn(new StreamedResponse());
247
        }
248
249
        $this->auditManager = $this->getMockBuilder(AuditManager::class)
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getMockBuilder(\S...onstructor()->getMock() of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Sonata\AdminBundle\Model\AuditManager> of property $auditManager.

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...
250
            ->disableOriginalConstructor()
251
            ->getMock();
252
253
        $this->adminObjectAclManipulator = $this->getMockBuilder(AdminObjectAclManipulator::class)
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getMockBuilder(\S...onstructor()->getMock() of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Sonata\AdminBundl...inObjectAclManipulator> of property $adminObjectAclManipulator.

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...
254
            ->disableOriginalConstructor()
255
            ->getMock();
256
257
        $this->csrfProvider = $this->getMockBuilder(CsrfTokenManagerInterface::class)
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getMockBuilder(\S...face::class)->getMock() of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Symfony\Component...fTokenManagerInterface> of property $csrfProvider.

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...
258
            ->getMock();
259
260
        $this->csrfProvider->expects($this->any())
261
            ->method('getToken')
262
            ->willReturnCallback(static function ($intention) {
263
                return new CsrfToken($intention, 'csrf-token-123_'.$intention);
264
            });
265
266
        $this->csrfProvider->expects($this->any())
267
            ->method('isTokenValid')
268
            ->willReturnCallback(static function (CsrfToken $token) {
269
                if ($token->getValue() === 'csrf-token-123_'.$token->getId()) {
270
                    return true;
271
                }
272
273
                return false;
274
            });
275
276
        $this->logger = $this->createMock(LoggerInterface::class);
0 ignored issues
show
Bug introduced by
The property logger does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
277
278
        $requestStack = new RequestStack();
279
        $requestStack->push($this->request);
280
281
        $this->kernel = $this->createMock(KernelInterface::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\Symfo...KernelInterface::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Symfony\Component...Kernel\KernelInterface> of property $kernel.

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...
282
283
        $this->container->expects($this->any())
284
            ->method('get')
285
            ->willReturnCallback(function ($id) use (
286
                $templating,
287
                $twig,
288
                $exporter,
289
                $requestStack
290
            ) {
291
                switch ($id) {
292
                    case 'sonata.admin.pool':
293
                        return $this->pool;
294
                    case 'request_stack':
295
                        return $requestStack;
296
                    case 'foo.admin':
297
                        return $this->admin;
298
                    case 'foo.admin.template_registry':
299
                        return $this->templateRegistry->reveal();
0 ignored issues
show
Bug introduced by
The method reveal() does not seem to exist on object<Sonata\AdminBundl...plateRegistryInterface>.

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

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

Loading history...
300
                    case 'templating':
301
                        return $templating;
302
                    case 'twig':
303
                        return $twig;
304
                    case 'session':
305
                        return $this->session;
306
                    case 'sonata.admin.exporter':
307
                        return $exporter;
308
                    case 'sonata.admin.audit.manager':
309
                        return $this->auditManager;
310
                    case 'sonata.admin.object.manipulator.acl.admin':
311
                        return $this->adminObjectAclManipulator;
312
                    case 'security.csrf.token_manager':
313
                        return $this->csrfProvider;
314
                    case 'logger':
315
                        return $this->logger;
316
                    case 'kernel':
317
                        return $this->kernel;
318
                    case 'translator':
319
                        return $this->translator;
320
                }
321
            });
322
323
        $this->container->expects($this->any())
324
            ->method('has')
325
            ->willReturnCallback(function ($id) {
326
                if ('security.csrf.token_manager' === $id && null !== $this->getCsrfProvider()) {
327
                    return true;
328
                }
329
330
                if ('logger' === $id) {
331
                    return true;
332
                }
333
334
                if ('session' === $id) {
335
                    return true;
336
                }
337
338
                if ('templating' === $id) {
339
                    return true;
340
                }
341
342
                if ('translator' === $id) {
343
                    return true;
344
                }
345
346
                return false;
347
            });
348
349
        $this->container->expects($this->any())
350
            ->method('getParameter')
351
            ->willReturnCallback(static function ($name) {
352
                switch ($name) {
353
                    case 'security.role_hierarchy.roles':
354
                       return ['ROLE_SUPER_ADMIN' => ['ROLE_USER', 'ROLE_SONATA_ADMIN', 'ROLE_ADMIN']];
355
                }
356
            });
357
358
        $this->templateRegistry->getTemplate('ajax')->willReturn('@SonataAdmin/ajax_layout.html.twig');
359
        $this->templateRegistry->getTemplate('layout')->willReturn('@SonataAdmin/standard_layout.html.twig');
360
        $this->templateRegistry->getTemplate('show')->willReturn('@SonataAdmin/CRUD/show.html.twig');
361
        $this->templateRegistry->getTemplate('show_compare')->willReturn('@SonataAdmin/CRUD/show_compare.html.twig');
362
        $this->templateRegistry->getTemplate('edit')->willReturn('@SonataAdmin/CRUD/edit.html.twig');
363
        $this->templateRegistry->getTemplate('dashboard')->willReturn('@SonataAdmin/Core/dashboard.html.twig');
364
        $this->templateRegistry->getTemplate('search')->willReturn('@SonataAdmin/Core/search.html.twig');
365
        $this->templateRegistry->getTemplate('list')->willReturn('@SonataAdmin/CRUD/list.html.twig');
366
        $this->templateRegistry->getTemplate('preview')->willReturn('@SonataAdmin/CRUD/preview.html.twig');
367
        $this->templateRegistry->getTemplate('history')->willReturn('@SonataAdmin/CRUD/history.html.twig');
368
        $this->templateRegistry->getTemplate('acl')->willReturn('@SonataAdmin/CRUD/acl.html.twig');
369
        $this->templateRegistry->getTemplate('delete')->willReturn('@SonataAdmin/CRUD/delete.html.twig');
370
        $this->templateRegistry->getTemplate('batch')->willReturn('@SonataAdmin/CRUD/list__batch.html.twig');
371
        $this->templateRegistry->getTemplate('batch_confirmation')->willReturn('@SonataAdmin/CRUD/batch_confirmation.html.twig');
372
373
        // NEXT_MAJOR: Remove this call
374
        $this->admin->method('getTemplate')->willReturnMap([
375
            ['ajax', '@SonataAdmin/ajax_layout.html.twig'],
376
            ['layout', '@SonataAdmin/standard_layout.html.twig'],
377
            ['show', '@SonataAdmin/CRUD/show.html.twig'],
378
            ['show_compare', '@SonataAdmin/CRUD/show_compare.html.twig'],
379
            ['edit', '@SonataAdmin/CRUD/edit.html.twig'],
380
            ['dashboard', '@SonataAdmin/Core/dashboard.html.twig'],
381
            ['search', '@SonataAdmin/Core/search.html.twig'],
382
            ['list', '@SonataAdmin/CRUD/list.html.twig'],
383
            ['preview', '@SonataAdmin/CRUD/preview.html.twig'],
384
            ['history', '@SonataAdmin/CRUD/history.html.twig'],
385
            ['acl', '@SonataAdmin/CRUD/acl.html.twig'],
386
            ['delete', '@SonataAdmin/CRUD/delete.html.twig'],
387
            ['batch', '@SonataAdmin/CRUD/list__batch.html.twig'],
388
            ['batch_confirmation', '@SonataAdmin/CRUD/batch_confirmation.html.twig'],
389
        ]);
390
391
        $this->admin->expects($this->any())
392
            ->method('getIdParameter')
393
            ->willReturn('id');
394
395
        $this->admin->expects($this->any())
396
            ->method('getAccessMapping')
397
            ->willReturn([]);
398
399
        $this->admin->expects($this->any())
400
            ->method('generateUrl')
401
            ->willReturnCallback(
402
403
                    static function ($name, array $parameters = [], $absolute = false) {
0 ignored issues
show
Unused Code introduced by
The parameter $absolute is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
404
                        $result = $name;
405
                        if (!empty($parameters)) {
406
                            $result .= '?'.http_build_query($parameters);
407
                        }
408
409
                        return $result;
410
                    }
411
412
            );
413
414
        $this->admin->expects($this->any())
415
            ->method('generateObjectUrl')
416
            ->willReturnCallback(
417
418
                    static function ($name, $object, array $parameters = [], $absolute = false) {
0 ignored issues
show
Unused Code introduced by
The parameter $absolute is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
419
                        $result = \get_class($object).'_'.$name;
420
                        if (!empty($parameters)) {
421
                            $result .= '?'.http_build_query($parameters);
422
                        }
423
424
                        return $result;
425
                    }
426
427
            );
428
429
        $this->admin->expects($this->any())
430
            ->method('getCode')
431
            ->willReturn('foo.admin');
432
433
        $this->controller = new CRUDController();
434
        $this->controller->setContainer($this->container);
0 ignored issues
show
Documentation introduced by
$this->container is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a null|object<Symfony\Comp...ion\ContainerInterface>.

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...
435
436
        // Make some methods public to test them
437
        $testedMethods = [
438
            'renderJson',
439
            'isXmlHttpRequest',
440
            'configure',
441
            'getBaseTemplate',
442
            'redirectTo',
443
            'addFlash',
444
        ];
445
        foreach ($testedMethods as $testedMethod) {
446
            // NEXT_MAJOR: Remove this check and only use CRUDController
447
            if (method_exists(CRUDController::class, $testedMethod)) {
448
                $method = new \ReflectionMethod(CRUDController::class, $testedMethod);
449
            } else {
450
                $method = new \ReflectionMethod(Controller::class, $testedMethod);
451
            }
452
453
            $method->setAccessible(true);
454
            $this->protectedTestedMethods[$testedMethod] = $method;
455
        }
456
    }
457
458
    public function testRenderJson1(): void
459
    {
460
        $data = ['example' => '123', 'foo' => 'bar'];
461
462
        $this->request->headers->set('Content-Type', 'application/x-www-form-urlencoded');
463
        $response = $this->protectedTestedMethods['renderJson']->invoke($this->controller, $data, 200, [], $this->request);
464
465
        $this->assertSame($response->headers->get('Content-Type'), 'application/json');
466
        $this->assertSame(json_encode($data), $response->getContent());
467
    }
468
469
    public function testRenderJson2(): void
470
    {
471
        $data = ['example' => '123', 'foo' => 'bar'];
472
473
        $this->request->headers->set('Content-Type', 'multipart/form-data');
474
        $response = $this->protectedTestedMethods['renderJson']->invoke($this->controller, $data, 200, [], $this->request);
475
476
        $this->assertSame($response->headers->get('Content-Type'), 'application/json');
477
        $this->assertSame(json_encode($data), $response->getContent());
478
    }
479
480
    public function testRenderJsonAjax(): void
481
    {
482
        $data = ['example' => '123', 'foo' => 'bar'];
483
484
        $this->request->attributes->set('_xml_http_request', true);
485
        $this->request->headers->set('Content-Type', 'multipart/form-data');
486
        $response = $this->protectedTestedMethods['renderJson']->invoke($this->controller, $data, 200, [], $this->request);
487
488
        $this->assertSame($response->headers->get('Content-Type'), 'application/json');
489
        $this->assertSame(json_encode($data), $response->getContent());
490
    }
491
492
    public function testIsXmlHttpRequest(): void
493
    {
494
        $this->assertFalse($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
495
496
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
497
498
        $this->assertTrue($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
499
500
        $this->request->headers->remove('X-Requested-With');
501
        $this->assertFalse($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
502
503
        $this->request->attributes->set('_xml_http_request', true);
504
        $this->assertTrue($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
505
    }
506
507
    public function testConfigure(): void
508
    {
509
        $uniqueId = '';
510
511
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
512
            ->method('setUniqid')
513
            ->willReturnCallback(static function ($uniqid) use (&$uniqueId): void {
514
                $uniqueId = $uniqid;
515
            });
516
517
        $this->request->query->set('uniqid', 123456);
518
        $this->protectedTestedMethods['configure']->invoke($this->controller);
519
520
        $this->assertSame(123456, $uniqueId);
521
        $this->assertAttributeSame($this->admin, 'admin', $this->controller);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit\Framework\Assert::assertAttributeSame() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/issues/3338

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

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

Loading history...
522
    }
523
524
    public function testConfigureChild(): void
525
    {
526
        $uniqueId = '';
527
528
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
529
            ->method('setUniqid')
530
            ->willReturnCallback(static function ($uniqid) use (&$uniqueId): void {
531
                $uniqueId = $uniqid;
532
            });
533
534
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
535
            ->method('isChild')
536
            ->willReturn(true);
537
538
        $adminParent = $this->getMockBuilder(AbstractAdmin::class)
539
            ->disableOriginalConstructor()
540
            ->getMock();
541
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
542
            ->method('getParent')
543
            ->willReturn($adminParent);
544
545
        $this->request->query->set('uniqid', 123456);
546
        $this->protectedTestedMethods['configure']->invoke($this->controller);
547
548
        $this->assertSame(123456, $uniqueId);
549
        $this->assertAttributeInstanceOf(\get_class($adminParent), 'admin', $this->controller);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit\Framework\Assert...rtAttributeInstanceOf() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/issues/3338

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

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

Loading history...
550
    }
551
552
    public function testConfigureWithException(): void
553
    {
554
        $this->expectException(
555
            \RuntimeException::class,
556
            'There is no `_sonata_admin` defined for the controller `Sonata\AdminBundle\Controller\CRUDController`'
0 ignored issues
show
Unused Code introduced by
The call to CRUDControllerTest::expectException() has too many arguments starting with 'There is no `_sonata_ad...oller\\CRUDController`'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
557
        );
558
559
        $this->request->attributes->remove('_sonata_admin');
560
        $this->protectedTestedMethods['configure']->invoke($this->controller);
561
    }
562
563
    public function testConfigureWithException2(): void
564
    {
565
        $this->expectException(
566
            \InvalidArgumentException::class,
567
            'Found service "nonexistent.admin" is not a valid admin service'
0 ignored issues
show
Unused Code introduced by
The call to CRUDControllerTest::expectException() has too many arguments starting with 'Found service "nonexist... a valid admin service'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
568
        );
569
570
        $this->pool->setAdminServiceIds(['nonexistent.admin']);
571
        $this->request->attributes->set('_sonata_admin', 'nonexistent.admin');
572
        $this->protectedTestedMethods['configure']->invoke($this->controller);
573
    }
574
575
    public function testGetBaseTemplate(): void
576
    {
577
        $this->assertSame(
578
            '@SonataAdmin/standard_layout.html.twig',
579
            $this->protectedTestedMethods['getBaseTemplate']->invoke($this->controller, $this->request)
580
        );
581
582
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
583
        $this->assertSame(
584
            '@SonataAdmin/ajax_layout.html.twig',
585
            $this->protectedTestedMethods['getBaseTemplate']->invoke($this->controller, $this->request)
586
        );
587
588
        $this->request->headers->remove('X-Requested-With');
589
        $this->assertSame(
590
            '@SonataAdmin/standard_layout.html.twig',
591
            $this->protectedTestedMethods['getBaseTemplate']->invoke($this->controller, $this->request)
592
        );
593
594
        $this->request->attributes->set('_xml_http_request', true);
595
        $this->assertSame(
596
            '@SonataAdmin/ajax_layout.html.twig',
597
            $this->protectedTestedMethods['getBaseTemplate']->invoke($this->controller, $this->request)
598
        );
599
    }
600
601
    public function testRender(): void
602
    {
603
        $this->parameters = [];
604
        $this->assertInstanceOf(
605
            Response::class,
606
            $this->controller->renderWithExtraParams('@FooAdmin/foo.html.twig', [], null)
607
        );
608
        $this->assertSame($this->admin, $this->parameters['admin']);
609
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
610
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
611
        $this->assertSame('@FooAdmin/foo.html.twig', $this->template);
612
    }
613
614
    public function testRenderWithResponse(): void
615
    {
616
        $this->parameters = [];
617
        $response = $response = new Response();
618
        $response->headers->set('X-foo', 'bar');
619
        $responseResult = $this->controller->renderWithExtraParams('@FooAdmin/foo.html.twig', [], $response);
620
621
        $this->assertSame($response, $responseResult);
622
        $this->assertSame('bar', $responseResult->headers->get('X-foo'));
623
        $this->assertSame($this->admin, $this->parameters['admin']);
624
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
625
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
626
        $this->assertSame('@FooAdmin/foo.html.twig', $this->template);
627
    }
628
629
    public function testRenderCustomParams(): void
630
    {
631
        $this->parameters = [];
632
        $this->assertInstanceOf(
633
            Response::class,
634
            $this->controller->renderWithExtraParams(
635
                '@FooAdmin/foo.html.twig',
636
                ['foo' => 'bar'],
637
                null
638
            )
639
        );
640
        $this->assertSame($this->admin, $this->parameters['admin']);
641
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
642
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
643
        $this->assertSame('bar', $this->parameters['foo']);
644
        $this->assertSame('@FooAdmin/foo.html.twig', $this->template);
645
    }
646
647
    public function testRenderAjax(): void
648
    {
649
        $this->parameters = [];
650
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
651
        $this->assertInstanceOf(
652
            Response::class,
653
            $this->controller->renderWithExtraParams(
654
                '@FooAdmin/foo.html.twig',
655
                ['foo' => 'bar'],
656
                null
657
            )
658
        );
659
        $this->assertSame($this->admin, $this->parameters['admin']);
660
        $this->assertSame('@SonataAdmin/ajax_layout.html.twig', $this->parameters['base_template']);
661
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
662
        $this->assertSame('bar', $this->parameters['foo']);
663
        $this->assertSame('@FooAdmin/foo.html.twig', $this->template);
664
    }
665
666
    public function testListActionAccessDenied(): void
667
    {
668
        $this->expectException(AccessDeniedException::class);
669
670
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
671
            ->method('checkAccess')
672
            ->with($this->equalTo('list'))
673
            ->will($this->throwException(new AccessDeniedException()));
674
675
        $this->controller->listAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::listAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
676
    }
677
678
    public function testPreList(): void
679
    {
680
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
681
            ->method('hasRoute')
682
            ->with($this->equalTo('list'))
683
            ->willReturn(true);
684
685
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
686
            ->method('checkAccess')
687
            ->with($this->equalTo('list'))
688
            ->willReturn(true);
689
690
        $controller = new PreCRUDController();
691
        $controller->setContainer($this->container);
692
693
        $response = $controller->listAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to PreCRUDController::listAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
694
        $this->assertInstanceOf(Response::class, $response);
695
        $this->assertSame('preList called', $response->getContent());
696
    }
697
698
    public function testListAction(): void
699
    {
700
        $datagrid = $this->createMock(DatagridInterface::class);
701
702
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
703
            ->method('hasRoute')
704
            ->with($this->equalTo('list'))
705
            ->willReturn(true);
706
707
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
708
            ->method('checkAccess')
709
            ->with($this->equalTo('list'))
710
            ->willReturn(true);
711
712
        $form = $this->getMockBuilder(Form::class)
713
            ->disableOriginalConstructor()
714
            ->getMock();
715
716
        $form->expects($this->once())
717
            ->method('createView')
718
            ->willReturn($this->createMock(FormView::class));
719
720
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
721
            ->method('getDatagrid')
722
            ->willReturn($datagrid);
723
724
        $datagrid->expects($this->once())
725
            ->method('getForm')
726
            ->willReturn($form);
727
728
        $this->parameters = [];
729
        $this->assertInstanceOf(Response::class, $this->controller->listAction($this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::listAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
730
731
        $this->assertSame($this->admin, $this->parameters['admin']);
732
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
733
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
734
735
        $this->assertSame('list', $this->parameters['action']);
736
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
737
        $this->assertInstanceOf(DatagridInterface::class, $this->parameters['datagrid']);
738
        $this->assertSame('csrf-token-123_sonata.batch', $this->parameters['csrf_token']);
739
        $this->assertSame([], $this->session->getFlashBag()->all());
740
        $this->assertSame('@SonataAdmin/CRUD/list.html.twig', $this->template);
741
    }
742
743
    public function testBatchActionDeleteAccessDenied(): void
744
    {
745
        $this->expectException(AccessDeniedException::class);
746
747
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
748
            ->method('checkAccess')
749
            ->with($this->equalTo('batchDelete'))
750
            ->will($this->throwException(new AccessDeniedException()));
751
752
        $this->controller->batchActionDelete($this->createMock(ProxyQueryInterface::class));
0 ignored issues
show
Documentation introduced by
$this->createMock(\Sonat...yQueryInterface::class) is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Sonata\AdminBundl...id\ProxyQueryInterface>.

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...
753
    }
754
755
    public function testBatchActionDelete(): void
756
    {
757
        $modelManager = $this->createMock(ModelManagerInterface::class);
758
759
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
760
            ->method('checkAccess')
761
            ->with($this->equalTo('batchDelete'))
762
            ->willReturn(true);
763
764
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
765
            ->method('getModelManager')
766
            ->willReturn($modelManager);
767
768
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
769
            ->method('getFilterParameters')
770
            ->willReturn(['foo' => 'bar']);
771
772
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
773
774
        $result = $this->controller->batchActionDelete($this->createMock(ProxyQueryInterface::class));
0 ignored issues
show
Documentation introduced by
$this->createMock(\Sonat...yQueryInterface::class) is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Sonata\AdminBundl...id\ProxyQueryInterface>.

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...
775
776
        $this->assertInstanceOf(RedirectResponse::class, $result);
777
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
778
        $this->assertSame('list?filter%5Bfoo%5D=bar', $result->getTargetUrl());
779
    }
780
781
    public function testBatchActionDeleteWithModelManagerException(): void
782
    {
783
        $modelManager = $this->createMock(ModelManagerInterface::class);
784
        $this->assertLoggerLogsModelManagerException($modelManager, 'batchDelete');
785
786
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
787
            ->method('getModelManager')
788
            ->willReturn($modelManager);
789
790
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
791
            ->method('getFilterParameters')
792
            ->willReturn(['foo' => 'bar']);
793
794
        $this->expectTranslate('flash_batch_delete_error', [], 'SonataAdminBundle');
795
796
        $result = $this->controller->batchActionDelete($this->createMock(ProxyQueryInterface::class));
0 ignored issues
show
Documentation introduced by
$this->createMock(\Sonat...yQueryInterface::class) is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Sonata\AdminBundl...id\ProxyQueryInterface>.

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...
797
798
        $this->assertInstanceOf(RedirectResponse::class, $result);
799
        $this->assertSame(['flash_batch_delete_error'], $this->session->getFlashBag()->get('sonata_flash_error'));
800
        $this->assertSame('list?filter%5Bfoo%5D=bar', $result->getTargetUrl());
801
    }
802
803
    public function testBatchActionDeleteWithModelManagerExceptionInDebugMode(): void
804
    {
805
        $modelManager = $this->createMock(ModelManagerInterface::class);
806
        $this->expectException(ModelManagerException::class);
807
808
        $modelManager->expects($this->once())
809
            ->method('batchDelete')
810
            ->willReturnCallback(static function (): void {
811
                throw new ModelManagerException();
812
            });
813
814
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
815
            ->method('getModelManager')
816
            ->willReturn($modelManager);
817
818
        $this->kernel->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...Kernel\KernelInterface>.

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...
819
            ->method('isDebug')
820
            ->willReturn(true);
821
822
        $this->controller->batchActionDelete($this->createMock(ProxyQueryInterface::class));
0 ignored issues
show
Documentation introduced by
$this->createMock(\Sonat...yQueryInterface::class) is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Sonata\AdminBundl...id\ProxyQueryInterface>.

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...
823
    }
824
825
    public function testShowActionNotFoundException(): void
826
    {
827
        $this->expectException(NotFoundHttpException::class);
828
829
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
830
            ->method('getObject')
831
            ->willReturn(false);
832
833
        $this->controller->showAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::showAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
834
    }
835
836
    public function testShowActionAccessDenied(): void
837
    {
838
        $this->expectException(AccessDeniedException::class);
839
840
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
841
            ->method('getObject')
842
            ->willReturn(new \stdClass());
843
844
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
845
            ->method('checkAccess')
846
            ->with($this->equalTo('show'))
847
            ->will($this->throwException(new AccessDeniedException()));
848
849
        $this->controller->showAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::showAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
850
    }
851
852
    /**
853
     * @group legacy
854
     * @expectedDeprecation Calling this method without implementing "configureShowFields" is not supported since 3.40.0 and will no longer be possible in 4.0
855
     */
856
    public function testShowActionDeprecation(): void
857
    {
858
        $object = new \stdClass();
859
860
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
861
            ->method('getObject')
862
            ->willReturn($object);
863
864
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
865
            ->method('checkAccess')
866
            ->with($this->equalTo('show'))
867
            ->willReturn(true);
868
869
        $show = $this->createMock(FieldDescriptionCollection::class);
870
871
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
872
            ->method('getShow')
873
            ->willReturn($show);
874
875
        $show->expects($this->once())
876
            ->method('getElements')
877
            ->willReturn([]);
878
879
        $show->expects($this->once())
880
            ->method('count')
881
            ->willReturn(0);
882
883
        $this->controller->showAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::showAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
884
    }
885
886
    public function testPreShow(): void
887
    {
888
        $object = new \stdClass();
889
        $object->foo = 123456;
890
891
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
892
            ->method('getObject')
893
            ->willReturn($object);
894
895
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
896
            ->method('checkAccess')
897
            ->with($this->equalTo('show'))
898
            ->willReturn(true);
899
900
        $controller = new PreCRUDController();
901
        $controller->setContainer($this->container);
902
903
        $response = $controller->showAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to PreCRUDController::showAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
904
        $this->assertInstanceOf(Response::class, $response);
905
        $this->assertSame('preShow called: 123456', $response->getContent());
906
    }
907
908
    public function testShowAction(): void
909
    {
910
        $object = new \stdClass();
911
912
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
913
            ->method('getObject')
914
            ->willReturn($object);
915
916
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
917
            ->method('checkAccess')
918
            ->with($this->equalTo('show'))
919
            ->willReturn(true);
920
921
        $show = $this->createMock(FieldDescriptionCollection::class);
922
923
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
924
            ->method('getShow')
925
            ->willReturn($show);
926
927
        $show->expects($this->once())
928
            ->method('getElements')
929
            ->willReturn(['field' => 'fielddata']);
930
931
        $this->assertInstanceOf(Response::class, $this->controller->showAction(null, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::showAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
932
933
        $this->assertSame($this->admin, $this->parameters['admin']);
934
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
935
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
936
937
        $this->assertSame('show', $this->parameters['action']);
938
        $this->assertInstanceOf(FieldDescriptionCollection::class, $this->parameters['elements']);
939
        $this->assertSame($object, $this->parameters['object']);
940
941
        $this->assertSame([], $this->session->getFlashBag()->all());
942
        $this->assertSame('@SonataAdmin/CRUD/show.html.twig', $this->template);
943
    }
944
945
    /**
946
     * @dataProvider getRedirectToTests
947
     */
948
    public function testRedirectTo($expected, $route, $queryParams, $requestParams, $hasActiveSubclass): void
949
    {
950
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
951
            ->method('hasActiveSubclass')
952
            ->willReturn($hasActiveSubclass);
953
954
        $object = new \stdClass();
955
956
        foreach ($queryParams as $key => $value) {
957
            $this->request->query->set($key, $value);
958
        }
959
960
        foreach ($requestParams as $key => $value) {
961
            $this->request->request->set($key, $value);
962
        }
963
964
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
965
            ->method('hasRoute')
966
            ->with($this->equalTo($route))
967
            ->willReturn(true);
968
969
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
970
            ->method('hasAccess')
971
            ->with($this->equalTo($route))
972
            ->willReturn(true);
973
974
        $response = $this->protectedTestedMethods['redirectTo']->invoke($this->controller, $object, $this->request);
975
        $this->assertInstanceOf(RedirectResponse::class, $response);
976
        $this->assertSame($expected, $response->getTargetUrl());
977
    }
978
979
    public function testRedirectToWithObject(): void
980
    {
981
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
982
            ->method('hasActiveSubclass')
983
            ->willReturn(false);
984
985
        $object = new \stdClass();
986
987
        $this->admin->expects($this->at(0))
0 ignored issues
show
Bug introduced by
The method expects() 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...
988
            ->method('hasRoute')
989
            ->with($this->equalTo('edit'))
990
            ->willReturn(true);
991
992
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
993
            ->method('hasAccess')
994
            ->with($this->equalTo('edit'), $object)
995
            ->willReturn(false);
996
997
        $response = $this->protectedTestedMethods['redirectTo']->invoke($this->controller, $object, $this->request);
998
        $this->assertInstanceOf(RedirectResponse::class, $response);
999
        $this->assertSame('list', $response->getTargetUrl());
1000
    }
1001
1002
    public function getRedirectToTests()
1003
    {
1004
        return [
1005
            ['stdClass_edit', 'edit', [], [], false],
1006
            ['list', 'list', ['btn_update_and_list' => true], [], false],
1007
            ['list', 'list', ['btn_create_and_list' => true], [], false],
1008
            ['create', 'create', ['btn_create_and_create' => true], [], false],
1009
            ['create?subclass=foo', 'create', ['btn_create_and_create' => true, 'subclass' => 'foo'], [], true],
1010
            ['stdClass_edit?_tab=first_tab', 'edit', ['btn_update_and_edit' => true], ['_tab' => 'first_tab'], false],
1011
        ];
1012
    }
1013
1014
    public function testDeleteActionNotFoundException(): void
1015
    {
1016
        $this->expectException(NotFoundHttpException::class);
1017
1018
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1019
            ->method('getObject')
1020
            ->willReturn(false);
1021
1022
        $this->controller->deleteAction(1, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::deleteAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1023
    }
1024
1025
    public function testDeleteActionAccessDenied(): void
1026
    {
1027
        $this->expectException(AccessDeniedException::class);
1028
1029
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1030
            ->method('getObject')
1031
            ->willReturn(new \stdClass());
1032
1033
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1034
            ->method('checkAccess')
1035
            ->with($this->equalTo('delete'))
1036
            ->will($this->throwException(new AccessDeniedException()));
1037
1038
        $this->controller->deleteAction(1, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::deleteAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1039
    }
1040
1041
    public function testPreDelete(): void
1042
    {
1043
        $object = new \stdClass();
1044
        $object->foo = 123456;
1045
1046
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1047
            ->method('getObject')
1048
            ->willReturn($object);
1049
1050
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1051
            ->method('checkAccess')
1052
            ->with($this->equalTo('delete'))
1053
            ->willReturn(true);
1054
1055
        $controller = new PreCRUDController();
1056
        $controller->setContainer($this->container);
1057
1058
        $response = $controller->deleteAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to PreCRUDController::deleteAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1059
        $this->assertInstanceOf(Response::class, $response);
1060
        $this->assertSame('preDelete called: 123456', $response->getContent());
1061
    }
1062
1063
    public function testDeleteAction(): void
1064
    {
1065
        $object = new \stdClass();
1066
1067
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1068
            ->method('getObject')
1069
            ->willReturn($object);
1070
1071
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1072
            ->method('checkAccess')
1073
            ->with($this->equalTo('delete'))
1074
            ->willReturn(true);
1075
1076
        $this->assertInstanceOf(Response::class, $this->controller->deleteAction(1, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::deleteAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1077
1078
        $this->assertSame($this->admin, $this->parameters['admin']);
1079
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1080
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1081
1082
        $this->assertSame('delete', $this->parameters['action']);
1083
        $this->assertSame($object, $this->parameters['object']);
1084
        $this->assertSame('csrf-token-123_sonata.delete', $this->parameters['csrf_token']);
1085
1086
        $this->assertSame([], $this->session->getFlashBag()->all());
1087
        $this->assertSame('@SonataAdmin/CRUD/delete.html.twig', $this->template);
1088
    }
1089
1090
    /**
1091
     * @group legacy
1092
     * @expectedDeprecation Accessing a child that isn't connected to a given parent is deprecated since 3.34 and won't be allowed in 4.0.
1093
     */
1094
    public function testDeleteActionChildDeprecation(): void
1095
    {
1096
        $object = new \stdClass();
1097
        $object->parent = 'test';
1098
1099
        $object2 = new \stdClass();
1100
1101
        $admin = $this->createMock(PostAdmin::class);
1102
1103
        $admin->expects($this->once())
1104
            ->method('getObject')
1105
            ->willReturn($object2);
1106
1107
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1108
            ->method('getObject')
1109
            ->willReturn($object);
1110
1111
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1112
            ->method('getParent')
1113
            ->willReturn($admin);
1114
1115
        $this->admin->expects($this->exactly(2))
0 ignored issues
show
Bug introduced by
The method expects() 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...
1116
            ->method('getParentAssociationMapping')
1117
            ->willReturn('parent');
1118
1119
        $this->controller->deleteAction(1, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::deleteAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1120
    }
1121
1122
    public function testDeleteActionNoParentMappings(): void
1123
    {
1124
        $object = new \stdClass();
1125
1126
        $admin = $this->createMock(PostAdmin::class);
1127
1128
        $admin->expects($this->never())
1129
            ->method('getObject');
1130
1131
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1132
            ->method('getObject')
1133
            ->willReturn($object);
1134
1135
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1136
            ->method('getParent')
1137
            ->willReturn($admin);
1138
1139
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1140
            ->method('getParentAssociationMapping')
1141
            ->willReturn(false);
1142
1143
        $this->controller->deleteAction(1, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::deleteAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1144
    }
1145
1146
    public function testDeleteActionNoCsrfToken(): void
1147
    {
1148
        $this->csrfProvider = null;
1149
1150
        $object = new \stdClass();
1151
1152
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1153
            ->method('getObject')
1154
            ->willReturn($object);
1155
1156
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1157
            ->method('checkAccess')
1158
            ->with($this->equalTo('delete'))
1159
            ->willReturn(true);
1160
1161
        $this->assertInstanceOf(Response::class, $this->controller->deleteAction(1, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::deleteAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1162
1163
        $this->assertSame($this->admin, $this->parameters['admin']);
1164
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1165
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1166
1167
        $this->assertSame('delete', $this->parameters['action']);
1168
        $this->assertSame($object, $this->parameters['object']);
1169
        $this->assertFalse($this->parameters['csrf_token']);
1170
1171
        $this->assertSame([], $this->session->getFlashBag()->all());
1172
        $this->assertSame('@SonataAdmin/CRUD/delete.html.twig', $this->template);
1173
    }
1174
1175
    public function testDeleteActionAjaxSuccess1(): void
1176
    {
1177
        $object = new \stdClass();
1178
1179
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1180
            ->method('getObject')
1181
            ->willReturn($object);
1182
1183
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1184
            ->method('checkAccess')
1185
            ->with($this->equalTo('delete'))
1186
            ->willReturn(true);
1187
1188
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
1189
            ->method('getOption')
1190
            ->with('csrf_protection')
1191
            ->willReturn(true);
1192
1193
        $this->request->setMethod('DELETE');
1194
1195
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1196
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1197
1198
        $response = $this->controller->deleteAction(1, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::deleteAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1199
1200
        $this->assertInstanceOf(Response::class, $response);
1201
        $this->assertSame(json_encode(['result' => 'ok']), $response->getContent());
1202
        $this->assertSame([], $this->session->getFlashBag()->all());
1203
    }
1204
1205
    public function testDeleteActionAjaxSuccess2(): void
1206
    {
1207
        $object = new \stdClass();
1208
1209
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1210
            ->method('getObject')
1211
            ->willReturn($object);
1212
1213
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1214
            ->method('checkAccess')
1215
            ->with($this->equalTo('delete'))
1216
            ->willReturn(true);
1217
1218
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
1219
            ->method('getOption')
1220
            ->with('csrf_protection')
1221
            ->willReturn(true);
1222
1223
        $this->request->setMethod('POST');
1224
        $this->request->request->set('_method', 'DELETE');
1225
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1226
1227
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1228
1229
        $response = $this->controller->deleteAction(1, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::deleteAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1230
1231
        $this->assertInstanceOf(Response::class, $response);
1232
        $this->assertSame(json_encode(['result' => 'ok']), $response->getContent());
1233
        $this->assertSame([], $this->session->getFlashBag()->all());
1234
    }
1235
1236
    public function testDeleteActionAjaxError(): void
1237
    {
1238
        $object = new \stdClass();
1239
1240
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1241
            ->method('getObject')
1242
            ->willReturn($object);
1243
1244
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1245
            ->method('checkAccess')
1246
            ->with($this->equalTo('delete'))
1247
            ->willReturn(true);
1248
1249
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1250
            ->method('getClass')
1251
            ->willReturn('stdClass');
1252
1253
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
1254
            ->method('getOption')
1255
            ->with('csrf_protection')
1256
            ->willReturn(true);
1257
1258
        $this->assertLoggerLogsModelManagerException($this->admin, 'delete');
1259
1260
        $this->request->setMethod('DELETE');
1261
1262
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1263
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1264
1265
        $response = $this->controller->deleteAction(1, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::deleteAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1266
1267
        $this->assertInstanceOf(Response::class, $response);
1268
        $this->assertSame(json_encode(['result' => 'error']), $response->getContent());
1269
        $this->assertSame([], $this->session->getFlashBag()->all());
1270
    }
1271
1272
    public function testDeleteActionWithModelManagerExceptionInDebugMode(): void
1273
    {
1274
        $this->expectException(ModelManagerException::class);
1275
1276
        $object = new \stdClass();
1277
1278
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1279
            ->method('getObject')
1280
            ->willReturn($object);
1281
1282
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1283
            ->method('checkAccess')
1284
            ->with($this->equalTo('delete'))
1285
            ->willReturn(true);
1286
1287
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
1288
            ->method('getOption')
1289
            ->with('csrf_protection')
1290
            ->willReturn(true);
1291
1292
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1293
            ->method('delete')
1294
            ->willReturnCallback(static function (): void {
1295
                throw new ModelManagerException();
1296
            });
1297
1298
        $this->kernel->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...Kernel\KernelInterface>.

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...
1299
            ->method('isDebug')
1300
            ->willReturn(true);
1301
1302
        $this->request->setMethod('DELETE');
1303
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1304
1305
        $this->controller->deleteAction(1, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::deleteAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1306
    }
1307
1308
    /**
1309
     * @dataProvider getToStringValues
1310
     */
1311
    public function testDeleteActionSuccess1($expectedToStringValue, $toStringValue): void
1312
    {
1313
        $object = new \stdClass();
1314
1315
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1316
            ->method('getObject')
1317
            ->willReturn($object);
1318
1319
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1320
            ->method('toString')
1321
            ->with($this->equalTo($object))
1322
            ->willReturn($toStringValue);
1323
1324
        $this->expectTranslate('flash_delete_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1325
1326
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1327
            ->method('checkAccess')
1328
            ->with($this->equalTo('delete'))
1329
            ->willReturn(true);
1330
1331
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
1332
            ->method('getOption')
1333
            ->with('csrf_protection')
1334
            ->willReturn(true);
1335
1336
        $this->request->setMethod('DELETE');
1337
1338
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1339
1340
        $response = $this->controller->deleteAction(1, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::deleteAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1341
1342
        $this->assertInstanceOf(RedirectResponse::class, $response);
1343
        $this->assertSame(['flash_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1344
        $this->assertSame('list', $response->getTargetUrl());
1345
    }
1346
1347
    /**
1348
     * @dataProvider getToStringValues
1349
     */
1350
    public function testDeleteActionSuccess2($expectedToStringValue, $toStringValue): void
1351
    {
1352
        $object = new \stdClass();
1353
1354
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1355
            ->method('getObject')
1356
            ->willReturn($object);
1357
1358
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1359
            ->method('checkAccess')
1360
            ->with($this->equalTo('delete'))
1361
            ->willReturn(true);
1362
1363
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1364
            ->method('toString')
1365
            ->with($this->equalTo($object))
1366
            ->willReturn($toStringValue);
1367
1368
        $this->expectTranslate('flash_delete_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1369
1370
        $this->request->setMethod('POST');
1371
        $this->request->request->set('_method', 'DELETE');
1372
1373
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1374
1375
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
1376
            ->method('getOption')
1377
            ->with('csrf_protection')
1378
            ->willReturn(true);
1379
1380
        $response = $this->controller->deleteAction(1, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::deleteAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1381
1382
        $this->assertInstanceOf(RedirectResponse::class, $response);
1383
        $this->assertSame(['flash_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1384
        $this->assertSame('list', $response->getTargetUrl());
1385
    }
1386
1387
    /**
1388
     * @dataProvider getToStringValues
1389
     */
1390
    public function testDeleteActionSuccessNoCsrfTokenProvider($expectedToStringValue, $toStringValue): void
1391
    {
1392
        $this->csrfProvider = null;
1393
1394
        $object = new \stdClass();
1395
1396
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1397
            ->method('getObject')
1398
            ->willReturn($object);
1399
1400
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1401
            ->method('checkAccess')
1402
            ->with($this->equalTo('delete'))
1403
            ->willReturn(true);
1404
1405
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1406
            ->method('toString')
1407
            ->with($this->equalTo($object))
1408
            ->willReturn($toStringValue);
1409
1410
        $this->expectTranslate('flash_delete_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1411
1412
        $this->request->setMethod('POST');
1413
        $this->request->request->set('_method', 'DELETE');
1414
1415
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
1416
            ->method('getOption')
1417
            ->with('csrf_protection')
1418
            ->willReturn(true);
1419
1420
        $response = $this->controller->deleteAction(1, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::deleteAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1421
1422
        $this->assertInstanceOf(RedirectResponse::class, $response);
1423
        $this->assertSame(['flash_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1424
        $this->assertSame('list', $response->getTargetUrl());
1425
    }
1426
1427
    public function testDeleteActionWrongRequestMethod(): void
1428
    {
1429
        $object = new \stdClass();
1430
1431
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1432
            ->method('getObject')
1433
            ->willReturn($object);
1434
1435
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1436
            ->method('checkAccess')
1437
            ->with($this->equalTo('delete'))
1438
            ->willReturn(true);
1439
1440
        //without POST request parameter "_method" should not be used as real REST method
1441
        $this->request->query->set('_method', 'DELETE');
1442
1443
        $this->assertInstanceOf(Response::class, $this->controller->deleteAction(1, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::deleteAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1444
1445
        $this->assertSame($this->admin, $this->parameters['admin']);
1446
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1447
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1448
1449
        $this->assertSame('delete', $this->parameters['action']);
1450
        $this->assertSame($object, $this->parameters['object']);
1451
        $this->assertSame('csrf-token-123_sonata.delete', $this->parameters['csrf_token']);
1452
1453
        $this->assertSame([], $this->session->getFlashBag()->all());
1454
        $this->assertSame('@SonataAdmin/CRUD/delete.html.twig', $this->template);
1455
    }
1456
1457
    /**
1458
     * @dataProvider getToStringValues
1459
     */
1460
    public function testDeleteActionError($expectedToStringValue, $toStringValue): void
1461
    {
1462
        $object = new \stdClass();
1463
1464
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1465
            ->method('getObject')
1466
            ->willReturn($object);
1467
1468
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1469
            ->method('checkAccess')
1470
            ->with($this->equalTo('delete'))
1471
            ->willReturn(true);
1472
1473
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1474
            ->method('toString')
1475
            ->with($this->equalTo($object))
1476
            ->willReturn($toStringValue);
1477
1478
        $this->expectTranslate('flash_delete_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1479
1480
        $this->assertLoggerLogsModelManagerException($this->admin, 'delete');
1481
1482
        $this->request->setMethod('DELETE');
1483
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1484
1485
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
1486
            ->method('getOption')
1487
            ->with('csrf_protection')
1488
            ->willReturn(true);
1489
1490
        $response = $this->controller->deleteAction(1, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::deleteAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1491
1492
        $this->assertInstanceOf(RedirectResponse::class, $response);
1493
        $this->assertSame(['flash_delete_error'], $this->session->getFlashBag()->get('sonata_flash_error'));
1494
        $this->assertSame('list', $response->getTargetUrl());
1495
    }
1496
1497
    public function testDeleteActionInvalidCsrfToken(): void
1498
    {
1499
        $object = new \stdClass();
1500
1501
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1502
            ->method('getObject')
1503
            ->willReturn($object);
1504
1505
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1506
            ->method('checkAccess')
1507
            ->with($this->equalTo('delete'))
1508
            ->willReturn(true);
1509
1510
        $this->request->setMethod('POST');
1511
        $this->request->request->set('_method', 'DELETE');
1512
        $this->request->request->set('_sonata_csrf_token', 'CSRF-INVALID');
1513
1514
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
1515
            ->method('getOption')
1516
            ->with('csrf_protection')
1517
            ->willReturn(true);
1518
1519
        try {
1520
            $this->controller->deleteAction(1, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::deleteAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1521
        } catch (HttpException $e) {
1522
            $this->assertSame('The csrf token is not valid, CSRF attack?', $e->getMessage());
1523
            $this->assertSame(400, $e->getStatusCode());
1524
        }
1525
    }
1526
1527
    public function testDeleteActionWithDisabledCsrfProtection(): void
1528
    {
1529
        $object = new \stdClass();
1530
1531
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1532
            ->method('getObject')
1533
            ->willReturn($object);
1534
1535
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1536
            ->method('checkAccess')
1537
            ->with($this->equalTo('delete'))
1538
            ->willReturn(true);
1539
1540
        $this->request->setMethod('POST');
1541
        $this->request->request->set('_method', 'DELETE');
1542
1543
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
1544
            ->method('getOption')
1545
            ->with('csrf_protection')
1546
            ->willReturn(false);
1547
1548
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1549
            ->method('toString')
1550
            ->with($object)
1551
            ->willReturn(\stdClass::class);
1552
1553
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1554
            ->method('delete')
1555
            ->with($object);
1556
1557
        $this->controller->deleteAction(1, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::deleteAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1558
    }
1559
1560
    public function testEditActionNotFoundException(): void
1561
    {
1562
        $this->expectException(NotFoundHttpException::class);
1563
1564
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1565
            ->method('getObject')
1566
            ->willReturn(false);
1567
1568
        $this->controller->editAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::editAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1569
    }
1570
1571
    public function testEditActionRuntimeException(): void
1572
    {
1573
        $this->expectException(\RuntimeException::class);
1574
1575
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1576
            ->method('getObject')
1577
            ->willReturn(new \stdClass());
1578
1579
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1580
            ->method('checkAccess')
1581
            ->with($this->equalTo('edit'))
1582
            ->willReturn(true);
1583
1584
        $form = $this->createMock(Form::class);
1585
1586
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1587
            ->method('getForm')
1588
            ->willReturn($form);
1589
1590
        $form->expects($this->once())
1591
            ->method('all')
1592
            ->willReturn([]);
1593
1594
        $this->controller->editAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::editAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1595
    }
1596
1597
    public function testEditActionAccessDenied(): void
1598
    {
1599
        $this->expectException(AccessDeniedException::class);
1600
1601
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1602
            ->method('getObject')
1603
            ->willReturn(new \stdClass());
1604
1605
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1606
            ->method('checkAccess')
1607
            ->with($this->equalTo('edit'))
1608
            ->will($this->throwException(new AccessDeniedException()));
1609
1610
        $this->controller->editAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::editAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1611
    }
1612
1613
    public function testPreEdit(): void
1614
    {
1615
        $object = new \stdClass();
1616
        $object->foo = 123456;
1617
1618
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1619
            ->method('getObject')
1620
            ->willReturn($object);
1621
1622
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1623
            ->method('checkAccess')
1624
            ->with($this->equalTo('edit'))
1625
            ->willReturn(true);
1626
1627
        $controller = new PreCRUDController();
1628
        $controller->setContainer($this->container);
1629
1630
        $response = $controller->editAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to PreCRUDController::editAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1631
        $this->assertInstanceOf(Response::class, $response);
1632
        $this->assertSame('preEdit called: 123456', $response->getContent());
1633
    }
1634
1635
    public function testEditAction(): void
1636
    {
1637
        $object = new \stdClass();
1638
1639
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1640
            ->method('getObject')
1641
            ->willReturn($object);
1642
1643
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1644
            ->method('checkAccess')
1645
            ->with($this->equalTo('edit'))
1646
            ->willReturn(true);
1647
1648
        $form = $this->createMock(Form::class);
1649
1650
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1651
            ->method('getForm')
1652
            ->willReturn($form);
1653
1654
        $formView = $this->createMock(FormView::class);
1655
1656
        $form->expects($this->any())
1657
            ->method('createView')
1658
            ->willReturn($formView);
1659
1660
        $form->expects($this->once())
1661
            ->method('all')
1662
            ->willReturn(['field' => 'fielddata']);
1663
1664
        $this->assertInstanceOf(Response::class, $this->controller->editAction(null, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::editAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1665
1666
        $this->assertSame($this->admin, $this->parameters['admin']);
1667
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1668
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1669
1670
        $this->assertSame('edit', $this->parameters['action']);
1671
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1672
        $this->assertSame($object, $this->parameters['object']);
1673
        $this->assertSame([], $this->session->getFlashBag()->all());
1674
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1675
    }
1676
1677
    /**
1678
     * @dataProvider getToStringValues
1679
     */
1680
    public function testEditActionSuccess($expectedToStringValue, $toStringValue): void
1681
    {
1682
        $object = new \stdClass();
1683
1684
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1685
            ->method('getObject')
1686
            ->willReturn($object);
1687
1688
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1689
            ->method('update')
1690
            ->willReturnArgument(0);
1691
1692
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1693
            ->method('checkAccess')
1694
            ->with($this->equalTo('edit'));
1695
1696
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1697
            ->method('hasRoute')
1698
            ->with($this->equalTo('edit'))
1699
            ->willReturn(true);
1700
1701
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1702
            ->method('hasAccess')
1703
            ->with($this->equalTo('edit'))
1704
            ->willReturn(true);
1705
1706
        $form = $this->createMock(Form::class);
1707
1708
        $form->expects($this->once())
1709
            ->method('getData')
1710
            ->willReturn($object);
1711
1712
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1713
            ->method('getForm')
1714
            ->willReturn($form);
1715
1716
        $form->expects($this->once())
1717
            ->method('isSubmitted')
1718
            ->willReturn(true);
1719
1720
        $form->expects($this->once())
1721
            ->method('isValid')
1722
            ->willReturn(true);
1723
1724
        $form->expects($this->once())
1725
            ->method('all')
1726
            ->willReturn(['field' => 'fielddata']);
1727
1728
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1729
            ->method('toString')
1730
            ->with($this->equalTo($object))
1731
            ->willReturn($toStringValue);
1732
1733
        $this->expectTranslate('flash_edit_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1734
1735
        $this->request->setMethod('POST');
1736
1737
        $response = $this->controller->editAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::editAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1738
1739
        $this->assertInstanceOf(RedirectResponse::class, $response);
1740
        $this->assertSame(['flash_edit_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1741
        $this->assertSame('stdClass_edit', $response->getTargetUrl());
1742
    }
1743
1744
    /**
1745
     * @dataProvider getToStringValues
1746
     */
1747
    public function testEditActionError($expectedToStringValue, $toStringValue): void
1748
    {
1749
        $object = new \stdClass();
1750
1751
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1752
            ->method('getObject')
1753
            ->willReturn($object);
1754
1755
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1756
            ->method('checkAccess')
1757
            ->with($this->equalTo('edit'))
1758
            ->willReturn(true);
1759
1760
        $form = $this->createMock(Form::class);
1761
1762
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1763
            ->method('getForm')
1764
            ->willReturn($form);
1765
1766
        $form->expects($this->once())
1767
            ->method('isSubmitted')
1768
            ->willReturn(true);
1769
1770
        $form->expects($this->once())
1771
            ->method('isValid')
1772
            ->willReturn(false);
1773
1774
        $form->expects($this->once())
1775
            ->method('all')
1776
            ->willReturn(['field' => 'fielddata']);
1777
1778
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1779
            ->method('toString')
1780
            ->with($this->equalTo($object))
1781
            ->willReturn($toStringValue);
1782
1783
        $this->expectTranslate('flash_edit_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1784
1785
        $this->request->setMethod('POST');
1786
1787
        $formView = $this->createMock(FormView::class);
1788
1789
        $form->expects($this->any())
1790
            ->method('createView')
1791
            ->willReturn($formView);
1792
1793
        $this->assertInstanceOf(Response::class, $this->controller->editAction(null, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::editAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1794
1795
        $this->assertSame($this->admin, $this->parameters['admin']);
1796
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1797
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1798
1799
        $this->assertSame('edit', $this->parameters['action']);
1800
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1801
        $this->assertSame($object, $this->parameters['object']);
1802
1803
        $this->assertSame(['sonata_flash_error' => ['flash_edit_error']], $this->session->getFlashBag()->all());
1804
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1805
    }
1806
1807
    public function testEditActionAjaxSuccess(): void
1808
    {
1809
        $object = new \stdClass();
1810
1811
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1812
            ->method('getObject')
1813
            ->willReturn($object);
1814
1815
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1816
            ->method('update')
1817
            ->willReturnArgument(0);
1818
1819
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1820
            ->method('checkAccess')
1821
            ->with($this->equalTo('edit'))
1822
            ->willReturn(true);
1823
1824
        $form = $this->createMock(Form::class);
1825
1826
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1827
            ->method('getForm')
1828
            ->willReturn($form);
1829
1830
        $form->expects($this->once())
1831
            ->method('isSubmitted')
1832
            ->willReturn(true);
1833
1834
        $form->expects($this->once())
1835
            ->method('isValid')
1836
            ->willReturn(true);
1837
1838
        $form->expects($this->once())
1839
            ->method('getData')
1840
            ->willReturn($object);
1841
1842
        $form->expects($this->once())
1843
            ->method('all')
1844
            ->willReturn(['field' => 'fielddata']);
1845
1846
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() 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...
1847
            ->method('getNormalizedIdentifier')
1848
            ->with($this->equalTo($object))
1849
            ->willReturn('foo_normalized');
1850
1851
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1852
            ->method('toString')
1853
            ->willReturn('foo');
1854
1855
        $this->request->setMethod('POST');
1856
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1857
1858
        $response = $this->controller->editAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::editAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1859
1860
        $this->assertInstanceOf(Response::class, $response);
1861
        $this->assertSame(json_encode(['result' => 'ok', 'objectId' => 'foo_normalized', 'objectName' => 'foo']), $response->getContent());
1862
        $this->assertSame([], $this->session->getFlashBag()->all());
1863
    }
1864
1865
    public function testEditActionAjaxError(): void
1866
    {
1867
        $object = new \stdClass();
1868
1869
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1870
            ->method('getObject')
1871
            ->willReturn($object);
1872
1873
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1874
            ->method('checkAccess')
1875
            ->with($this->equalTo('edit'))
1876
            ->willReturn(true);
1877
1878
        $form = $this->createMock(Form::class);
1879
1880
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1881
            ->method('getForm')
1882
            ->willReturn($form);
1883
1884
        $form->expects($this->once())
1885
            ->method('isSubmitted')
1886
            ->willReturn(true);
1887
1888
        $form->expects($this->once())
1889
            ->method('isValid')
1890
            ->willReturn(false);
1891
1892
        $form->expects($this->once())
1893
            ->method('all')
1894
            ->willReturn(['field' => 'fielddata']);
1895
1896
        $formError = $this->createMock(FormError::class);
1897
        $formError->expects($this->atLeastOnce())
1898
            ->method('getMessage')
1899
            ->willReturn('Form error message');
1900
1901
        $form->expects($this->once())
1902
            ->method('getErrors')
1903
            ->with(true)
1904
            ->willReturn([$formError]);
1905
1906
        $this->request->setMethod('POST');
1907
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1908
        $this->request->headers->set('Accept', 'application/json');
1909
1910
        $this->assertInstanceOf(JsonResponse::class, $response = $this->controller->editAction(null, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::editAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1911
        $this->assertJsonStringEqualsJsonString('{"result":"error","errors":["Form error message"]}', $response->getContent());
0 ignored issues
show
Security Bug introduced by
It seems like $response->getContent() targeting Symfony\Component\HttpFo...\Response::getContent() can also be of type false; however, PHPUnit\Framework\Assert...tringEqualsJsonString() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
1912
    }
1913
1914
    /**
1915
     * @legacy
1916
     * @expectedDeprecation In next major version response will return 406 NOT ACCEPTABLE without `Accept: application/json`
1917
     */
1918
    public function testEditActionAjaxErrorWithoutAcceptApplicationJson(): void
1919
    {
1920
        $object = new \stdClass();
1921
1922
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1923
            ->method('getObject')
1924
            ->willReturn($object);
1925
1926
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1927
            ->method('checkAccess')
1928
            ->with($this->equalTo('edit'))
1929
            ->willReturn(true);
1930
1931
        $form = $this->createMock(Form::class);
1932
1933
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1934
            ->method('getForm')
1935
            ->willReturn($form);
1936
1937
        $form->expects($this->once())
1938
            ->method('isSubmitted')
1939
            ->willReturn(true);
1940
1941
        $form->expects($this->once())
1942
            ->method('isValid')
1943
            ->willReturn(false);
1944
1945
        $form->expects($this->once())
1946
            ->method('all')
1947
            ->willReturn(['field' => 'fielddata']);
1948
1949
        $this->request->setMethod('POST');
1950
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1951
1952
        $formView = $this->createMock(FormView::class);
1953
        $form
1954
            ->method('createView')
1955
            ->willReturn($formView);
1956
1957
        $this->assertInstanceOf(Response::class, $response = $this->controller->editAction(null, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::editAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1958
        $this->assertSame($this->admin, $this->parameters['admin']);
1959
        $this->assertSame('@SonataAdmin/ajax_layout.html.twig', $this->parameters['base_template']);
1960
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1961
        $this->assertSame('edit', $this->parameters['action']);
1962
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1963
        $this->assertSame($object, $this->parameters['object']);
1964
        $this->assertSame(['sonata_flash_error' => [0 => null]], $this->session->getFlashBag()->all());
1965
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1966
    }
1967
1968
    /**
1969
     * @dataProvider getToStringValues
1970
     */
1971
    public function testEditActionWithModelManagerException($expectedToStringValue, $toStringValue): void
1972
    {
1973
        $object = new \stdClass();
1974
1975
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1976
            ->method('getObject')
1977
            ->willReturn($object);
1978
1979
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1980
            ->method('checkAccess')
1981
            ->with($this->equalTo('edit'))
1982
            ->willReturn(true);
1983
1984
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1985
            ->method('getClass')
1986
            ->willReturn('stdClass');
1987
1988
        $form = $this->createMock(Form::class);
1989
1990
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
1991
            ->method('getForm')
1992
            ->willReturn($form);
1993
1994
        $form->expects($this->once())
1995
            ->method('isValid')
1996
            ->willReturn(true);
1997
1998
        $form->expects($this->once())
1999
            ->method('getData')
2000
            ->willReturn($object);
2001
2002
        $form->expects($this->once())
2003
            ->method('all')
2004
            ->willReturn(['field' => 'fielddata']);
2005
2006
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2007
            ->method('toString')
2008
            ->with($this->equalTo($object))
2009
            ->willReturn($toStringValue);
2010
2011
        $this->expectTranslate('flash_edit_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
2012
2013
        $form->expects($this->once())
2014
            ->method('isSubmitted')
2015
            ->willReturn(true);
2016
        $this->request->setMethod('POST');
2017
2018
        $formView = $this->createMock(FormView::class);
2019
2020
        $form->expects($this->any())
2021
            ->method('createView')
2022
            ->willReturn($formView);
2023
2024
        $this->assertLoggerLogsModelManagerException($this->admin, 'update');
2025
        $this->assertInstanceOf(Response::class, $this->controller->editAction(null, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::editAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2026
2027
        $this->assertSame($this->admin, $this->parameters['admin']);
2028
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2029
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2030
2031
        $this->assertSame('edit', $this->parameters['action']);
2032
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2033
        $this->assertSame($object, $this->parameters['object']);
2034
2035
        $this->assertSame(['sonata_flash_error' => ['flash_edit_error']], $this->session->getFlashBag()->all());
2036
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
2037
    }
2038
2039
    public function testEditActionWithPreview(): void
2040
    {
2041
        $object = new \stdClass();
2042
2043
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2044
            ->method('getObject')
2045
            ->willReturn($object);
2046
2047
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2048
            ->method('checkAccess')
2049
            ->with($this->equalTo('edit'))
2050
            ->willReturn(true);
2051
2052
        $form = $this->createMock(Form::class);
2053
2054
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2055
            ->method('getForm')
2056
            ->willReturn($form);
2057
2058
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2059
            ->method('supportsPreviewMode')
2060
            ->willReturn(true);
2061
2062
        $formView = $this->createMock(FormView::class);
2063
2064
        $form->expects($this->any())
2065
            ->method('createView')
2066
            ->willReturn($formView);
2067
2068
        $form->expects($this->once())
2069
            ->method('isSubmitted')
2070
            ->willReturn(true);
2071
2072
        $form->expects($this->once())
2073
            ->method('isValid')
2074
            ->willReturn(true);
2075
2076
        $form->expects($this->once())
2077
            ->method('all')
2078
            ->willReturn(['field' => 'fielddata']);
2079
2080
        $this->request->setMethod('POST');
2081
        $this->request->request->set('btn_preview', 'Preview');
2082
2083
        $this->assertInstanceOf(Response::class, $this->controller->editAction(null, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::editAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2084
2085
        $this->assertSame($this->admin, $this->parameters['admin']);
2086
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2087
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2088
2089
        $this->assertSame('edit', $this->parameters['action']);
2090
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2091
        $this->assertSame($object, $this->parameters['object']);
2092
2093
        $this->assertSame([], $this->session->getFlashBag()->all());
2094
        $this->assertSame('@SonataAdmin/CRUD/preview.html.twig', $this->template);
2095
    }
2096
2097
    public function testEditActionWithLockException(): void
2098
    {
2099
        $object = new \stdClass();
2100
        $class = \get_class($object);
2101
2102
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2103
            ->method('getObject')
2104
            ->willReturn($object);
2105
2106
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2107
            ->method('checkAccess')
2108
            ->with($this->equalTo('edit'))
2109
            ->willReturn(true);
2110
2111
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2112
            ->method('getClass')
2113
            ->willReturn($class);
2114
2115
        $form = $this->createMock(Form::class);
2116
2117
        $form->expects($this->any())
2118
            ->method('isValid')
2119
            ->willReturn(true);
2120
2121
        $form->expects($this->once())
2122
            ->method('getData')
2123
            ->willReturn($object);
2124
2125
        $form->expects($this->once())
2126
            ->method('all')
2127
            ->willReturn(['field' => 'fielddata']);
2128
2129
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2130
            ->method('getForm')
2131
            ->willReturn($form);
2132
2133
        $form->expects($this->any())
2134
            ->method('isSubmitted')
2135
            ->willReturn(true);
2136
        $this->request->setMethod('POST');
2137
2138
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2139
            ->method('update')
2140
            ->will($this->throwException(new LockException()));
2141
2142
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2143
            ->method('toString')
2144
            ->with($this->equalTo($object))
2145
            ->willReturn($class);
2146
2147
        $formView = $this->createMock(FormView::class);
2148
2149
        $form->expects($this->any())
2150
            ->method('createView')
2151
            ->willReturn($formView);
2152
2153
        $this->expectTranslate('flash_lock_error', [
2154
            '%name%' => $class,
2155
            '%link_start%' => '<a href="stdClass_edit">',
2156
            '%link_end%' => '</a>',
2157
        ], 'SonataAdminBundle');
2158
2159
        $this->assertInstanceOf(Response::class, $this->controller->editAction(null, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::editAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2160
    }
2161
2162
    public function testCreateActionAccessDenied(): void
2163
    {
2164
        $this->expectException(AccessDeniedException::class);
2165
2166
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2167
            ->method('checkAccess')
2168
            ->with($this->equalTo('create'))
2169
            ->will($this->throwException(new AccessDeniedException()));
2170
2171
        $this->controller->createAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::createAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2172
    }
2173
2174
    public function testCreateActionRuntimeException(): void
2175
    {
2176
        $this->expectException(\RuntimeException::class);
2177
2178
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2179
            ->method('checkAccess')
2180
            ->with($this->equalTo('create'))
2181
            ->willReturn(true);
2182
2183
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2184
            ->method('getClass')
2185
            ->willReturn('stdClass');
2186
2187
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2188
            ->method('getNewInstance')
2189
            ->willReturn(new \stdClass());
2190
2191
        $form = $this->createMock(Form::class);
2192
2193
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2194
            ->method('getForm')
2195
            ->willReturn($form);
2196
2197
        $form->expects($this->once())
2198
            ->method('all')
2199
            ->willReturn([]);
2200
2201
        $this->controller->createAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::createAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2202
    }
2203
2204
    public function testPreCreate(): void
2205
    {
2206
        $object = new \stdClass();
2207
        $object->foo = 123456;
2208
2209
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2210
            ->method('checkAccess')
2211
            ->with($this->equalTo('create'))
2212
            ->willReturn(true);
2213
2214
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2215
            ->method('getClass')
2216
            ->willReturn('stdClass');
2217
2218
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2219
            ->method('getNewInstance')
2220
            ->willReturn($object);
2221
2222
        $controller = new PreCRUDController();
2223
        $controller->setContainer($this->container);
2224
2225
        $response = $controller->createAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to PreCRUDController::createAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2226
        $this->assertInstanceOf(Response::class, $response);
2227
        $this->assertSame('preCreate called: 123456', $response->getContent());
2228
    }
2229
2230
    public function testCreateAction(): void
2231
    {
2232
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2233
            ->method('checkAccess')
2234
            ->with($this->equalTo('create'))
2235
            ->willReturn(true);
2236
2237
        $object = new \stdClass();
2238
2239
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2240
            ->method('getClass')
2241
            ->willReturn('stdClass');
2242
2243
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2244
            ->method('getNewInstance')
2245
            ->willReturn($object);
2246
2247
        $form = $this->createMock(Form::class);
2248
2249
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2250
            ->method('getForm')
2251
            ->willReturn($form);
2252
2253
        $form->expects($this->once())
2254
            ->method('all')
2255
            ->willReturn(['field' => 'fielddata']);
2256
2257
        $formView = $this->createMock(FormView::class);
2258
2259
        $form->expects($this->any())
2260
            ->method('createView')
2261
            ->willReturn($formView);
2262
2263
        $this->assertInstanceOf(Response::class, $this->controller->createAction($this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::createAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2264
2265
        $this->assertSame($this->admin, $this->parameters['admin']);
2266
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2267
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2268
2269
        $this->assertSame('create', $this->parameters['action']);
2270
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2271
        $this->assertSame($object, $this->parameters['object']);
2272
2273
        $this->assertSame([], $this->session->getFlashBag()->all());
2274
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
2275
    }
2276
2277
    /**
2278
     * @dataProvider getToStringValues
2279
     */
2280
    public function testCreateActionSuccess($expectedToStringValue, $toStringValue): void
2281
    {
2282
        $object = new \stdClass();
2283
2284
        $this->admin->expects($this->exactly(2))
0 ignored issues
show
Bug introduced by
The method expects() 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...
2285
            ->method('checkAccess')
2286
            ->willReturnCallback(static function ($name, $objectIn = null) use ($object) {
2287
                if ('edit' === $name) {
2288
                    return true;
2289
                }
2290
2291
                if ('create' !== $name) {
2292
                    return false;
2293
                }
2294
2295
                if (null === $objectIn) {
2296
                    return true;
2297
                }
2298
2299
                return $objectIn === $object;
2300
            });
2301
2302
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2303
            ->method('hasRoute')
2304
            ->with($this->equalTo('edit'))
2305
            ->willReturn(true);
2306
2307
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2308
            ->method('hasAccess')
2309
            ->with($this->equalTo('edit'))
2310
            ->willReturn(true);
2311
2312
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2313
            ->method('getNewInstance')
2314
            ->willReturn($object);
2315
2316
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2317
            ->method('create')
2318
            ->willReturnArgument(0);
2319
2320
        $form = $this->createMock(Form::class);
2321
2322
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2323
            ->method('getClass')
2324
            ->willReturn('stdClass');
2325
2326
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2327
            ->method('getForm')
2328
            ->willReturn($form);
2329
2330
        $form->expects($this->once())
2331
            ->method('all')
2332
            ->willReturn(['field' => 'fielddata']);
2333
2334
        $form->expects($this->once())
2335
            ->method('isSubmitted')
2336
            ->willReturn(true);
2337
2338
        $form->expects($this->once())
2339
            ->method('isValid')
2340
            ->willReturn(true);
2341
2342
        $form->expects($this->once())
2343
            ->method('getData')
2344
            ->willReturn($object);
2345
2346
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2347
            ->method('toString')
2348
            ->with($this->equalTo($object))
2349
            ->willReturn($toStringValue);
2350
2351
        $this->expectTranslate('flash_create_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
2352
2353
        $this->request->setMethod('POST');
2354
2355
        $response = $this->controller->createAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::createAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2356
2357
        $this->assertInstanceOf(RedirectResponse::class, $response);
2358
        $this->assertSame(['flash_create_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
2359
        $this->assertSame('stdClass_edit', $response->getTargetUrl());
2360
    }
2361
2362
    public function testCreateActionAccessDenied2(): void
2363
    {
2364
        $this->expectException(AccessDeniedException::class);
2365
2366
        $object = new \stdClass();
2367
2368
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2369
            ->method('checkAccess')
2370
            ->willReturnCallback(static function ($name, $object = null) {
2371
                if ('create' !== $name) {
2372
                    throw new AccessDeniedException();
2373
                }
2374
                if (null === $object) {
2375
                    return true;
2376
                }
2377
2378
                throw new AccessDeniedException();
2379
            });
2380
2381
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2382
            ->method('getNewInstance')
2383
            ->willReturn($object);
2384
2385
        $form = $this->createMock(Form::class);
2386
2387
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2388
            ->method('getClass')
2389
            ->willReturn('stdClass');
2390
2391
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2392
            ->method('getForm')
2393
            ->willReturn($form);
2394
2395
        $form->expects($this->once())
2396
            ->method('all')
2397
            ->willReturn(['field' => 'fielddata']);
2398
2399
        $form->expects($this->once())
2400
            ->method('isSubmitted')
2401
            ->willReturn(true);
2402
2403
        $form->expects($this->once())
2404
            ->method('getData')
2405
            ->willReturn($object);
2406
2407
        $form->expects($this->once())
2408
            ->method('isValid')
2409
            ->willReturn(true);
2410
2411
        $this->request->setMethod('POST');
2412
2413
        $this->controller->createAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::createAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2414
    }
2415
2416
    /**
2417
     * @dataProvider getToStringValues
2418
     */
2419
    public function testCreateActionError($expectedToStringValue, $toStringValue): void
2420
    {
2421
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2422
            ->method('checkAccess')
2423
            ->with($this->equalTo('create'))
2424
            ->willReturn(true);
2425
2426
        $object = new \stdClass();
2427
2428
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2429
            ->method('getClass')
2430
            ->willReturn('stdClass');
2431
2432
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2433
            ->method('getNewInstance')
2434
            ->willReturn($object);
2435
2436
        $form = $this->createMock(Form::class);
2437
2438
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2439
            ->method('getForm')
2440
            ->willReturn($form);
2441
2442
        $form->expects($this->once())
2443
            ->method('all')
2444
            ->willReturn(['field' => 'fielddata']);
2445
2446
        $form->expects($this->once())
2447
            ->method('isSubmitted')
2448
            ->willReturn(true);
2449
2450
        $form->expects($this->once())
2451
            ->method('isValid')
2452
            ->willReturn(false);
2453
2454
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2455
            ->method('toString')
2456
            ->with($this->equalTo($object))
2457
            ->willReturn($toStringValue);
2458
2459
        $this->expectTranslate('flash_create_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
2460
2461
        $this->request->setMethod('POST');
2462
2463
        $formView = $this->createMock(FormView::class);
2464
2465
        $form->expects($this->any())
2466
            ->method('createView')
2467
            ->willReturn($formView);
2468
2469
        $this->assertInstanceOf(Response::class, $this->controller->createAction($this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::createAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2470
2471
        $this->assertSame($this->admin, $this->parameters['admin']);
2472
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2473
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2474
2475
        $this->assertSame('create', $this->parameters['action']);
2476
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2477
        $this->assertSame($object, $this->parameters['object']);
2478
2479
        $this->assertSame(['sonata_flash_error' => ['flash_create_error']], $this->session->getFlashBag()->all());
2480
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
2481
    }
2482
2483
    /**
2484
     * @dataProvider getToStringValues
2485
     */
2486
    public function testCreateActionWithModelManagerException($expectedToStringValue, $toStringValue): void
2487
    {
2488
        $this->admin->expects($this->exactly(2))
0 ignored issues
show
Bug introduced by
The method expects() 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...
2489
            ->method('checkAccess')
2490
            ->with($this->equalTo('create'))
2491
            ->willReturn(true);
2492
2493
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2494
            ->method('getClass')
2495
            ->willReturn('stdClass');
2496
2497
        $object = new \stdClass();
2498
2499
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2500
            ->method('getNewInstance')
2501
            ->willReturn($object);
2502
2503
        $form = $this->createMock(Form::class);
2504
2505
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2506
            ->method('getForm')
2507
            ->willReturn($form);
2508
2509
        $form->expects($this->once())
2510
            ->method('all')
2511
            ->willReturn(['field' => 'fielddata']);
2512
2513
        $form->expects($this->once())
2514
            ->method('isValid')
2515
            ->willReturn(true);
2516
2517
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2518
            ->method('toString')
2519
            ->with($this->equalTo($object))
2520
            ->willReturn($toStringValue);
2521
2522
        $this->expectTranslate('flash_create_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
2523
2524
        $form->expects($this->once())
2525
            ->method('isSubmitted')
2526
            ->willReturn(true);
2527
2528
        $form->expects($this->once())
2529
            ->method('getData')
2530
            ->willReturn($object);
2531
2532
        $this->request->setMethod('POST');
2533
2534
        $formView = $this->createMock(FormView::class);
2535
2536
        $form->expects($this->any())
2537
            ->method('createView')
2538
            ->willReturn($formView);
2539
2540
        $this->assertLoggerLogsModelManagerException($this->admin, 'create');
2541
2542
        $this->assertInstanceOf(Response::class, $this->controller->createAction($this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::createAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2543
2544
        $this->assertSame($this->admin, $this->parameters['admin']);
2545
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2546
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2547
2548
        $this->assertSame('create', $this->parameters['action']);
2549
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2550
        $this->assertSame($object, $this->parameters['object']);
2551
2552
        $this->assertSame(['sonata_flash_error' => ['flash_create_error']], $this->session->getFlashBag()->all());
2553
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
2554
    }
2555
2556
    public function testCreateActionAjaxSuccess(): void
2557
    {
2558
        $object = new \stdClass();
2559
2560
        $this->admin->expects($this->exactly(2))
0 ignored issues
show
Bug introduced by
The method expects() 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...
2561
            ->method('checkAccess')
2562
            ->willReturnCallback(static function ($name, $objectIn = null) use ($object) {
2563
                if ('create' !== $name) {
2564
                    return false;
2565
                }
2566
2567
                if (null === $objectIn) {
2568
                    return true;
2569
                }
2570
2571
                return $objectIn === $object;
2572
            });
2573
2574
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2575
            ->method('getNewInstance')
2576
            ->willReturn($object);
2577
2578
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2579
            ->method('create')
2580
            ->willReturnArgument(0);
2581
2582
        $form = $this->createMock(Form::class);
2583
2584
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2585
            ->method('getForm')
2586
            ->willReturn($form);
2587
2588
        $form->expects($this->once())
2589
            ->method('all')
2590
            ->willReturn(['field' => 'fielddata']);
2591
2592
        $form->expects($this->once())
2593
            ->method('isSubmitted')
2594
            ->willReturn(true);
2595
2596
        $form->expects($this->once())
2597
            ->method('isValid')
2598
            ->willReturn(true);
2599
2600
        $form->expects($this->once())
2601
            ->method('getData')
2602
            ->willReturn($object);
2603
2604
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2605
            ->method('getClass')
2606
            ->willReturn('stdClass');
2607
2608
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2609
            ->method('getNormalizedIdentifier')
2610
            ->with($this->equalTo($object))
2611
            ->willReturn('foo_normalized');
2612
2613
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2614
            ->method('toString')
2615
            ->willReturn('foo');
2616
2617
        $this->request->setMethod('POST');
2618
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
2619
2620
        $response = $this->controller->createAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::createAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2621
2622
        $this->assertInstanceOf(Response::class, $response);
2623
        $this->assertSame(json_encode(['result' => 'ok', 'objectId' => 'foo_normalized', 'objectName' => 'foo']), $response->getContent());
2624
        $this->assertSame([], $this->session->getFlashBag()->all());
2625
    }
2626
2627
    public function testCreateActionAjaxError(): void
2628
    {
2629
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2630
            ->method('checkAccess')
2631
            ->with($this->equalTo('create'))
2632
            ->willReturn(true);
2633
2634
        $object = new \stdClass();
2635
2636
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2637
            ->method('getNewInstance')
2638
            ->willReturn($object);
2639
2640
        $form = $this->createMock(Form::class);
2641
2642
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2643
            ->method('getClass')
2644
            ->willReturn('stdClass');
2645
2646
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2647
            ->method('getForm')
2648
            ->willReturn($form);
2649
2650
        $form->expects($this->once())
2651
            ->method('all')
2652
            ->willReturn(['field' => 'fielddata']);
2653
2654
        $form->expects($this->once())
2655
            ->method('isSubmitted')
2656
            ->willReturn(true);
2657
2658
        $form->expects($this->once())
2659
            ->method('isValid')
2660
            ->willReturn(false);
2661
2662
        $formError = $this->createMock(FormError::class);
2663
        $formError->expects($this->atLeastOnce())
2664
            ->method('getMessage')
2665
            ->willReturn('Form error message');
2666
2667
        $form->expects($this->once())
2668
            ->method('getErrors')
2669
            ->with(true)
2670
            ->willReturn([$formError]);
2671
2672
        $this->request->setMethod('POST');
2673
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
2674
        $this->request->headers->set('Accept', 'application/json');
2675
2676
        $this->assertInstanceOf(JsonResponse::class, $response = $this->controller->createAction($this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::createAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2677
        $this->assertJsonStringEqualsJsonString('{"result":"error","errors":["Form error message"]}', $response->getContent());
0 ignored issues
show
Security Bug introduced by
It seems like $response->getContent() targeting Symfony\Component\HttpFo...\Response::getContent() can also be of type false; however, PHPUnit\Framework\Assert...tringEqualsJsonString() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
2678
    }
2679
2680
    /**
2681
     * @legacy
2682
     * @expectedDeprecation In next major version response will return 406 NOT ACCEPTABLE without `Accept: application/json`
2683
     */
2684
    public function testCreateActionAjaxErrorWithoutAcceptApplicationJson(): void
2685
    {
2686
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2687
            ->method('checkAccess')
2688
            ->with($this->equalTo('create'))
2689
            ->willReturn(true);
2690
2691
        $object = new \stdClass();
2692
2693
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2694
            ->method('getNewInstance')
2695
            ->willReturn($object);
2696
2697
        $form = $this->createMock(Form::class);
2698
2699
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2700
            ->method('getClass')
2701
            ->willReturn('stdClass');
2702
2703
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2704
            ->method('getForm')
2705
            ->willReturn($form);
2706
2707
        $form->expects($this->once())
2708
            ->method('all')
2709
            ->willReturn(['field' => 'fielddata']);
2710
2711
        $form->expects($this->once())
2712
            ->method('isSubmitted')
2713
            ->willReturn(true);
2714
2715
        $form->expects($this->once())
2716
            ->method('isValid')
2717
            ->willReturn(false);
2718
2719
        $this->request->setMethod('POST');
2720
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
2721
2722
        $formView = $this->createMock(FormView::class);
2723
        $form
2724
            ->method('createView')
2725
            ->willReturn($formView);
2726
2727
        $this->assertInstanceOf(Response::class, $response = $this->controller->createAction($this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::createAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2728
        $this->assertSame($this->admin, $this->parameters['admin']);
2729
        $this->assertSame('@SonataAdmin/ajax_layout.html.twig', $this->parameters['base_template']);
2730
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2731
        $this->assertSame('create', $this->parameters['action']);
2732
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2733
        $this->assertSame($object, $this->parameters['object']);
2734
        $this->assertSame(['sonata_flash_error' => [0 => null]], $this->session->getFlashBag()->all());
2735
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
2736
    }
2737
2738
    public function testCreateActionWithPreview(): void
2739
    {
2740
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2741
            ->method('checkAccess')
2742
            ->with($this->equalTo('create'))
2743
            ->willReturn(true);
2744
2745
        $object = new \stdClass();
2746
2747
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2748
            ->method('getNewInstance')
2749
            ->willReturn($object);
2750
2751
        $form = $this->createMock(Form::class);
2752
2753
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2754
            ->method('getClass')
2755
            ->willReturn('stdClass');
2756
2757
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2758
            ->method('getForm')
2759
            ->willReturn($form);
2760
2761
        $form->expects($this->once())
2762
            ->method('all')
2763
            ->willReturn(['field' => 'fielddata']);
2764
2765
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2766
            ->method('supportsPreviewMode')
2767
            ->willReturn(true);
2768
2769
        $formView = $this->createMock(FormView::class);
2770
2771
        $form->expects($this->any())
2772
            ->method('createView')
2773
            ->willReturn($formView);
2774
2775
        $form->expects($this->once())
2776
            ->method('isSubmitted')
2777
            ->willReturn(true);
2778
2779
        $form->expects($this->once())
2780
            ->method('isValid')
2781
            ->willReturn(true);
2782
2783
        $this->request->setMethod('POST');
2784
        $this->request->request->set('btn_preview', 'Preview');
2785
2786
        $this->assertInstanceOf(Response::class, $this->controller->createAction($this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::createAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2787
2788
        $this->assertSame($this->admin, $this->parameters['admin']);
2789
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2790
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2791
2792
        $this->assertSame('create', $this->parameters['action']);
2793
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2794
        $this->assertSame($object, $this->parameters['object']);
2795
2796
        $this->assertSame([], $this->session->getFlashBag()->all());
2797
        $this->assertSame('@SonataAdmin/CRUD/preview.html.twig', $this->template);
2798
    }
2799
2800
    public function testExportActionAccessDenied(): void
2801
    {
2802
        $this->expectException(AccessDeniedException::class);
2803
2804
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2805
            ->method('checkAccess')
2806
            ->with($this->equalTo('export'))
2807
            ->will($this->throwException(new AccessDeniedException()));
2808
2809
        $this->controller->exportAction($this->request);
2810
    }
2811
2812
    public function testExportActionWrongFormat(): void
2813
    {
2814
        $this->expectException(\RuntimeException::class, 'Export in format `csv` is not allowed for class: `Foo`. Allowed formats are: `json`');
0 ignored issues
show
Unused Code introduced by
The call to CRUDControllerTest::expectException() has too many arguments starting with 'Export in format `csv` ...ed formats are: `json`'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2815
2816
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2817
            ->method('checkAccess')
2818
            ->with($this->equalTo('export'))
2819
            ->willReturn(true);
2820
2821
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2822
            ->method('getExportFormats')
2823
            ->willReturn(['json']);
2824
2825
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2826
            ->method('getClass')
2827
            ->willReturn('Foo');
2828
2829
        $this->request->query->set('format', 'csv');
2830
2831
        $this->controller->exportAction($this->request);
2832
    }
2833
2834
    public function testExportAction(): void
2835
    {
2836
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2837
            ->method('checkAccess')
2838
            ->with($this->equalTo('export'))
2839
            ->willReturn(true);
2840
2841
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2842
            ->method('getExportFormats')
2843
            ->willReturn(['json']);
2844
2845
        $dataSourceIterator = $this->createMock(SourceIteratorInterface::class);
2846
2847
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2848
            ->method('getDataSourceIterator')
2849
            ->willReturn($dataSourceIterator);
2850
2851
        $this->request->query->set('format', 'json');
2852
2853
        $response = $this->controller->exportAction($this->request);
2854
        $this->assertInstanceOf(StreamedResponse::class, $response);
2855
        $this->assertSame(200, $response->getStatusCode());
2856
        $this->assertSame([], $this->session->getFlashBag()->all());
2857
    }
2858
2859
    public function testHistoryActionAccessDenied(): void
2860
    {
2861
        $this->expectException(AccessDeniedException::class);
2862
2863
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2864
            ->method('getObject')
2865
            ->willReturn(new \StdClass());
2866
2867
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2868
            ->method('checkAccess')
2869
            ->with($this->equalTo('history'))
2870
            ->will($this->throwException(new AccessDeniedException()));
2871
2872
        $this->controller->historyAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::historyAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2873
    }
2874
2875
    public function testHistoryActionNotFoundException(): void
2876
    {
2877
        $this->expectException(NotFoundHttpException::class);
2878
2879
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2880
            ->method('getObject')
2881
            ->willReturn(false);
2882
2883
        $this->controller->historyAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::historyAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2884
    }
2885
2886
    public function testHistoryActionNoReader(): void
2887
    {
2888
        $this->expectException(NotFoundHttpException::class, 'unable to find the audit reader for class : Foo');
0 ignored issues
show
Unused Code introduced by
The call to CRUDControllerTest::expectException() has too many arguments starting with 'unable to find the audit reader for class : Foo'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2889
2890
        $this->request->query->set('id', 123);
2891
2892
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2893
            ->method('checkAccess')
2894
            ->with($this->equalTo('history'))
2895
            ->willReturn(true);
2896
2897
        $object = new \stdClass();
2898
2899
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2900
            ->method('getObject')
2901
            ->willReturn($object);
2902
2903
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2904
            ->method('getClass')
2905
            ->willReturn('Foo');
2906
2907
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

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...
2908
            ->method('hasReader')
2909
            ->with($this->equalTo('Foo'))
2910
            ->willReturn(false);
2911
2912
        $this->controller->historyAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::historyAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2913
    }
2914
2915
    public function testHistoryAction(): void
2916
    {
2917
        $this->request->query->set('id', 123);
2918
2919
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2920
            ->method('checkAccess')
2921
            ->with($this->equalTo('history'))
2922
            ->willReturn(true);
2923
2924
        $object = new \stdClass();
2925
2926
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2927
            ->method('getObject')
2928
            ->willReturn($object);
2929
2930
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2931
            ->method('getClass')
2932
            ->willReturn('Foo');
2933
2934
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

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...
2935
            ->method('hasReader')
2936
            ->with($this->equalTo('Foo'))
2937
            ->willReturn(true);
2938
2939
        $reader = $this->createMock(AuditReaderInterface::class);
2940
2941
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

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...
2942
            ->method('getReader')
2943
            ->with($this->equalTo('Foo'))
2944
            ->willReturn($reader);
2945
2946
        $reader->expects($this->once())
2947
            ->method('findRevisions')
2948
            ->with($this->equalTo('Foo'), $this->equalTo(123))
2949
            ->willReturn([]);
2950
2951
        $this->assertInstanceOf(Response::class, $this->controller->historyAction(null, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::historyAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2952
2953
        $this->assertSame($this->admin, $this->parameters['admin']);
2954
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2955
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2956
2957
        $this->assertSame('history', $this->parameters['action']);
2958
        $this->assertSame([], $this->parameters['revisions']);
2959
        $this->assertSame($object, $this->parameters['object']);
2960
2961
        $this->assertSame([], $this->session->getFlashBag()->all());
2962
        $this->assertSame('@SonataAdmin/CRUD/history.html.twig', $this->template);
2963
    }
2964
2965
    public function testAclActionAclNotEnabled(): void
2966
    {
2967
        $this->expectException(NotFoundHttpException::class, 'ACL are not enabled for this admin');
0 ignored issues
show
Unused Code introduced by
The call to CRUDControllerTest::expectException() has too many arguments starting with 'ACL are not enabled for this admin'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2968
2969
        $this->controller->aclAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::aclAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2970
    }
2971
2972
    public function testAclActionNotFoundException(): void
2973
    {
2974
        $this->expectException(NotFoundHttpException::class);
2975
2976
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2977
            ->method('isAclEnabled')
2978
            ->willReturn(true);
2979
2980
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2981
            ->method('getObject')
2982
            ->willReturn(false);
2983
2984
        $this->controller->aclAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::aclAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2985
    }
2986
2987
    public function testAclActionAccessDenied(): void
2988
    {
2989
        $this->expectException(AccessDeniedException::class);
2990
2991
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2992
            ->method('isAclEnabled')
2993
            ->willReturn(true);
2994
2995
        $object = new \stdClass();
2996
2997
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
2998
            ->method('getObject')
2999
            ->willReturn($object);
3000
3001
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3002
            ->method('checkAccess')
3003
            ->with($this->equalTo('acl'), $this->equalTo($object))
3004
            ->will($this->throwException(new AccessDeniedException()));
3005
3006
        $this->controller->aclAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::aclAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3007
    }
3008
3009
    public function testAclAction(): void
3010
    {
3011
        $this->request->query->set('id', 123);
3012
3013
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3014
            ->method('isAclEnabled')
3015
            ->willReturn(true);
3016
3017
        $object = new \stdClass();
3018
3019
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3020
            ->method('getObject')
3021
            ->willReturn($object);
3022
3023
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3024
            ->method('checkAccess')
3025
            ->willReturn(true);
3026
3027
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3028
            ->method('getSecurityInformation')
3029
            ->willReturn([]);
3030
3031
        $this->adminObjectAclManipulator->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...inObjectAclManipulator>.

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...
3032
            ->method('getMaskBuilderClass')
3033
            ->willReturn(AdminPermissionMap::class);
3034
3035
        $aclUsersForm = $this->getMockBuilder(Form::class)
3036
            ->disableOriginalConstructor()
3037
            ->getMock();
3038
3039
        $aclUsersForm->expects($this->once())
3040
            ->method('createView')
3041
            ->willReturn($this->createMock(FormView::class));
3042
3043
        $aclRolesForm = $this->getMockBuilder(Form::class)
3044
            ->disableOriginalConstructor()
3045
            ->getMock();
3046
3047
        $aclRolesForm->expects($this->once())
3048
            ->method('createView')
3049
            ->willReturn($this->createMock(FormView::class));
3050
3051
        $this->adminObjectAclManipulator->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...inObjectAclManipulator>.

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...
3052
            ->method('createAclUsersForm')
3053
            ->with($this->isInstanceOf(AdminObjectAclData::class))
3054
            ->willReturn($aclUsersForm);
3055
3056
        $this->adminObjectAclManipulator->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...inObjectAclManipulator>.

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...
3057
            ->method('createAclRolesForm')
3058
            ->with($this->isInstanceOf(AdminObjectAclData::class))
3059
            ->willReturn($aclRolesForm);
3060
3061
        $aclSecurityHandler = $this->getMockBuilder(AclSecurityHandler::class)
3062
            ->disableOriginalConstructor()
3063
            ->getMock();
3064
3065
        $aclSecurityHandler->expects($this->any())
3066
            ->method('getObjectPermissions')
3067
            ->willReturn([]);
3068
3069
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3070
            ->method('getSecurityHandler')
3071
            ->willReturn($aclSecurityHandler);
3072
3073
        $this->assertInstanceOf(Response::class, $this->controller->aclAction(null, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::aclAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3074
3075
        $this->assertSame($this->admin, $this->parameters['admin']);
3076
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
3077
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3078
3079
        $this->assertSame('acl', $this->parameters['action']);
3080
        $this->assertSame([], $this->parameters['permissions']);
3081
        $this->assertSame($object, $this->parameters['object']);
3082
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['users']);
3083
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['roles']);
3084
        $this->assertInstanceOf(FormView::class, $this->parameters['aclUsersForm']);
3085
        $this->assertInstanceOf(FormView::class, $this->parameters['aclRolesForm']);
3086
3087
        $this->assertSame([], $this->session->getFlashBag()->all());
3088
        $this->assertSame('@SonataAdmin/CRUD/acl.html.twig', $this->template);
3089
    }
3090
3091
    public function testAclActionInvalidUpdate(): void
3092
    {
3093
        $this->request->query->set('id', 123);
3094
        $this->request->request->set(AdminObjectAclManipulator::ACL_USERS_FORM_NAME, []);
3095
3096
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3097
            ->method('isAclEnabled')
3098
            ->willReturn(true);
3099
3100
        $object = new \stdClass();
3101
3102
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3103
            ->method('getObject')
3104
            ->willReturn($object);
3105
3106
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3107
            ->method('checkAccess')
3108
            ->willReturn(true);
3109
3110
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3111
            ->method('getSecurityInformation')
3112
            ->willReturn([]);
3113
3114
        $this->adminObjectAclManipulator->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...inObjectAclManipulator>.

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...
3115
            ->method('getMaskBuilderClass')
3116
            ->willReturn(AdminPermissionMap::class);
3117
3118
        $aclUsersForm = $this->getMockBuilder(Form::class)
3119
            ->disableOriginalConstructor()
3120
            ->getMock();
3121
3122
        $aclUsersForm->expects($this->once())
3123
            ->method('isValid')
3124
            ->willReturn(false);
3125
3126
        $aclUsersForm->expects($this->once())
3127
            ->method('createView')
3128
            ->willReturn($this->createMock(FormView::class));
3129
3130
        $aclRolesForm = $this->getMockBuilder(Form::class)
3131
            ->disableOriginalConstructor()
3132
            ->getMock();
3133
3134
        $aclRolesForm->expects($this->once())
3135
            ->method('createView')
3136
            ->willReturn($this->createMock(FormView::class));
3137
3138
        $this->adminObjectAclManipulator->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...inObjectAclManipulator>.

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...
3139
            ->method('createAclUsersForm')
3140
            ->with($this->isInstanceOf(AdminObjectAclData::class))
3141
            ->willReturn($aclUsersForm);
3142
3143
        $this->adminObjectAclManipulator->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...inObjectAclManipulator>.

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...
3144
            ->method('createAclRolesForm')
3145
            ->with($this->isInstanceOf(AdminObjectAclData::class))
3146
            ->willReturn($aclRolesForm);
3147
3148
        $aclSecurityHandler = $this->getMockBuilder(AclSecurityHandler::class)
3149
            ->disableOriginalConstructor()
3150
            ->getMock();
3151
3152
        $aclSecurityHandler->expects($this->any())
3153
            ->method('getObjectPermissions')
3154
            ->willReturn([]);
3155
3156
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3157
            ->method('getSecurityHandler')
3158
            ->willReturn($aclSecurityHandler);
3159
3160
        $this->request->setMethod('POST');
3161
3162
        $this->assertInstanceOf(Response::class, $this->controller->aclAction(null, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::aclAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3163
3164
        $this->assertSame($this->admin, $this->parameters['admin']);
3165
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
3166
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3167
3168
        $this->assertSame('acl', $this->parameters['action']);
3169
        $this->assertSame([], $this->parameters['permissions']);
3170
        $this->assertSame($object, $this->parameters['object']);
3171
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['users']);
3172
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['roles']);
3173
        $this->assertInstanceOf(FormView::class, $this->parameters['aclUsersForm']);
3174
        $this->assertInstanceOf(FormView::class, $this->parameters['aclRolesForm']);
3175
3176
        $this->assertSame([], $this->session->getFlashBag()->all());
3177
        $this->assertSame('@SonataAdmin/CRUD/acl.html.twig', $this->template);
3178
    }
3179
3180
    public function testAclActionSuccessfulUpdate(): void
3181
    {
3182
        $this->request->query->set('id', 123);
3183
        $this->request->request->set(AdminObjectAclManipulator::ACL_ROLES_FORM_NAME, []);
3184
3185
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3186
            ->method('isAclEnabled')
3187
            ->willReturn(true);
3188
3189
        $object = new \stdClass();
3190
3191
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3192
            ->method('getObject')
3193
            ->willReturn($object);
3194
3195
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3196
            ->method('checkAccess')
3197
            ->willReturn(true);
3198
3199
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3200
            ->method('getSecurityInformation')
3201
            ->willReturn([]);
3202
3203
        $this->adminObjectAclManipulator->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...inObjectAclManipulator>.

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...
3204
            ->method('getMaskBuilderClass')
3205
            ->willReturn(AdminPermissionMap::class);
3206
3207
        $aclUsersForm = $this->getMockBuilder(Form::class)
3208
            ->disableOriginalConstructor()
3209
            ->getMock();
3210
3211
        $aclUsersForm->expects($this->any())
3212
            ->method('createView')
3213
            ->willReturn($this->createMock(FormView::class));
3214
3215
        $aclRolesForm = $this->getMockBuilder(Form::class)
3216
            ->disableOriginalConstructor()
3217
            ->getMock();
3218
3219
        $aclRolesForm->expects($this->any())
3220
            ->method('createView')
3221
            ->willReturn($this->createMock(FormView::class));
3222
3223
        $aclRolesForm->expects($this->once())
3224
            ->method('isValid')
3225
            ->willReturn(true);
3226
3227
        $this->adminObjectAclManipulator->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...inObjectAclManipulator>.

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...
3228
            ->method('createAclUsersForm')
3229
            ->with($this->isInstanceOf(AdminObjectAclData::class))
3230
            ->willReturn($aclUsersForm);
3231
3232
        $this->adminObjectAclManipulator->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...inObjectAclManipulator>.

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...
3233
            ->method('createAclRolesForm')
3234
            ->with($this->isInstanceOf(AdminObjectAclData::class))
3235
            ->willReturn($aclRolesForm);
3236
3237
        $aclSecurityHandler = $this->getMockBuilder(AclSecurityHandler::class)
3238
            ->disableOriginalConstructor()
3239
            ->getMock();
3240
3241
        $aclSecurityHandler->expects($this->any())
3242
            ->method('getObjectPermissions')
3243
            ->willReturn([]);
3244
3245
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3246
            ->method('getSecurityHandler')
3247
            ->willReturn($aclSecurityHandler);
3248
3249
        $this->expectTranslate('flash_acl_edit_success', [], 'SonataAdminBundle');
3250
3251
        $this->request->setMethod('POST');
3252
3253
        $response = $this->controller->aclAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::aclAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3254
3255
        $this->assertInstanceOf(RedirectResponse::class, $response);
3256
3257
        $this->assertSame(['flash_acl_edit_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3258
        $this->assertSame('stdClass_acl', $response->getTargetUrl());
3259
    }
3260
3261
    public function testHistoryViewRevisionActionAccessDenied(): void
3262
    {
3263
        $this->expectException(AccessDeniedException::class);
3264
3265
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3266
            ->method('getObject')
3267
            ->willReturn(new \StdClass());
3268
3269
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3270
            ->method('checkAccess')
3271
            ->with($this->equalTo('historyViewRevision'))
3272
            ->will($this->throwException(new AccessDeniedException()));
3273
3274
        $this->controller->historyViewRevisionAction(null, null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::historyViewRevisionAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3275
    }
3276
3277
    public function testHistoryViewRevisionActionNotFoundException(): void
3278
    {
3279
        $this->expectException(NotFoundHttpException::class, 'unable to find the object with id: 123');
0 ignored issues
show
Unused Code introduced by
The call to CRUDControllerTest::expectException() has too many arguments starting with 'unable to find the object with id: 123'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3280
3281
        $this->request->query->set('id', 123);
3282
3283
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3284
            ->method('getObject')
3285
            ->willReturn(false);
3286
3287
        $this->controller->historyViewRevisionAction(null, null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::historyViewRevisionAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3288
    }
3289
3290
    public function testHistoryViewRevisionActionNoReader(): void
3291
    {
3292
        $this->expectException(NotFoundHttpException::class, 'unable to find the audit reader for class : Foo');
0 ignored issues
show
Unused Code introduced by
The call to CRUDControllerTest::expectException() has too many arguments starting with 'unable to find the audit reader for class : Foo'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3293
3294
        $this->request->query->set('id', 123);
3295
3296
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3297
            ->method('checkAccess')
3298
            ->with($this->equalTo('historyViewRevision'))
3299
            ->willReturn(true);
3300
3301
        $object = new \stdClass();
3302
3303
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3304
            ->method('getObject')
3305
            ->willReturn($object);
3306
3307
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3308
            ->method('getClass')
3309
            ->willReturn('Foo');
3310
3311
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

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...
3312
            ->method('hasReader')
3313
            ->with($this->equalTo('Foo'))
3314
            ->willReturn(false);
3315
3316
        $this->controller->historyViewRevisionAction(null, null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::historyViewRevisionAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3317
    }
3318
3319
    public function testHistoryViewRevisionActionNotFoundRevision(): void
3320
    {
3321
        $this->expectException(NotFoundHttpException::class, 'unable to find the targeted object `123` from the revision `456` with classname : `Foo`');
0 ignored issues
show
Unused Code introduced by
The call to CRUDControllerTest::expectException() has too many arguments starting with 'unable to find the targ...with classname : `Foo`'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3322
3323
        $this->request->query->set('id', 123);
3324
3325
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3326
            ->method('checkAccess')
3327
            ->with($this->equalTo('historyViewRevision'))
3328
            ->willReturn(true);
3329
3330
        $object = new \stdClass();
3331
3332
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3333
            ->method('getObject')
3334
            ->willReturn($object);
3335
3336
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3337
            ->method('getClass')
3338
            ->willReturn('Foo');
3339
3340
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

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...
3341
            ->method('hasReader')
3342
            ->with($this->equalTo('Foo'))
3343
            ->willReturn(true);
3344
3345
        $reader = $this->createMock(AuditReaderInterface::class);
3346
3347
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

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...
3348
            ->method('getReader')
3349
            ->with($this->equalTo('Foo'))
3350
            ->willReturn($reader);
3351
3352
        $reader->expects($this->once())
3353
            ->method('find')
3354
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3355
            ->willReturn(null);
3356
3357
        $this->controller->historyViewRevisionAction(123, 456, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::historyViewRevisionAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3358
    }
3359
3360
    public function testHistoryViewRevisionAction(): void
3361
    {
3362
        $this->request->query->set('id', 123);
3363
3364
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3365
            ->method('checkAccess')
3366
            ->with($this->equalTo('historyViewRevision'))
3367
            ->willReturn(true);
3368
3369
        $object = new \stdClass();
3370
3371
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3372
            ->method('getObject')
3373
            ->willReturn($object);
3374
3375
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3376
            ->method('getClass')
3377
            ->willReturn('Foo');
3378
3379
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

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...
3380
            ->method('hasReader')
3381
            ->with($this->equalTo('Foo'))
3382
            ->willReturn(true);
3383
3384
        $reader = $this->createMock(AuditReaderInterface::class);
3385
3386
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

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...
3387
            ->method('getReader')
3388
            ->with($this->equalTo('Foo'))
3389
            ->willReturn($reader);
3390
3391
        $objectRevision = new \stdClass();
3392
        $objectRevision->revision = 456;
3393
3394
        $reader->expects($this->once())
3395
            ->method('find')
3396
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3397
            ->willReturn($objectRevision);
3398
3399
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3400
            ->method('setSubject')
3401
            ->with($this->equalTo($objectRevision))
3402
            ->willReturn(null);
3403
3404
        $fieldDescriptionCollection = new FieldDescriptionCollection();
3405
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3406
            ->method('getShow')
3407
            ->willReturn($fieldDescriptionCollection);
3408
3409
        $this->assertInstanceOf(Response::class, $this->controller->historyViewRevisionAction(123, 456, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::historyViewRevisionAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3410
3411
        $this->assertSame($this->admin, $this->parameters['admin']);
3412
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
3413
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3414
3415
        $this->assertSame('show', $this->parameters['action']);
3416
        $this->assertSame($objectRevision, $this->parameters['object']);
3417
        $this->assertSame($fieldDescriptionCollection, $this->parameters['elements']);
3418
3419
        $this->assertSame([], $this->session->getFlashBag()->all());
3420
        $this->assertSame('@SonataAdmin/CRUD/show.html.twig', $this->template);
3421
    }
3422
3423
    public function testHistoryCompareRevisionsActionAccessDenied(): void
3424
    {
3425
        $this->expectException(AccessDeniedException::class);
3426
3427
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3428
            ->method('checkAccess')
3429
            ->with($this->equalTo('historyCompareRevisions'))
3430
            ->will($this->throwException(new AccessDeniedException()));
3431
3432
        $this->controller->historyCompareRevisionsAction(null, null, null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::historyCompareRevisionsAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3433
    }
3434
3435
    public function testHistoryCompareRevisionsActionNotFoundException(): void
3436
    {
3437
        $this->expectException(NotFoundHttpException::class, 'unable to find the object with id: 123');
0 ignored issues
show
Unused Code introduced by
The call to CRUDControllerTest::expectException() has too many arguments starting with 'unable to find the object with id: 123'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3438
3439
        $this->request->query->set('id', 123);
3440
3441
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3442
            ->method('checkAccess')
3443
            ->with($this->equalTo('historyCompareRevisions'))
3444
            ->willReturn(true);
3445
3446
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3447
            ->method('getObject')
3448
            ->willReturn(false);
3449
3450
        $this->controller->historyCompareRevisionsAction(null, null, null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::historyCompareRevisionsAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3451
    }
3452
3453
    public function testHistoryCompareRevisionsActionNoReader(): void
3454
    {
3455
        $this->expectException(NotFoundHttpException::class, 'unable to find the audit reader for class : Foo');
0 ignored issues
show
Unused Code introduced by
The call to CRUDControllerTest::expectException() has too many arguments starting with 'unable to find the audit reader for class : Foo'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3456
3457
        $this->request->query->set('id', 123);
3458
3459
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3460
            ->method('checkAccess')
3461
            ->with($this->equalTo('historyCompareRevisions'))
3462
            ->willReturn(true);
3463
3464
        $object = new \stdClass();
3465
3466
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3467
            ->method('getObject')
3468
            ->willReturn($object);
3469
3470
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3471
            ->method('getClass')
3472
            ->willReturn('Foo');
3473
3474
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

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...
3475
            ->method('hasReader')
3476
            ->with($this->equalTo('Foo'))
3477
            ->willReturn(false);
3478
3479
        $this->controller->historyCompareRevisionsAction(null, null, null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::historyCompareRevisionsAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3480
    }
3481
3482
    public function testHistoryCompareRevisionsActionNotFoundBaseRevision(): void
3483
    {
3484
        $this->expectException(NotFoundHttpException::class, 'unable to find the targeted object `123` from the revision `456` with classname : `Foo`');
0 ignored issues
show
Unused Code introduced by
The call to CRUDControllerTest::expectException() has too many arguments starting with 'unable to find the targ...with classname : `Foo`'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3485
3486
        $this->request->query->set('id', 123);
3487
3488
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3489
            ->method('checkAccess')
3490
            ->with($this->equalTo('historyCompareRevisions'))
3491
            ->willReturn(true);
3492
3493
        $object = new \stdClass();
3494
3495
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3496
            ->method('getObject')
3497
            ->willReturn($object);
3498
3499
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3500
            ->method('getClass')
3501
            ->willReturn('Foo');
3502
3503
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

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...
3504
            ->method('hasReader')
3505
            ->with($this->equalTo('Foo'))
3506
            ->willReturn(true);
3507
3508
        $reader = $this->createMock(AuditReaderInterface::class);
3509
3510
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

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...
3511
            ->method('getReader')
3512
            ->with($this->equalTo('Foo'))
3513
            ->willReturn($reader);
3514
3515
        // once because it will not be found and therefore the second call won't be executed
3516
        $reader->expects($this->once())
3517
            ->method('find')
3518
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3519
            ->willReturn(null);
3520
3521
        $this->controller->historyCompareRevisionsAction(123, 456, 789, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::historyCompareRevisionsAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3522
    }
3523
3524
    public function testHistoryCompareRevisionsActionNotFoundCompareRevision(): void
3525
    {
3526
        $this->expectException(NotFoundHttpException::class, 'unable to find the targeted object `123` from the revision `789` with classname : `Foo`');
0 ignored issues
show
Unused Code introduced by
The call to CRUDControllerTest::expectException() has too many arguments starting with 'unable to find the targ...with classname : `Foo`'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3527
3528
        $this->request->query->set('id', 123);
3529
3530
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3531
            ->method('checkAccess')
3532
            ->with($this->equalTo('historyCompareRevisions'))
3533
            ->willReturn(true);
3534
3535
        $object = new \stdClass();
3536
3537
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3538
            ->method('getObject')
3539
            ->willReturn($object);
3540
3541
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3542
            ->method('getClass')
3543
            ->willReturn('Foo');
3544
3545
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

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...
3546
            ->method('hasReader')
3547
            ->with($this->equalTo('Foo'))
3548
            ->willReturn(true);
3549
3550
        $reader = $this->createMock(AuditReaderInterface::class);
3551
3552
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

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...
3553
            ->method('getReader')
3554
            ->with($this->equalTo('Foo'))
3555
            ->willReturn($reader);
3556
3557
        $objectRevision = new \stdClass();
3558
        $objectRevision->revision = 456;
3559
3560
        // first call should return, so the second call will throw an exception
3561
        $reader->expects($this->at(0))
3562
            ->method('find')
3563
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3564
            ->willReturn($objectRevision);
3565
3566
        $reader->expects($this->at(1))
3567
            ->method('find')
3568
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(789))
3569
            ->willReturn(null);
3570
3571
        $this->controller->historyCompareRevisionsAction(123, 456, 789, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::historyCompareRevisionsAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3572
    }
3573
3574
    public function testHistoryCompareRevisionsActionAction(): void
3575
    {
3576
        $this->request->query->set('id', 123);
3577
3578
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3579
            ->method('checkAccess')
3580
            ->with($this->equalTo('historyCompareRevisions'))
3581
            ->willReturn(true);
3582
3583
        $object = new \stdClass();
3584
3585
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3586
            ->method('getObject')
3587
            ->willReturn($object);
3588
3589
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3590
            ->method('getClass')
3591
            ->willReturn('Foo');
3592
3593
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

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...
3594
            ->method('hasReader')
3595
            ->with($this->equalTo('Foo'))
3596
            ->willReturn(true);
3597
3598
        $reader = $this->createMock(AuditReaderInterface::class);
3599
3600
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

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...
3601
            ->method('getReader')
3602
            ->with($this->equalTo('Foo'))
3603
            ->willReturn($reader);
3604
3605
        $objectRevision = new \stdClass();
3606
        $objectRevision->revision = 456;
3607
3608
        $compareObjectRevision = new \stdClass();
3609
        $compareObjectRevision->revision = 789;
3610
3611
        $reader->expects($this->at(0))
3612
            ->method('find')
3613
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3614
            ->willReturn($objectRevision);
3615
3616
        $reader->expects($this->at(1))
3617
            ->method('find')
3618
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(789))
3619
            ->willReturn($compareObjectRevision);
3620
3621
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3622
            ->method('setSubject')
3623
            ->with($this->equalTo($objectRevision))
3624
            ->willReturn(null);
3625
3626
        $fieldDescriptionCollection = new FieldDescriptionCollection();
3627
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3628
            ->method('getShow')
3629
            ->willReturn($fieldDescriptionCollection);
3630
3631
        $this->assertInstanceOf(Response::class, $this->controller->historyCompareRevisionsAction(123, 456, 789, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::historyCompareRevisionsAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3632
3633
        $this->assertSame($this->admin, $this->parameters['admin']);
3634
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
3635
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3636
3637
        $this->assertSame('show', $this->parameters['action']);
3638
        $this->assertSame($objectRevision, $this->parameters['object']);
3639
        $this->assertSame($compareObjectRevision, $this->parameters['object_compare']);
3640
        $this->assertSame($fieldDescriptionCollection, $this->parameters['elements']);
3641
3642
        $this->assertSame([], $this->session->getFlashBag()->all());
3643
        $this->assertSame('@SonataAdmin/CRUD/show_compare.html.twig', $this->template);
3644
    }
3645
3646
    public function testBatchActionWrongMethod(): void
3647
    {
3648
        $this->expectException(NotFoundHttpException::class, 'Invalid request type "GET", POST expected');
0 ignored issues
show
Unused Code introduced by
The call to CRUDControllerTest::expectException() has too many arguments starting with 'Invalid request type "GET", POST expected'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3649
3650
        $this->controller->batchAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::batchAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3651
    }
3652
3653
    /**
3654
     * NEXT_MAJOR: Remove this legacy group.
3655
     *
3656
     * @group legacy
3657
     */
3658
    public function testBatchActionActionNotDefined(): void
3659
    {
3660
        $this->expectException(\RuntimeException::class, 'The `foo` batch action is not defined');
0 ignored issues
show
Unused Code introduced by
The call to CRUDControllerTest::expectException() has too many arguments starting with 'The `foo` batch action is not defined'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3661
3662
        $batchActions = [];
3663
3664
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3665
            ->method('getBatchActions')
3666
            ->willReturn($batchActions);
3667
3668
        $this->request->setMethod('POST');
3669
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3670
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3671
3672
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
3673
            ->method('getOption')
3674
            ->with('csrf_protection')
3675
            ->willReturn(true);
3676
3677
        $this->controller->batchAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::batchAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3678
    }
3679
3680
    public function testBatchActionActionInvalidCsrfToken(): void
3681
    {
3682
        $this->request->setMethod('POST');
3683
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3684
        $this->request->request->set('_sonata_csrf_token', 'CSRF-INVALID');
3685
3686
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
3687
            ->method('getOption')
3688
            ->with('csrf_protection')
3689
            ->willReturn(true);
3690
3691
        try {
3692
            $this->controller->batchAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::batchAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3693
        } catch (HttpException $e) {
3694
            $this->assertSame('The csrf token is not valid, CSRF attack?', $e->getMessage());
3695
            $this->assertSame(400, $e->getStatusCode());
3696
        }
3697
    }
3698
3699
    public function testBatchActionActionWithDisabledCsrfProtection(): void
3700
    {
3701
        $this->request->setMethod('POST');
3702
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3703
3704
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
3705
            ->method('getOption')
3706
            ->with('csrf_protection')
3707
            ->willReturn(false);
3708
3709
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3710
            ->method('getBatchActions')
3711
            ->willReturn(['foo' => ['label' => 'foo']]);
3712
3713
        $datagrid = $this->createMock(DatagridInterface::class);
3714
3715
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3716
            ->method('getDatagrid')
3717
            ->willReturn($datagrid);
3718
3719
        $datagrid->expects($this->once())
3720
            ->method('buildPager');
3721
3722
        $form = $this->createMock(FormInterface::class);
3723
3724
        $datagrid->expects($this->once())
3725
            ->method('getForm')
3726
            ->willReturn($form);
3727
3728
        $formView = $this->createMock(FormView::class);
3729
3730
        $form->expects($this->once())
3731
            ->method('createView')
3732
            ->willReturn($formView);
3733
3734
        $this->controller->batchAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::batchAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3735
    }
3736
3737
    /**
3738
     * NEXT_MAJOR: Remove this legacy group.
3739
     *
3740
     * @group legacy
3741
     */
3742
    public function testBatchActionMethodNotExist(): void
3743
    {
3744
        $this->expectException(\RuntimeException::class, 'A `Sonata\AdminBundle\Controller\CRUDController::batchActionFoo` method must be callable');
0 ignored issues
show
Unused Code introduced by
The call to CRUDControllerTest::expectException() has too many arguments starting with 'A `Sonata\\AdminBundle\...ethod must be callable'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3745
3746
        $batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3747
3748
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3749
            ->method('getBatchActions')
3750
            ->willReturn($batchActions);
3751
3752
        $datagrid = $this->createMock(DatagridInterface::class);
3753
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3754
            ->method('getDatagrid')
3755
            ->willReturn($datagrid);
3756
3757
        $this->request->setMethod('POST');
3758
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3759
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3760
3761
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
3762
            ->method('getOption')
3763
            ->with('csrf_protection')
3764
            ->willReturn(true);
3765
3766
        $this->controller->batchAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::batchAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3767
    }
3768
3769
    /**
3770
     * NEXT_MAJOR: Remove this legacy group.
3771
     *
3772
     * @group legacy
3773
     */
3774
    public function testBatchActionWithoutConfirmation(): void
3775
    {
3776
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3777
3778
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3779
            ->method('getBatchActions')
3780
            ->willReturn($batchActions);
3781
3782
        $datagrid = $this->createMock(DatagridInterface::class);
3783
3784
        $query = $this->createMock(ProxyQueryInterface::class);
3785
        $datagrid->expects($this->once())
3786
            ->method('getQuery')
3787
            ->willReturn($query);
3788
3789
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3790
            ->method('getDatagrid')
3791
            ->willReturn($datagrid);
3792
3793
        $modelManager = $this->createMock(ModelManagerInterface::class);
3794
3795
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3796
            ->method('checkAccess')
3797
            ->with($this->equalTo('batchDelete'))
3798
            ->willReturn(true);
3799
3800
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3801
            ->method('getModelManager')
3802
            ->willReturn($modelManager);
3803
3804
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3805
            ->method('getClass')
3806
            ->willReturn('Foo');
3807
3808
        $modelManager->expects($this->once())
3809
            ->method('addIdentifiersToQuery')
3810
            ->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456']))
3811
            ->willReturn(true);
3812
3813
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
3814
3815
        $this->request->setMethod('POST');
3816
        $this->request->request->set('data', json_encode(['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false]));
3817
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3818
3819
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
3820
            ->method('getOption')
3821
            ->with('csrf_protection')
3822
            ->willReturn(true);
3823
3824
        $result = $this->controller->batchAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::batchAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3825
3826
        $this->assertInstanceOf(RedirectResponse::class, $result);
3827
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3828
        $this->assertSame('list', $result->getTargetUrl());
3829
    }
3830
3831
    /**
3832
     * NEXT_MAJOR: Remove this legacy group.
3833
     *
3834
     * @group legacy
3835
     */
3836
    public function testBatchActionWithoutConfirmation2(): void
3837
    {
3838
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3839
3840
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3841
            ->method('getBatchActions')
3842
            ->willReturn($batchActions);
3843
3844
        $datagrid = $this->createMock(DatagridInterface::class);
3845
3846
        $query = $this->createMock(ProxyQueryInterface::class);
3847
        $datagrid->expects($this->once())
3848
            ->method('getQuery')
3849
            ->willReturn($query);
3850
3851
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3852
            ->method('getDatagrid')
3853
            ->willReturn($datagrid);
3854
3855
        $modelManager = $this->createMock(ModelManagerInterface::class);
3856
3857
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3858
            ->method('checkAccess')
3859
            ->with($this->equalTo('batchDelete'))
3860
            ->willReturn(true);
3861
3862
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3863
            ->method('getModelManager')
3864
            ->willReturn($modelManager);
3865
3866
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3867
            ->method('getClass')
3868
            ->willReturn('Foo');
3869
3870
        $modelManager->expects($this->once())
3871
            ->method('addIdentifiersToQuery')
3872
            ->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456']))
3873
            ->willReturn(true);
3874
3875
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
3876
3877
        $this->request->setMethod('POST');
3878
        $this->request->request->set('action', 'delete');
3879
        $this->request->request->set('idx', ['123', '456']);
3880
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3881
3882
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
3883
            ->method('getOption')
3884
            ->with('csrf_protection')
3885
            ->willReturn(true);
3886
3887
        $result = $this->controller->batchAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::batchAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3888
3889
        $this->assertInstanceOf(RedirectResponse::class, $result);
3890
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3891
        $this->assertSame('list', $result->getTargetUrl());
3892
    }
3893
3894
    /**
3895
     * NEXT_MAJOR: Remove this legacy group.
3896
     *
3897
     * @group legacy
3898
     */
3899
    public function testBatchActionWithConfirmation(): void
3900
    {
3901
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'translation_domain' => 'FooBarBaz', 'ask_confirmation' => true]];
3902
3903
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3904
            ->method('getBatchActions')
3905
            ->willReturn($batchActions);
3906
3907
        $data = ['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false];
3908
3909
        $this->request->setMethod('POST');
3910
        $this->request->request->set('data', json_encode($data));
3911
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3912
3913
        $datagrid = $this->createMock(DatagridInterface::class);
3914
3915
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3916
            ->method('getDatagrid')
3917
            ->willReturn($datagrid);
3918
3919
        $form = $this->getMockBuilder(Form::class)
3920
            ->disableOriginalConstructor()
3921
            ->getMock();
3922
3923
        $form->expects($this->once())
3924
            ->method('createView')
3925
            ->willReturn($this->createMock(FormView::class));
3926
3927
        $datagrid->expects($this->once())
3928
            ->method('getForm')
3929
            ->willReturn($form);
3930
3931
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
3932
            ->method('getOption')
3933
            ->with('csrf_protection')
3934
            ->willReturn(true);
3935
3936
        $this->assertInstanceOf(Response::class, $this->controller->batchAction($this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::batchAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3937
3938
        $this->assertSame($this->admin, $this->parameters['admin']);
3939
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
3940
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3941
3942
        $this->assertSame('list', $this->parameters['action']);
3943
        $this->assertSame($datagrid, $this->parameters['datagrid']);
3944
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
3945
        $this->assertSame($data, $this->parameters['data']);
3946
        $this->assertSame('csrf-token-123_sonata.batch', $this->parameters['csrf_token']);
3947
        $this->assertSame('Foo Bar', $this->parameters['action_label']);
3948
3949
        $this->assertSame([], $this->session->getFlashBag()->all());
3950
        $this->assertSame('@SonataAdmin/CRUD/batch_confirmation.html.twig', $this->template);
3951
    }
3952
3953
    /**
3954
     * NEXT_MAJOR: Remove this legacy group.
3955
     *
3956
     * @group legacy
3957
     */
3958
    public function testBatchActionNonRelevantAction(): void
3959
    {
3960
        $controller = new BatchAdminController();
3961
        $controller->setContainer($this->container);
3962
3963
        $batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3964
3965
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3966
            ->method('getBatchActions')
3967
            ->willReturn($batchActions);
3968
3969
        $datagrid = $this->createMock(DatagridInterface::class);
3970
3971
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3972
            ->method('getDatagrid')
3973
            ->willReturn($datagrid);
3974
3975
        $this->expectTranslate('flash_batch_empty', [], 'SonataAdminBundle');
3976
3977
        $this->request->setMethod('POST');
3978
        $this->request->request->set('action', 'foo');
3979
        $this->request->request->set('idx', ['789']);
3980
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3981
3982
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
3983
            ->method('getOption')
3984
            ->with('csrf_protection')
3985
            ->willReturn(true);
3986
3987
        $result = $controller->batchAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to BatchAdminController::batchAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3988
3989
        $this->assertInstanceOf(RedirectResponse::class, $result);
3990
        $this->assertSame(['flash_batch_empty'], $this->session->getFlashBag()->get('sonata_flash_info'));
3991
        $this->assertSame('list', $result->getTargetUrl());
3992
    }
3993
3994
    public function testBatchActionWithCustomConfirmationTemplate(): void
3995
    {
3996
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => true, 'template' => 'custom_template.html.twig']];
3997
3998
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
3999
            ->method('getBatchActions')
4000
            ->willReturn($batchActions);
4001
4002
        $data = ['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false];
4003
4004
        $this->request->setMethod('POST');
4005
        $this->request->request->set('data', json_encode($data));
4006
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
4007
4008
        $datagrid = $this->createMock(DatagridInterface::class);
4009
4010
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
4011
            ->method('getDatagrid')
4012
            ->willReturn($datagrid);
4013
4014
        $form = $this->createMock(Form::class);
4015
4016
        $form->expects($this->once())
4017
            ->method('createView')
4018
            ->willReturn($this->createMock(FormView::class));
4019
4020
        $datagrid->expects($this->once())
4021
            ->method('getForm')
4022
            ->willReturn($form);
4023
4024
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
4025
            ->method('getOption')
4026
            ->with('csrf_protection')
4027
            ->willReturn(true);
4028
4029
        $this->controller->batchAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::batchAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
4030
4031
        $this->assertSame('custom_template.html.twig', $this->template);
4032
    }
4033
4034
    /**
4035
     * NEXT_MAJOR: Remove this legacy group.
4036
     *
4037
     * @group legacy
4038
     */
4039
    public function testBatchActionNonRelevantAction2(): void
4040
    {
4041
        $controller = new BatchAdminController();
4042
        $controller->setContainer($this->container);
4043
4044
        $batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
4045
4046
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
4047
            ->method('getBatchActions')
4048
            ->willReturn($batchActions);
4049
4050
        $datagrid = $this->createMock(DatagridInterface::class);
4051
4052
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
4053
            ->method('getDatagrid')
4054
            ->willReturn($datagrid);
4055
4056
        $this->expectTranslate('flash_foo_error', [], 'SonataAdminBundle');
4057
4058
        $this->request->setMethod('POST');
4059
        $this->request->request->set('action', 'foo');
4060
        $this->request->request->set('idx', ['999']);
4061
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
4062
4063
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
4064
            ->method('getOption')
4065
            ->with('csrf_protection')
4066
            ->willReturn(true);
4067
4068
        $result = $controller->batchAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to BatchAdminController::batchAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
4069
4070
        $this->assertInstanceOf(RedirectResponse::class, $result);
4071
        $this->assertSame(['flash_foo_error'], $this->session->getFlashBag()->get('sonata_flash_info'));
4072
        $this->assertSame('list', $result->getTargetUrl());
4073
    }
4074
4075
    /**
4076
     * NEXT_MAJOR: Remove this legacy group.
4077
     *
4078
     * @group legacy
4079
     */
4080
    public function testBatchActionNoItems(): void
4081
    {
4082
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => true]];
4083
4084
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
4085
            ->method('getBatchActions')
4086
            ->willReturn($batchActions);
4087
4088
        $datagrid = $this->createMock(DatagridInterface::class);
4089
4090
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
4091
            ->method('getDatagrid')
4092
            ->willReturn($datagrid);
4093
4094
        $this->expectTranslate('flash_batch_empty', [], 'SonataAdminBundle');
4095
4096
        $this->request->setMethod('POST');
4097
        $this->request->request->set('action', 'delete');
4098
        $this->request->request->set('idx', []);
4099
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
4100
4101
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
4102
            ->method('getOption')
4103
            ->with('csrf_protection')
4104
            ->willReturn(true);
4105
4106
        $result = $this->controller->batchAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::batchAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
4107
4108
        $this->assertInstanceOf(RedirectResponse::class, $result);
4109
        $this->assertSame(['flash_batch_empty'], $this->session->getFlashBag()->get('sonata_flash_info'));
4110
        $this->assertSame('list', $result->getTargetUrl());
4111
    }
4112
4113
    /**
4114
     * NEXT_MAJOR: Remove this legacy group.
4115
     *
4116
     * @group legacy
4117
     */
4118
    public function testBatchActionNoItemsEmptyQuery(): void
4119
    {
4120
        $controller = new BatchAdminController();
4121
        $controller->setContainer($this->container);
4122
4123
        $batchActions = ['bar' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
4124
4125
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
4126
            ->method('getBatchActions')
4127
            ->willReturn($batchActions);
4128
4129
        $datagrid = $this->createMock(DatagridInterface::class);
4130
4131
        $query = $this->createMock(ProxyQueryInterface::class);
4132
        $datagrid->expects($this->once())
4133
            ->method('getQuery')
4134
            ->willReturn($query);
4135
4136
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
4137
            ->method('getDatagrid')
4138
            ->willReturn($datagrid);
4139
4140
        $modelManager = $this->createMock(ModelManagerInterface::class);
4141
4142
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
4143
            ->method('getModelManager')
4144
            ->willReturn($modelManager);
4145
4146
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
4147
            ->method('getClass')
4148
            ->willReturn('Foo');
4149
4150
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
4151
            ->method('getOption')
4152
            ->with('csrf_protection')
4153
            ->willReturn(true);
4154
4155
        $this->request->setMethod('POST');
4156
        $this->request->request->set('action', 'bar');
4157
        $this->request->request->set('idx', []);
4158
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
4159
4160
        $this->expectTranslate('flash_batch_no_elements_processed', [], 'SonataAdminBundle');
4161
        $result = $controller->batchAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to BatchAdminController::batchAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
4162
4163
        $this->assertInstanceOf(Response::class, $result);
4164
        $this->assertRegExp('/Redirecting to list/', $result->getContent());
0 ignored issues
show
Security Bug introduced by
It seems like $result->getContent() targeting Symfony\Component\HttpFo...\Response::getContent() can also be of type false; however, PHPUnit\Framework\Assert::assertRegExp() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
4165
    }
4166
4167
    /**
4168
     * NEXT_MAJOR: Remove this legacy group.
4169
     *
4170
     * @group legacy
4171
     */
4172
    public function testBatchActionWithRequesData(): void
4173
    {
4174
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
4175
4176
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
4177
            ->method('getBatchActions')
4178
            ->willReturn($batchActions);
4179
4180
        $datagrid = $this->createMock(DatagridInterface::class);
4181
4182
        $query = $this->createMock(ProxyQueryInterface::class);
4183
        $datagrid->expects($this->once())
4184
            ->method('getQuery')
4185
            ->willReturn($query);
4186
4187
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
4188
            ->method('getDatagrid')
4189
            ->willReturn($datagrid);
4190
4191
        $modelManager = $this->createMock(ModelManagerInterface::class);
4192
4193
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() 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...
4194
            ->method('checkAccess')
4195
            ->with($this->equalTo('batchDelete'))
4196
            ->willReturn(true);
4197
4198
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
4199
            ->method('getModelManager')
4200
            ->willReturn($modelManager);
4201
4202
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() 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...
4203
            ->method('getClass')
4204
            ->willReturn('Foo');
4205
4206
        $modelManager->expects($this->once())
4207
            ->method('addIdentifiersToQuery')
4208
            ->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456']))
4209
            ->willReturn(true);
4210
4211
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
4212
4213
        $this->request->setMethod('POST');
4214
        $this->request->request->set('data', json_encode(['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false]));
4215
        $this->request->request->set('foo', 'bar');
4216
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
4217
4218
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
4219
            ->method('getOption')
4220
            ->with('csrf_protection')
4221
            ->willReturn(true);
4222
4223
        $result = $this->controller->batchAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::batchAction() has too many arguments starting with $this->request.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
4224
4225
        $this->assertInstanceOf(RedirectResponse::class, $result);
4226
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
4227
        $this->assertSame('list', $result->getTargetUrl());
4228
        $this->assertSame('bar', $this->request->request->get('foo'));
4229
    }
4230
4231
    public function testItThrowsWhenCallingAnUndefinedMethod(): void
4232
    {
4233
        $this->expectException(
4234
            \LogicException::class
4235
        );
4236
        $this->expectExceptionMessage(
4237
            'Call to undefined method Sonata\AdminBundle\Controller\CRUDController::doesNotExist'
4238
        );
4239
        $this->controller->doesNotExist();
0 ignored issues
show
Documentation Bug introduced by
The method doesNotExist does not exist on object<Sonata\AdminBundl...troller\CRUDController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
4240
    }
4241
4242
    /**
4243
     * @expectedDeprecation Method Sonata\AdminBundle\Controller\CRUDController::render has been renamed to Sonata\AdminBundle\Controller\CRUDController::renderWithExtraParams.
4244
     */
4245
    public function testRenderIsDeprecated(): void
4246
    {
4247
        $this->controller->render('toto.html.twig');
0 ignored issues
show
Deprecated Code introduced by
The method Sonata\AdminBundle\Contr...RUDController::render() has been deprecated with message: since version 3.27, to be removed in 4.0. Use Sonata\AdminBundle\Controller\CRUDController::renderWithExtraParams() instead.

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

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

Loading history...
4248
    }
4249
4250
    public function getCsrfProvider()
4251
    {
4252
        return $this->csrfProvider;
4253
    }
4254
4255
    public function getToStringValues()
4256
    {
4257
        return [
4258
            ['', ''],
4259
            ['Foo', 'Foo'],
4260
            ['&lt;a href=&quot;http://foo&quot;&gt;Bar&lt;/a&gt;', '<a href="http://foo">Bar</a>'],
4261
            ['&lt;&gt;&amp;&quot;&#039;abcdefghijklmnopqrstuvwxyz*-+.,?_()[]\/', '<>&"\'abcdefghijklmnopqrstuvwxyz*-+.,?_()[]\/'],
4262
        ];
4263
    }
4264
4265
    private function assertLoggerLogsModelManagerException($subject, string $method): void
4266
    {
4267
        $exception = new ModelManagerException(
4268
            $message = 'message',
4269
            1234,
4270
            new \Exception($previousExceptionMessage = 'very useful message')
4271
        );
4272
4273
        $subject->expects($this->once())
4274
            ->method($method)
4275
            ->willReturnCallback(static function () use ($exception): void {
4276
                throw $exception;
4277
            });
4278
4279
        $this->logger->expects($this->once())
4280
            ->method('error')
4281
            ->with($message, [
4282
                'exception' => $exception,
4283
                'previous_exception_message' => $previousExceptionMessage,
4284
            ]);
4285
    }
4286
4287
    private function expectTranslate(
4288
        string $id,
4289
        array $parameters = [],
4290
        ?string $domain = null,
4291
        ?string $locale = null
4292
    ): void {
4293
        $this->translator->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...on\TranslatorInterface>.

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...
4294
            ->method('trans')
4295
            ->with($this->equalTo($id), $this->equalTo($parameters), $this->equalTo($domain), $this->equalTo($locale))
4296
            ->willReturn($id);
4297
    }
4298
}
4299