Completed
Push — 3.x ( 470eac...cc0fde )
by Christian
03:33
created

CRUDControllerTest::testRedirectTo()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 9.44
c 0
b 0
f 0
cc 3
nc 4
nop 5
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\FormError;
48
use Symfony\Component\Form\FormRenderer;
49
use Symfony\Component\Form\FormView;
50
use Symfony\Component\HttpFoundation\JsonResponse;
51
use Symfony\Component\HttpFoundation\RedirectResponse;
52
use Symfony\Component\HttpFoundation\Request;
53
use Symfony\Component\HttpFoundation\RequestStack;
54
use Symfony\Component\HttpFoundation\Response;
55
use Symfony\Component\HttpFoundation\Session\Session;
56
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
57
use Symfony\Component\HttpFoundation\StreamedResponse;
58
use Symfony\Component\HttpKernel\Exception\HttpException;
59
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
60
use Symfony\Component\HttpKernel\KernelInterface;
61
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
62
use Symfony\Component\Security\Csrf\CsrfToken;
63
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
64
use Symfony\Component\Translation\TranslatorInterface;
65
use Twig\Environment;
66
67
/**
68
 * Test for CRUDController.
69
 *
70
 * @author Andrej Hudec <[email protected]>
71
 *
72
 * @group legacy
73
 */
74
class CRUDControllerTest extends TestCase
75
{
76
    /**
77
     * @var CRUDController
78
     */
79
    private $controller;
80
81
    /**
82
     * @var Request
83
     */
84
    private $request;
85
86
    /**
87
     * @var AbstractAdmin
88
     */
89
    private $admin;
90
91
    /**
92
     * @var TemplateRegistryInterface
93
     */
94
    private $templateRegistry;
95
96
    /**
97
     * @var Pool
98
     */
99
    private $pool;
100
101
    /**
102
     * @var array
103
     */
104
    private $parameters;
105
106
    /**
107
     * @var Session
108
     */
109
    private $session;
110
111
    /**
112
     * @var AuditManager
113
     */
114
    private $auditManager;
115
116
    /**
117
     * @var ContainerInterface
118
     */
119
    private $container;
120
121
    /**
122
     * @var AdminObjectAclManipulator
123
     */
124
    private $adminObjectAclManipulator;
125
126
    /**
127
     * @var string
128
     */
129
    private $template;
130
131
    /**
132
     * @var array
133
     */
134
    private $protectedTestedMethods;
135
136
    /**
137
     * @var CsrfTokenManagerInterface
138
     */
139
    private $csrfProvider;
140
141
    /**
142
     * @var KernelInterface
143
     */
144
    private $kernel;
145
146
    /**
147
     * @var TranslatorInterface
148
     */
149
    private $translator;
150
151
    /**
152
     * {@inheritdoc}
153
     */
154
    protected function setUp(): void
155
    {
156
        $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...
157
158
        $this->request = new Request();
159
        $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...
160
        $this->pool->setAdminServiceIds(['foo.admin']);
161
        $this->request->attributes->set('_sonata_admin', 'foo.admin');
162
        $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...
163
            ->disableOriginalConstructor()
164
            ->getMock();
165
        $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...
166
        $this->parameters = [];
167
        $this->template = '';
168
169
        $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...
170
171
        $templating = $this->getMockBuilder(DelegatingEngine::class)
172
            ->setConstructorArgs([$this->container, []])
173
            ->getMock();
174
175
        $templatingRenderReturnCallback = $this->returnCallback(function (
176
            $view,
177
            array $parameters = [],
178
            Response $response = null
179
        ) {
180
            $this->template = $view;
181
182
            if (null === $response) {
183
                $response = new Response();
184
            }
185
186
            $this->parameters = $parameters;
187
188
            return $response;
189
        });
190
191
        // SF < 3.3.10 BC
192
        $templating->expects($this->any())
193
            ->method('renderResponse')
194
            ->will($templatingRenderReturnCallback);
195
196
        $templating->expects($this->any())
197
            ->method('render')
198
            ->will($templatingRenderReturnCallback);
199
200
        $this->session = new Session(new MockArraySessionStorage());
201
202
        $twig = $this->getMockBuilder(Environment::class)
203
            ->disableOriginalConstructor()
204
            ->getMock();
205
206
        $twig->expects($this->any())
207
            ->method('getExtension')
208
            ->willReturnCallback(function ($name) {
209
                switch ($name) {
210
                    case FormExtension::class:
211
                        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...
212
                }
213
            });
214
215
        $twig->expects($this->any())
216
            ->method('getRuntime')
217
            ->willReturnCallback(function ($name) {
218
                switch ($name) {
219
                    case TwigRenderer::class:
220
                        return $this->createMock(TwigRenderer::class);
221
                    case FormRenderer::class:
222
                        return $this->createMock(FormRenderer::class);
223
                }
224
            });
225
226
        // NEXT_MAJOR : require sonata/exporter ^1.7 and remove conditional
227
        if (class_exists(Exporter::class)) {
228
            $exporter = new Exporter([new JsonWriter('/tmp/sonataadmin/export.json')]);
229
        } else {
230
            $exporter = $this->createMock(SonataExporter::class);
231
232
            $exporter->expects($this->any())
233
                ->method('getResponse')
234
                ->willReturn(new StreamedResponse());
235
        }
236
237
        $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...
238
            ->disableOriginalConstructor()
239
            ->getMock();
240
241
        $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...
242
            ->disableOriginalConstructor()
243
            ->getMock();
244
245
        $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...
246
            ->getMock();
247
248
        $this->csrfProvider->expects($this->any())
249
            ->method('getToken')
250
            ->willReturnCallback(static function ($intention) {
251
                return new CsrfToken($intention, 'csrf-token-123_'.$intention);
252
            });
253
254
        $this->csrfProvider->expects($this->any())
255
            ->method('isTokenValid')
256
            ->willReturnCallback(static function (CsrfToken $token) {
257
                if ($token->getValue() === 'csrf-token-123_'.$token->getId()) {
258
                    return true;
259
                }
260
261
                return false;
262
            });
263
264
        $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...
265
266
        $requestStack = new RequestStack();
267
        $requestStack->push($this->request);
268
269
        $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...
270
271
        $this->container->expects($this->any())
272
            ->method('get')
273
            ->willReturnCallback(function ($id) use (
274
                $templating,
275
                $twig,
276
                $exporter,
277
                $requestStack
278
            ) {
279
                switch ($id) {
280
                    case 'sonata.admin.pool':
281
                        return $this->pool;
282
                    case 'request_stack':
283
                        return $requestStack;
284
                    case 'foo.admin':
285
                        return $this->admin;
286
                    case 'foo.admin.template_registry':
287
                        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...
288
                    case 'templating':
289
                        return $templating;
290
                    case 'twig':
291
                        return $twig;
292
                    case 'session':
293
                        return $this->session;
294
                    case 'sonata.admin.exporter':
295
                        return $exporter;
296
                    case 'sonata.admin.audit.manager':
297
                        return $this->auditManager;
298
                    case 'sonata.admin.object.manipulator.acl.admin':
299
                        return $this->adminObjectAclManipulator;
300
                    case 'security.csrf.token_manager':
301
                        return $this->csrfProvider;
302
                    case 'logger':
303
                        return $this->logger;
304
                    case 'kernel':
305
                        return $this->kernel;
306
                    case 'translator':
307
                        return $this->translator;
308
                }
309
            });
310
311
        $this->container->expects($this->any())
312
            ->method('has')
313
            ->willReturnCallback(function ($id) {
314
                if ('security.csrf.token_manager' === $id && null !== $this->getCsrfProvider()) {
315
                    return true;
316
                }
317
318
                if ('logger' === $id) {
319
                    return true;
320
                }
321
322
                if ('session' === $id) {
323
                    return true;
324
                }
325
326
                if ('templating' === $id) {
327
                    return true;
328
                }
329
330
                if ('translator' === $id) {
331
                    return true;
332
                }
333
334
                return false;
335
            });
336
337
        $this->container->expects($this->any())
338
            ->method('getParameter')
339
            ->willReturnCallback(static function ($name) {
340
                switch ($name) {
341
                    case 'security.role_hierarchy.roles':
342
                       return ['ROLE_SUPER_ADMIN' => ['ROLE_USER', 'ROLE_SONATA_ADMIN', 'ROLE_ADMIN']];
343
                }
344
            });
345
346
        $this->templateRegistry->getTemplate('ajax')->willReturn('@SonataAdmin/ajax_layout.html.twig');
347
        $this->templateRegistry->getTemplate('layout')->willReturn('@SonataAdmin/standard_layout.html.twig');
348
        $this->templateRegistry->getTemplate('show')->willReturn('@SonataAdmin/CRUD/show.html.twig');
349
        $this->templateRegistry->getTemplate('show_compare')->willReturn('@SonataAdmin/CRUD/show_compare.html.twig');
350
        $this->templateRegistry->getTemplate('edit')->willReturn('@SonataAdmin/CRUD/edit.html.twig');
351
        $this->templateRegistry->getTemplate('dashboard')->willReturn('@SonataAdmin/Core/dashboard.html.twig');
352
        $this->templateRegistry->getTemplate('search')->willReturn('@SonataAdmin/Core/search.html.twig');
353
        $this->templateRegistry->getTemplate('list')->willReturn('@SonataAdmin/CRUD/list.html.twig');
354
        $this->templateRegistry->getTemplate('preview')->willReturn('@SonataAdmin/CRUD/preview.html.twig');
355
        $this->templateRegistry->getTemplate('history')->willReturn('@SonataAdmin/CRUD/history.html.twig');
356
        $this->templateRegistry->getTemplate('acl')->willReturn('@SonataAdmin/CRUD/acl.html.twig');
357
        $this->templateRegistry->getTemplate('delete')->willReturn('@SonataAdmin/CRUD/delete.html.twig');
358
        $this->templateRegistry->getTemplate('batch')->willReturn('@SonataAdmin/CRUD/list__batch.html.twig');
359
        $this->templateRegistry->getTemplate('batch_confirmation')->willReturn('@SonataAdmin/CRUD/batch_confirmation.html.twig');
360
361
        // NEXT_MAJOR: Remove this call
362
        $this->admin->method('getTemplate')->willReturnMap([
363
            ['ajax', '@SonataAdmin/ajax_layout.html.twig'],
364
            ['layout', '@SonataAdmin/standard_layout.html.twig'],
365
            ['show', '@SonataAdmin/CRUD/show.html.twig'],
366
            ['show_compare', '@SonataAdmin/CRUD/show_compare.html.twig'],
367
            ['edit', '@SonataAdmin/CRUD/edit.html.twig'],
368
            ['dashboard', '@SonataAdmin/Core/dashboard.html.twig'],
369
            ['search', '@SonataAdmin/Core/search.html.twig'],
370
            ['list', '@SonataAdmin/CRUD/list.html.twig'],
371
            ['preview', '@SonataAdmin/CRUD/preview.html.twig'],
372
            ['history', '@SonataAdmin/CRUD/history.html.twig'],
373
            ['acl', '@SonataAdmin/CRUD/acl.html.twig'],
374
            ['delete', '@SonataAdmin/CRUD/delete.html.twig'],
375
            ['batch', '@SonataAdmin/CRUD/list__batch.html.twig'],
376
            ['batch_confirmation', '@SonataAdmin/CRUD/batch_confirmation.html.twig'],
377
        ]);
378
379
        $this->admin->expects($this->any())
380
            ->method('getIdParameter')
381
            ->willReturn('id');
382
383
        $this->admin->expects($this->any())
384
            ->method('getAccessMapping')
385
            ->willReturn([]);
386
387
        $this->admin->expects($this->any())
388
            ->method('generateUrl')
389
            ->willReturnCallback(
390
391
                    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...
392
                        $result = $name;
393
                        if (!empty($parameters)) {
394
                            $result .= '?'.http_build_query($parameters);
395
                        }
396
397
                        return $result;
398
                    }
399
400
            );
401
402
        $this->admin->expects($this->any())
403
            ->method('generateObjectUrl')
404
            ->willReturnCallback(
405
406
                    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...
407
                        $result = \get_class($object).'_'.$name;
408
                        if (!empty($parameters)) {
409
                            $result .= '?'.http_build_query($parameters);
410
                        }
411
412
                        return $result;
413
                    }
414
415
            );
416
417
        $this->admin->expects($this->any())
418
            ->method('getCode')
419
            ->willReturn('foo.admin');
420
421
        $this->controller = new CRUDController();
422
        $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...
423
424
        // Make some methods public to test them
425
        $testedMethods = [
426
            'renderJson',
427
            'isXmlHttpRequest',
428
            'configure',
429
            'getBaseTemplate',
430
            'redirectTo',
431
            'addFlash',
432
        ];
433
        foreach ($testedMethods as $testedMethod) {
434
            // NEXT_MAJOR: Remove this check and only use CRUDController
435
            if (method_exists(CRUDController::class, $testedMethod)) {
436
                $method = new \ReflectionMethod(CRUDController::class, $testedMethod);
437
            } else {
438
                $method = new \ReflectionMethod(Controller::class, $testedMethod);
439
            }
440
441
            $method->setAccessible(true);
442
            $this->protectedTestedMethods[$testedMethod] = $method;
443
        }
444
    }
445
446
    public function testRenderJson1(): void
447
    {
448
        $data = ['example' => '123', 'foo' => 'bar'];
449
450
        $this->request->headers->set('Content-Type', 'application/x-www-form-urlencoded');
451
        $response = $this->protectedTestedMethods['renderJson']->invoke($this->controller, $data, 200, [], $this->request);
452
453
        $this->assertSame($response->headers->get('Content-Type'), 'application/json');
454
        $this->assertSame(json_encode($data), $response->getContent());
455
    }
456
457
    public function testRenderJson2(): void
458
    {
459
        $data = ['example' => '123', 'foo' => 'bar'];
460
461
        $this->request->headers->set('Content-Type', 'multipart/form-data');
462
        $response = $this->protectedTestedMethods['renderJson']->invoke($this->controller, $data, 200, [], $this->request);
463
464
        $this->assertSame($response->headers->get('Content-Type'), 'application/json');
465
        $this->assertSame(json_encode($data), $response->getContent());
466
    }
467
468
    public function testRenderJsonAjax(): void
469
    {
470
        $data = ['example' => '123', 'foo' => 'bar'];
471
472
        $this->request->attributes->set('_xml_http_request', true);
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 testIsXmlHttpRequest(): void
481
    {
482
        $this->assertFalse($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
483
484
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
485
486
        $this->assertTrue($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
487
488
        $this->request->headers->remove('X-Requested-With');
489
        $this->assertFalse($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
490
491
        $this->request->attributes->set('_xml_http_request', true);
492
        $this->assertTrue($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
493
    }
494
495
    public function testConfigure(): void
496
    {
497
        $uniqueId = '';
498
499
        $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...
500
            ->method('setUniqid')
501
            ->willReturnCallback(static function ($uniqid) use (&$uniqueId): void {
502
                $uniqueId = $uniqid;
503
            });
504
505
        $this->request->query->set('uniqid', 123456);
506
        $this->protectedTestedMethods['configure']->invoke($this->controller);
507
508
        $this->assertSame(123456, $uniqueId);
509
        $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...
510
    }
511
512
    public function testConfigureChild(): void
513
    {
514
        $uniqueId = '';
515
516
        $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...
517
            ->method('setUniqid')
518
            ->willReturnCallback(static function ($uniqid) use (&$uniqueId): void {
519
                $uniqueId = $uniqid;
520
            });
521
522
        $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...
523
            ->method('isChild')
524
            ->willReturn(true);
525
526
        $adminParent = $this->getMockBuilder(AbstractAdmin::class)
527
            ->disableOriginalConstructor()
528
            ->getMock();
529
        $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...
530
            ->method('getParent')
531
            ->willReturn($adminParent);
532
533
        $this->request->query->set('uniqid', 123456);
534
        $this->protectedTestedMethods['configure']->invoke($this->controller);
535
536
        $this->assertSame(123456, $uniqueId);
537
        $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...
538
    }
539
540
    public function testConfigureWithException(): void
541
    {
542
        $this->expectException(
543
            \RuntimeException::class,
544
            '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...
545
        );
546
547
        $this->request->attributes->remove('_sonata_admin');
548
        $this->protectedTestedMethods['configure']->invoke($this->controller);
549
    }
550
551
    public function testConfigureWithException2(): void
552
    {
553
        $this->expectException(
554
            \InvalidArgumentException::class,
555
            '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...
556
        );
557
558
        $this->pool->setAdminServiceIds(['nonexistent.admin']);
559
        $this->request->attributes->set('_sonata_admin', 'nonexistent.admin');
560
        $this->protectedTestedMethods['configure']->invoke($this->controller);
561
    }
562
563
    public function testGetBaseTemplate(): void
564
    {
565
        $this->assertSame(
566
            '@SonataAdmin/standard_layout.html.twig',
567
            $this->protectedTestedMethods['getBaseTemplate']->invoke($this->controller, $this->request)
568
        );
569
570
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
571
        $this->assertSame(
572
            '@SonataAdmin/ajax_layout.html.twig',
573
            $this->protectedTestedMethods['getBaseTemplate']->invoke($this->controller, $this->request)
574
        );
575
576
        $this->request->headers->remove('X-Requested-With');
577
        $this->assertSame(
578
            '@SonataAdmin/standard_layout.html.twig',
579
            $this->protectedTestedMethods['getBaseTemplate']->invoke($this->controller, $this->request)
580
        );
581
582
        $this->request->attributes->set('_xml_http_request', true);
583
        $this->assertSame(
584
            '@SonataAdmin/ajax_layout.html.twig',
585
            $this->protectedTestedMethods['getBaseTemplate']->invoke($this->controller, $this->request)
586
        );
587
    }
588
589
    public function testRender(): void
590
    {
591
        $this->parameters = [];
592
        $this->assertInstanceOf(
593
            Response::class,
594
            $this->controller->renderWithExtraParams('@FooAdmin/foo.html.twig', [], null)
595
        );
596
        $this->assertSame($this->admin, $this->parameters['admin']);
597
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
598
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
599
        $this->assertSame('@FooAdmin/foo.html.twig', $this->template);
600
    }
601
602
    public function testRenderWithResponse(): void
603
    {
604
        $this->parameters = [];
605
        $response = $response = new Response();
606
        $response->headers->set('X-foo', 'bar');
607
        $responseResult = $this->controller->renderWithExtraParams('@FooAdmin/foo.html.twig', [], $response);
608
609
        $this->assertSame($response, $responseResult);
610
        $this->assertSame('bar', $responseResult->headers->get('X-foo'));
611
        $this->assertSame($this->admin, $this->parameters['admin']);
612
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
613
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
614
        $this->assertSame('@FooAdmin/foo.html.twig', $this->template);
615
    }
616
617
    public function testRenderCustomParams(): void
618
    {
619
        $this->parameters = [];
620
        $this->assertInstanceOf(
621
            Response::class,
622
            $this->controller->renderWithExtraParams(
623
                '@FooAdmin/foo.html.twig',
624
                ['foo' => 'bar'],
625
                null
626
            )
627
        );
628
        $this->assertSame($this->admin, $this->parameters['admin']);
629
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
630
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
631
        $this->assertSame('bar', $this->parameters['foo']);
632
        $this->assertSame('@FooAdmin/foo.html.twig', $this->template);
633
    }
634
635
    public function testRenderAjax(): void
636
    {
637
        $this->parameters = [];
638
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
639
        $this->assertInstanceOf(
640
            Response::class,
641
            $this->controller->renderWithExtraParams(
642
                '@FooAdmin/foo.html.twig',
643
                ['foo' => 'bar'],
644
                null
645
            )
646
        );
647
        $this->assertSame($this->admin, $this->parameters['admin']);
648
        $this->assertSame('@SonataAdmin/ajax_layout.html.twig', $this->parameters['base_template']);
649
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
650
        $this->assertSame('bar', $this->parameters['foo']);
651
        $this->assertSame('@FooAdmin/foo.html.twig', $this->template);
652
    }
653
654
    public function testListActionAccessDenied(): void
655
    {
656
        $this->expectException(AccessDeniedException::class);
657
658
        $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...
659
            ->method('checkAccess')
660
            ->with($this->equalTo('list'))
661
            ->will($this->throwException(new AccessDeniedException()));
662
663
        $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...
664
    }
665
666
    public function testPreList(): void
667
    {
668
        $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...
669
            ->method('hasRoute')
670
            ->with($this->equalTo('list'))
671
            ->willReturn(true);
672
673
        $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...
674
            ->method('checkAccess')
675
            ->with($this->equalTo('list'))
676
            ->willReturn(true);
677
678
        $controller = new PreCRUDController();
679
        $controller->setContainer($this->container);
680
681
        $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...
682
        $this->assertInstanceOf(Response::class, $response);
683
        $this->assertSame('preList called', $response->getContent());
684
    }
685
686
    public function testListAction(): void
687
    {
688
        $datagrid = $this->createMock(DatagridInterface::class);
689
690
        $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...
691
            ->method('hasRoute')
692
            ->with($this->equalTo('list'))
693
            ->willReturn(true);
694
695
        $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...
696
            ->method('checkAccess')
697
            ->with($this->equalTo('list'))
698
            ->willReturn(true);
699
700
        $form = $this->getMockBuilder(Form::class)
701
            ->disableOriginalConstructor()
702
            ->getMock();
703
704
        $form->expects($this->once())
705
            ->method('createView')
706
            ->willReturn($this->createMock(FormView::class));
707
708
        $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...
709
            ->method('getDatagrid')
710
            ->willReturn($datagrid);
711
712
        $datagrid->expects($this->once())
713
            ->method('getForm')
714
            ->willReturn($form);
715
716
        $this->parameters = [];
717
        $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...
718
719
        $this->assertSame($this->admin, $this->parameters['admin']);
720
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
721
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
722
723
        $this->assertSame('list', $this->parameters['action']);
724
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
725
        $this->assertInstanceOf(DatagridInterface::class, $this->parameters['datagrid']);
726
        $this->assertSame('csrf-token-123_sonata.batch', $this->parameters['csrf_token']);
727
        $this->assertSame([], $this->session->getFlashBag()->all());
728
        $this->assertSame('@SonataAdmin/CRUD/list.html.twig', $this->template);
729
    }
730
731
    public function testBatchActionDeleteAccessDenied(): void
732
    {
733
        $this->expectException(AccessDeniedException::class);
734
735
        $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...
736
            ->method('checkAccess')
737
            ->with($this->equalTo('batchDelete'))
738
            ->will($this->throwException(new AccessDeniedException()));
739
740
        $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...
741
    }
742
743
    public function testBatchActionDelete(): void
744
    {
745
        $modelManager = $this->createMock(ModelManagerInterface::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
            ->willReturn(true);
751
752
        $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...
753
            ->method('getModelManager')
754
            ->willReturn($modelManager);
755
756
        $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...
757
            ->method('getFilterParameters')
758
            ->willReturn(['foo' => 'bar']);
759
760
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
761
762
        $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...
763
764
        $this->assertInstanceOf(RedirectResponse::class, $result);
765
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
766
        $this->assertSame('list?filter%5Bfoo%5D=bar', $result->getTargetUrl());
767
    }
768
769
    public function testBatchActionDeleteWithModelManagerException(): void
770
    {
771
        $modelManager = $this->createMock(ModelManagerInterface::class);
772
        $this->assertLoggerLogsModelManagerException($modelManager, 'batchDelete');
773
774
        $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...
775
            ->method('getModelManager')
776
            ->willReturn($modelManager);
777
778
        $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...
779
            ->method('getFilterParameters')
780
            ->willReturn(['foo' => 'bar']);
781
782
        $this->expectTranslate('flash_batch_delete_error', [], 'SonataAdminBundle');
783
784
        $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...
785
786
        $this->assertInstanceOf(RedirectResponse::class, $result);
787
        $this->assertSame(['flash_batch_delete_error'], $this->session->getFlashBag()->get('sonata_flash_error'));
788
        $this->assertSame('list?filter%5Bfoo%5D=bar', $result->getTargetUrl());
789
    }
790
791
    public function testBatchActionDeleteWithModelManagerExceptionInDebugMode(): void
792
    {
793
        $modelManager = $this->createMock(ModelManagerInterface::class);
794
        $this->expectException(ModelManagerException::class);
795
796
        $modelManager->expects($this->once())
797
            ->method('batchDelete')
798
            ->willReturnCallback(static function (): void {
799
                throw new ModelManagerException();
800
            });
801
802
        $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...
803
            ->method('getModelManager')
804
            ->willReturn($modelManager);
805
806
        $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...
807
            ->method('isDebug')
808
            ->willReturn(true);
809
810
        $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...
811
    }
812
813
    public function testShowActionNotFoundException(): void
814
    {
815
        $this->expectException(NotFoundHttpException::class);
816
817
        $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...
818
            ->method('getObject')
819
            ->willReturn(false);
820
821
        $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...
822
    }
823
824
    public function testShowActionAccessDenied(): void
825
    {
826
        $this->expectException(AccessDeniedException::class);
827
828
        $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...
829
            ->method('getObject')
830
            ->willReturn(new \stdClass());
831
832
        $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...
833
            ->method('checkAccess')
834
            ->with($this->equalTo('show'))
835
            ->will($this->throwException(new AccessDeniedException()));
836
837
        $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...
838
    }
839
840
    /**
841
     * @group legacy
842
     * @expectedDeprecation Calling this method without implementing "configureShowFields" is not supported since 3.40.0 and will no longer be possible in 4.0
843
     */
844
    public function testShowActionDeprecation(): void
845
    {
846
        $object = new \stdClass();
847
848
        $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...
849
            ->method('getObject')
850
            ->willReturn($object);
851
852
        $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...
853
            ->method('checkAccess')
854
            ->with($this->equalTo('show'))
855
            ->willReturn(true);
856
857
        $show = $this->createMock(FieldDescriptionCollection::class);
858
859
        $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...
860
            ->method('getShow')
861
            ->willReturn($show);
862
863
        $show->expects($this->once())
864
            ->method('getElements')
865
            ->willReturn([]);
866
867
        $show->expects($this->once())
868
            ->method('count')
869
            ->willReturn(0);
870
871
        $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...
872
    }
873
874
    public function testPreShow(): void
875
    {
876
        $object = new \stdClass();
877
        $object->foo = 123456;
878
879
        $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...
880
            ->method('getObject')
881
            ->willReturn($object);
882
883
        $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...
884
            ->method('checkAccess')
885
            ->with($this->equalTo('show'))
886
            ->willReturn(true);
887
888
        $controller = new PreCRUDController();
889
        $controller->setContainer($this->container);
890
891
        $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...
892
        $this->assertInstanceOf(Response::class, $response);
893
        $this->assertSame('preShow called: 123456', $response->getContent());
894
    }
895
896
    public function testShowAction(): void
897
    {
898
        $object = new \stdClass();
899
900
        $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...
901
            ->method('getObject')
902
            ->willReturn($object);
903
904
        $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...
905
            ->method('checkAccess')
906
            ->with($this->equalTo('show'))
907
            ->willReturn(true);
908
909
        $show = $this->createMock(FieldDescriptionCollection::class);
910
911
        $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...
912
            ->method('getShow')
913
            ->willReturn($show);
914
915
        $show->expects($this->once())
916
            ->method('getElements')
917
            ->willReturn(['field' => 'fielddata']);
918
919
        $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...
920
921
        $this->assertSame($this->admin, $this->parameters['admin']);
922
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
923
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
924
925
        $this->assertSame('show', $this->parameters['action']);
926
        $this->assertInstanceOf(FieldDescriptionCollection::class, $this->parameters['elements']);
927
        $this->assertSame($object, $this->parameters['object']);
928
929
        $this->assertSame([], $this->session->getFlashBag()->all());
930
        $this->assertSame('@SonataAdmin/CRUD/show.html.twig', $this->template);
931
    }
932
933
    /**
934
     * @dataProvider getRedirectToTests
935
     */
936
    public function testRedirectTo($expected, $route, $queryParams, $requestParams, $hasActiveSubclass): void
937
    {
938
        $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...
939
            ->method('hasActiveSubclass')
940
            ->willReturn($hasActiveSubclass);
941
942
        $object = new \stdClass();
943
944
        foreach ($queryParams as $key => $value) {
945
            $this->request->query->set($key, $value);
946
        }
947
948
        foreach ($requestParams as $key => $value) {
949
            $this->request->request->set($key, $value);
950
        }
951
952
        $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...
953
            ->method('hasRoute')
954
            ->with($this->equalTo($route))
955
            ->willReturn(true);
956
957
        $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...
958
            ->method('hasAccess')
959
            ->with($this->equalTo($route))
960
            ->willReturn(true);
961
962
        $response = $this->protectedTestedMethods['redirectTo']->invoke($this->controller, $object, $this->request);
963
        $this->assertInstanceOf(RedirectResponse::class, $response);
964
        $this->assertSame($expected, $response->getTargetUrl());
965
    }
966
967
    public function testRedirectToWithObject(): void
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('hasActiveSubclass')
971
            ->willReturn(false);
972
973
        $object = new \stdClass();
974
975
        $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...
976
            ->method('hasRoute')
977
            ->with($this->equalTo('edit'))
978
            ->willReturn(true);
979
980
        $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...
981
            ->method('hasAccess')
982
            ->with($this->equalTo('edit'), $object)
983
            ->willReturn(false);
984
985
        $response = $this->protectedTestedMethods['redirectTo']->invoke($this->controller, $object, $this->request);
986
        $this->assertInstanceOf(RedirectResponse::class, $response);
987
        $this->assertSame('list', $response->getTargetUrl());
988
    }
989
990
    public function getRedirectToTests()
991
    {
992
        return [
993
            ['stdClass_edit', 'edit', [], [], false],
994
            ['list', 'list', ['btn_update_and_list' => true], [], false],
995
            ['list', 'list', ['btn_create_and_list' => true], [], false],
996
            ['create', 'create', ['btn_create_and_create' => true], [], false],
997
            ['create?subclass=foo', 'create', ['btn_create_and_create' => true, 'subclass' => 'foo'], [], true],
998
            ['stdClass_edit?_tab=first_tab', 'edit', ['btn_update_and_edit' => true], ['_tab' => 'first_tab'], false],
999
        ];
1000
    }
1001
1002
    public function testDeleteActionNotFoundException(): void
1003
    {
1004
        $this->expectException(NotFoundHttpException::class);
1005
1006
        $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...
1007
            ->method('getObject')
1008
            ->willReturn(false);
1009
1010
        $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...
1011
    }
1012
1013
    public function testDeleteActionAccessDenied(): void
1014
    {
1015
        $this->expectException(AccessDeniedException::class);
1016
1017
        $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...
1018
            ->method('getObject')
1019
            ->willReturn(new \stdClass());
1020
1021
        $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...
1022
            ->method('checkAccess')
1023
            ->with($this->equalTo('delete'))
1024
            ->will($this->throwException(new AccessDeniedException()));
1025
1026
        $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...
1027
    }
1028
1029
    public function testPreDelete(): void
1030
    {
1031
        $object = new \stdClass();
1032
        $object->foo = 123456;
1033
1034
        $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...
1035
            ->method('getObject')
1036
            ->willReturn($object);
1037
1038
        $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...
1039
            ->method('checkAccess')
1040
            ->with($this->equalTo('delete'))
1041
            ->willReturn(true);
1042
1043
        $controller = new PreCRUDController();
1044
        $controller->setContainer($this->container);
1045
1046
        $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...
1047
        $this->assertInstanceOf(Response::class, $response);
1048
        $this->assertSame('preDelete called: 123456', $response->getContent());
1049
    }
1050
1051
    public function testDeleteAction(): void
1052
    {
1053
        $object = new \stdClass();
1054
1055
        $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...
1056
            ->method('getObject')
1057
            ->willReturn($object);
1058
1059
        $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...
1060
            ->method('checkAccess')
1061
            ->with($this->equalTo('delete'))
1062
            ->willReturn(true);
1063
1064
        $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...
1065
1066
        $this->assertSame($this->admin, $this->parameters['admin']);
1067
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1068
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1069
1070
        $this->assertSame('delete', $this->parameters['action']);
1071
        $this->assertSame($object, $this->parameters['object']);
1072
        $this->assertSame('csrf-token-123_sonata.delete', $this->parameters['csrf_token']);
1073
1074
        $this->assertSame([], $this->session->getFlashBag()->all());
1075
        $this->assertSame('@SonataAdmin/CRUD/delete.html.twig', $this->template);
1076
    }
1077
1078
    /**
1079
     * @group legacy
1080
     * @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.
1081
     */
1082
    public function testDeleteActionChildDeprecation(): void
1083
    {
1084
        $object = new \stdClass();
1085
        $object->parent = 'test';
1086
1087
        $object2 = new \stdClass();
1088
1089
        $admin = $this->createMock(PostAdmin::class);
1090
1091
        $admin->expects($this->once())
1092
            ->method('getObject')
1093
            ->willReturn($object2);
1094
1095
        $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...
1096
            ->method('getObject')
1097
            ->willReturn($object);
1098
1099
        $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...
1100
            ->method('getParent')
1101
            ->willReturn($admin);
1102
1103
        $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...
1104
            ->method('getParentAssociationMapping')
1105
            ->willReturn('parent');
1106
1107
        $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...
1108
    }
1109
1110
    public function testDeleteActionNoParentMappings(): void
1111
    {
1112
        $object = new \stdClass();
1113
1114
        $admin = $this->createMock(PostAdmin::class);
1115
1116
        $admin->expects($this->never())
1117
            ->method('getObject');
1118
1119
        $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...
1120
            ->method('getObject')
1121
            ->willReturn($object);
1122
1123
        $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...
1124
            ->method('getParent')
1125
            ->willReturn($admin);
1126
1127
        $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...
1128
            ->method('getParentAssociationMapping')
1129
            ->willReturn(false);
1130
1131
        $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...
1132
    }
1133
1134
    public function testDeleteActionNoCsrfToken(): void
1135
    {
1136
        $this->csrfProvider = null;
1137
1138
        $object = new \stdClass();
1139
1140
        $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...
1141
            ->method('getObject')
1142
            ->willReturn($object);
1143
1144
        $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...
1145
            ->method('checkAccess')
1146
            ->with($this->equalTo('delete'))
1147
            ->willReturn(true);
1148
1149
        $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...
1150
1151
        $this->assertSame($this->admin, $this->parameters['admin']);
1152
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1153
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1154
1155
        $this->assertSame('delete', $this->parameters['action']);
1156
        $this->assertSame($object, $this->parameters['object']);
1157
        $this->assertFalse($this->parameters['csrf_token']);
1158
1159
        $this->assertSame([], $this->session->getFlashBag()->all());
1160
        $this->assertSame('@SonataAdmin/CRUD/delete.html.twig', $this->template);
1161
    }
1162
1163
    public function testDeleteActionAjaxSuccess1(): void
1164
    {
1165
        $object = new \stdClass();
1166
1167
        $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...
1168
            ->method('getObject')
1169
            ->willReturn($object);
1170
1171
        $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...
1172
            ->method('checkAccess')
1173
            ->with($this->equalTo('delete'))
1174
            ->willReturn(true);
1175
1176
        $this->request->setMethod('DELETE');
1177
1178
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1179
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1180
1181
        $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...
1182
1183
        $this->assertInstanceOf(Response::class, $response);
1184
        $this->assertSame(json_encode(['result' => 'ok']), $response->getContent());
1185
        $this->assertSame([], $this->session->getFlashBag()->all());
1186
    }
1187
1188
    public function testDeleteActionAjaxSuccess2(): void
1189
    {
1190
        $object = new \stdClass();
1191
1192
        $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...
1193
            ->method('getObject')
1194
            ->willReturn($object);
1195
1196
        $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...
1197
            ->method('checkAccess')
1198
            ->with($this->equalTo('delete'))
1199
            ->willReturn(true);
1200
1201
        $this->request->setMethod('POST');
1202
        $this->request->request->set('_method', 'DELETE');
1203
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1204
1205
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1206
1207
        $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...
1208
1209
        $this->assertInstanceOf(Response::class, $response);
1210
        $this->assertSame(json_encode(['result' => 'ok']), $response->getContent());
1211
        $this->assertSame([], $this->session->getFlashBag()->all());
1212
    }
1213
1214
    public function testDeleteActionAjaxError(): void
1215
    {
1216
        $object = new \stdClass();
1217
1218
        $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...
1219
            ->method('getObject')
1220
            ->willReturn($object);
1221
1222
        $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...
1223
            ->method('checkAccess')
1224
            ->with($this->equalTo('delete'))
1225
            ->willReturn(true);
1226
1227
        $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...
1228
            ->method('getClass')
1229
            ->willReturn('stdClass');
1230
1231
        $this->assertLoggerLogsModelManagerException($this->admin, 'delete');
1232
1233
        $this->request->setMethod('DELETE');
1234
1235
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1236
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1237
1238
        $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...
1239
1240
        $this->assertInstanceOf(Response::class, $response);
1241
        $this->assertSame(json_encode(['result' => 'error']), $response->getContent());
1242
        $this->assertSame([], $this->session->getFlashBag()->all());
1243
    }
1244
1245
    public function testDeleteActionWithModelManagerExceptionInDebugMode(): void
1246
    {
1247
        $this->expectException(ModelManagerException::class);
1248
1249
        $object = new \stdClass();
1250
1251
        $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...
1252
            ->method('getObject')
1253
            ->willReturn($object);
1254
1255
        $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...
1256
            ->method('checkAccess')
1257
            ->with($this->equalTo('delete'))
1258
            ->willReturn(true);
1259
1260
        $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...
1261
            ->method('delete')
1262
            ->willReturnCallback(static function (): void {
1263
                throw new ModelManagerException();
1264
            });
1265
1266
        $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...
1267
            ->method('isDebug')
1268
            ->willReturn(true);
1269
1270
        $this->request->setMethod('DELETE');
1271
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1272
1273
        $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...
1274
    }
1275
1276
    /**
1277
     * @dataProvider getToStringValues
1278
     */
1279
    public function testDeleteActionSuccess1($expectedToStringValue, $toStringValue): void
1280
    {
1281
        $object = new \stdClass();
1282
1283
        $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...
1284
            ->method('getObject')
1285
            ->willReturn($object);
1286
1287
        $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...
1288
            ->method('toString')
1289
            ->with($this->equalTo($object))
1290
            ->willReturn($toStringValue);
1291
1292
        $this->expectTranslate('flash_delete_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1293
1294
        $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...
1295
            ->method('checkAccess')
1296
            ->with($this->equalTo('delete'))
1297
            ->willReturn(true);
1298
1299
        $this->request->setMethod('DELETE');
1300
1301
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1302
1303
        $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...
1304
1305
        $this->assertInstanceOf(RedirectResponse::class, $response);
1306
        $this->assertSame(['flash_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1307
        $this->assertSame('list', $response->getTargetUrl());
1308
    }
1309
1310
    /**
1311
     * @dataProvider getToStringValues
1312
     */
1313
    public function testDeleteActionSuccess2($expectedToStringValue, $toStringValue): void
1314
    {
1315
        $object = new \stdClass();
1316
1317
        $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...
1318
            ->method('getObject')
1319
            ->willReturn($object);
1320
1321
        $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...
1322
            ->method('checkAccess')
1323
            ->with($this->equalTo('delete'))
1324
            ->willReturn(true);
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('toString')
1328
            ->with($this->equalTo($object))
1329
            ->willReturn($toStringValue);
1330
1331
        $this->expectTranslate('flash_delete_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1332
1333
        $this->request->setMethod('POST');
1334
        $this->request->request->set('_method', 'DELETE');
1335
1336
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1337
1338
        $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...
1339
1340
        $this->assertInstanceOf(RedirectResponse::class, $response);
1341
        $this->assertSame(['flash_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1342
        $this->assertSame('list', $response->getTargetUrl());
1343
    }
1344
1345
    /**
1346
     * @dataProvider getToStringValues
1347
     */
1348
    public function testDeleteActionSuccessNoCsrfTokenProvider($expectedToStringValue, $toStringValue): void
1349
    {
1350
        $this->csrfProvider = null;
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
        $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...
1374
1375
        $this->assertInstanceOf(RedirectResponse::class, $response);
1376
        $this->assertSame(['flash_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1377
        $this->assertSame('list', $response->getTargetUrl());
1378
    }
1379
1380
    public function testDeleteActionWrongRequestMethod(): void
1381
    {
1382
        $object = new \stdClass();
1383
1384
        $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...
1385
            ->method('getObject')
1386
            ->willReturn($object);
1387
1388
        $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...
1389
            ->method('checkAccess')
1390
            ->with($this->equalTo('delete'))
1391
            ->willReturn(true);
1392
1393
        //without POST request parameter "_method" should not be used as real REST method
1394
        $this->request->query->set('_method', 'DELETE');
1395
1396
        $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...
1397
1398
        $this->assertSame($this->admin, $this->parameters['admin']);
1399
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1400
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1401
1402
        $this->assertSame('delete', $this->parameters['action']);
1403
        $this->assertSame($object, $this->parameters['object']);
1404
        $this->assertSame('csrf-token-123_sonata.delete', $this->parameters['csrf_token']);
1405
1406
        $this->assertSame([], $this->session->getFlashBag()->all());
1407
        $this->assertSame('@SonataAdmin/CRUD/delete.html.twig', $this->template);
1408
    }
1409
1410
    /**
1411
     * @dataProvider getToStringValues
1412
     */
1413
    public function testDeleteActionError($expectedToStringValue, $toStringValue): void
1414
    {
1415
        $object = new \stdClass();
1416
1417
        $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...
1418
            ->method('getObject')
1419
            ->willReturn($object);
1420
1421
        $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...
1422
            ->method('checkAccess')
1423
            ->with($this->equalTo('delete'))
1424
            ->willReturn(true);
1425
1426
        $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...
1427
            ->method('toString')
1428
            ->with($this->equalTo($object))
1429
            ->willReturn($toStringValue);
1430
1431
        $this->expectTranslate('flash_delete_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1432
1433
        $this->assertLoggerLogsModelManagerException($this->admin, 'delete');
1434
1435
        $this->request->setMethod('DELETE');
1436
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1437
1438
        $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...
1439
1440
        $this->assertInstanceOf(RedirectResponse::class, $response);
1441
        $this->assertSame(['flash_delete_error'], $this->session->getFlashBag()->get('sonata_flash_error'));
1442
        $this->assertSame('list', $response->getTargetUrl());
1443
    }
1444
1445
    public function testDeleteActionInvalidCsrfToken(): void
1446
    {
1447
        $object = new \stdClass();
1448
1449
        $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...
1450
            ->method('getObject')
1451
            ->willReturn($object);
1452
1453
        $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...
1454
            ->method('checkAccess')
1455
            ->with($this->equalTo('delete'))
1456
            ->willReturn(true);
1457
1458
        $this->request->setMethod('POST');
1459
        $this->request->request->set('_method', 'DELETE');
1460
        $this->request->request->set('_sonata_csrf_token', 'CSRF-INVALID');
1461
1462
        try {
1463
            $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...
1464
        } catch (HttpException $e) {
1465
            $this->assertSame('The csrf token is not valid, CSRF attack?', $e->getMessage());
1466
            $this->assertSame(400, $e->getStatusCode());
1467
        }
1468
    }
1469
1470
    public function testEditActionNotFoundException(): void
1471
    {
1472
        $this->expectException(NotFoundHttpException::class);
1473
1474
        $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...
1475
            ->method('getObject')
1476
            ->willReturn(false);
1477
1478
        $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...
1479
    }
1480
1481
    public function testEditActionRuntimeException(): void
1482
    {
1483
        $this->expectException(\RuntimeException::class);
1484
1485
        $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...
1486
            ->method('getObject')
1487
            ->willReturn(new \stdClass());
1488
1489
        $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...
1490
            ->method('checkAccess')
1491
            ->with($this->equalTo('edit'))
1492
            ->willReturn(true);
1493
1494
        $form = $this->createMock(Form::class);
1495
1496
        $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...
1497
            ->method('getForm')
1498
            ->willReturn($form);
1499
1500
        $form->expects($this->once())
1501
            ->method('all')
1502
            ->willReturn([]);
1503
1504
        $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...
1505
    }
1506
1507
    public function testEditActionAccessDenied(): void
1508
    {
1509
        $this->expectException(AccessDeniedException::class);
1510
1511
        $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...
1512
            ->method('getObject')
1513
            ->willReturn(new \stdClass());
1514
1515
        $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...
1516
            ->method('checkAccess')
1517
            ->with($this->equalTo('edit'))
1518
            ->will($this->throwException(new AccessDeniedException()));
1519
1520
        $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...
1521
    }
1522
1523
    public function testPreEdit(): void
1524
    {
1525
        $object = new \stdClass();
1526
        $object->foo = 123456;
1527
1528
        $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...
1529
            ->method('getObject')
1530
            ->willReturn($object);
1531
1532
        $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...
1533
            ->method('checkAccess')
1534
            ->with($this->equalTo('edit'))
1535
            ->willReturn(true);
1536
1537
        $controller = new PreCRUDController();
1538
        $controller->setContainer($this->container);
1539
1540
        $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...
1541
        $this->assertInstanceOf(Response::class, $response);
1542
        $this->assertSame('preEdit called: 123456', $response->getContent());
1543
    }
1544
1545
    public function testEditAction(): void
1546
    {
1547
        $object = new \stdClass();
1548
1549
        $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...
1550
            ->method('getObject')
1551
            ->willReturn($object);
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('checkAccess')
1555
            ->with($this->equalTo('edit'))
1556
            ->willReturn(true);
1557
1558
        $form = $this->createMock(Form::class);
1559
1560
        $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...
1561
            ->method('getForm')
1562
            ->willReturn($form);
1563
1564
        $formView = $this->createMock(FormView::class);
1565
1566
        $form->expects($this->any())
1567
            ->method('createView')
1568
            ->willReturn($formView);
1569
1570
        $form->expects($this->once())
1571
            ->method('all')
1572
            ->willReturn(['field' => 'fielddata']);
1573
1574
        $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...
1575
1576
        $this->assertSame($this->admin, $this->parameters['admin']);
1577
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1578
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1579
1580
        $this->assertSame('edit', $this->parameters['action']);
1581
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1582
        $this->assertSame($object, $this->parameters['object']);
1583
        $this->assertSame([], $this->session->getFlashBag()->all());
1584
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1585
    }
1586
1587
    /**
1588
     * @dataProvider getToStringValues
1589
     */
1590
    public function testEditActionSuccess($expectedToStringValue, $toStringValue): void
1591
    {
1592
        $object = new \stdClass();
1593
1594
        $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...
1595
            ->method('getObject')
1596
            ->willReturn($object);
1597
1598
        $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...
1599
            ->method('update')
1600
            ->willReturnArgument(0);
1601
1602
        $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...
1603
            ->method('checkAccess')
1604
            ->with($this->equalTo('edit'));
1605
1606
        $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...
1607
            ->method('hasRoute')
1608
            ->with($this->equalTo('edit'))
1609
            ->willReturn(true);
1610
1611
        $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...
1612
            ->method('hasAccess')
1613
            ->with($this->equalTo('edit'))
1614
            ->willReturn(true);
1615
1616
        $form = $this->createMock(Form::class);
1617
1618
        $form->expects($this->once())
1619
            ->method('getData')
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('getForm')
1624
            ->willReturn($form);
1625
1626
        $form->expects($this->once())
1627
            ->method('isSubmitted')
1628
            ->willReturn(true);
1629
1630
        $form->expects($this->once())
1631
            ->method('isValid')
1632
            ->willReturn(true);
1633
1634
        $form->expects($this->once())
1635
            ->method('all')
1636
            ->willReturn(['field' => 'fielddata']);
1637
1638
        $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...
1639
            ->method('toString')
1640
            ->with($this->equalTo($object))
1641
            ->willReturn($toStringValue);
1642
1643
        $this->expectTranslate('flash_edit_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1644
1645
        $this->request->setMethod('POST');
1646
1647
        $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...
1648
1649
        $this->assertInstanceOf(RedirectResponse::class, $response);
1650
        $this->assertSame(['flash_edit_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1651
        $this->assertSame('stdClass_edit', $response->getTargetUrl());
1652
    }
1653
1654
    /**
1655
     * @dataProvider getToStringValues
1656
     */
1657
    public function testEditActionError($expectedToStringValue, $toStringValue): void
1658
    {
1659
        $object = new \stdClass();
1660
1661
        $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...
1662
            ->method('getObject')
1663
            ->willReturn($object);
1664
1665
        $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...
1666
            ->method('checkAccess')
1667
            ->with($this->equalTo('edit'))
1668
            ->willReturn(true);
1669
1670
        $form = $this->createMock(Form::class);
1671
1672
        $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...
1673
            ->method('getForm')
1674
            ->willReturn($form);
1675
1676
        $form->expects($this->once())
1677
            ->method('isSubmitted')
1678
            ->willReturn(true);
1679
1680
        $form->expects($this->once())
1681
            ->method('isValid')
1682
            ->willReturn(false);
1683
1684
        $form->expects($this->once())
1685
            ->method('all')
1686
            ->willReturn(['field' => 'fielddata']);
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('toString')
1690
            ->with($this->equalTo($object))
1691
            ->willReturn($toStringValue);
1692
1693
        $this->expectTranslate('flash_edit_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1694
1695
        $this->request->setMethod('POST');
1696
1697
        $formView = $this->createMock(FormView::class);
1698
1699
        $form->expects($this->any())
1700
            ->method('createView')
1701
            ->willReturn($formView);
1702
1703
        $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...
1704
1705
        $this->assertSame($this->admin, $this->parameters['admin']);
1706
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1707
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1708
1709
        $this->assertSame('edit', $this->parameters['action']);
1710
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1711
        $this->assertSame($object, $this->parameters['object']);
1712
1713
        $this->assertSame(['sonata_flash_error' => ['flash_edit_error']], $this->session->getFlashBag()->all());
1714
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1715
    }
1716
1717
    public function testEditActionAjaxSuccess(): void
1718
    {
1719
        $object = new \stdClass();
1720
1721
        $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...
1722
            ->method('getObject')
1723
            ->willReturn($object);
1724
1725
        $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...
1726
            ->method('update')
1727
            ->willReturnArgument(0);
1728
1729
        $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...
1730
            ->method('checkAccess')
1731
            ->with($this->equalTo('edit'))
1732
            ->willReturn(true);
1733
1734
        $form = $this->createMock(Form::class);
1735
1736
        $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...
1737
            ->method('getForm')
1738
            ->willReturn($form);
1739
1740
        $form->expects($this->once())
1741
            ->method('isSubmitted')
1742
            ->willReturn(true);
1743
1744
        $form->expects($this->once())
1745
            ->method('isValid')
1746
            ->willReturn(true);
1747
1748
        $form->expects($this->once())
1749
            ->method('getData')
1750
            ->willReturn($object);
1751
1752
        $form->expects($this->once())
1753
            ->method('all')
1754
            ->willReturn(['field' => 'fielddata']);
1755
1756
        $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...
1757
            ->method('getNormalizedIdentifier')
1758
            ->with($this->equalTo($object))
1759
            ->willReturn('foo_normalized');
1760
1761
        $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...
1762
            ->method('toString')
1763
            ->willReturn('foo');
1764
1765
        $this->request->setMethod('POST');
1766
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1767
1768
        $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...
1769
1770
        $this->assertInstanceOf(Response::class, $response);
1771
        $this->assertSame(json_encode(['result' => 'ok', 'objectId' => 'foo_normalized', 'objectName' => 'foo']), $response->getContent());
1772
        $this->assertSame([], $this->session->getFlashBag()->all());
1773
    }
1774
1775
    public function testEditActionAjaxError(): void
1776
    {
1777
        $object = new \stdClass();
1778
1779
        $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...
1780
            ->method('getObject')
1781
            ->willReturn($object);
1782
1783
        $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...
1784
            ->method('checkAccess')
1785
            ->with($this->equalTo('edit'))
1786
            ->willReturn(true);
1787
1788
        $form = $this->createMock(Form::class);
1789
1790
        $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...
1791
            ->method('getForm')
1792
            ->willReturn($form);
1793
1794
        $form->expects($this->once())
1795
            ->method('isSubmitted')
1796
            ->willReturn(true);
1797
1798
        $form->expects($this->once())
1799
            ->method('isValid')
1800
            ->willReturn(false);
1801
1802
        $form->expects($this->once())
1803
            ->method('all')
1804
            ->willReturn(['field' => 'fielddata']);
1805
1806
        $formError = $this->createMock(FormError::class);
1807
        $formError->expects($this->atLeastOnce())
1808
            ->method('getMessage')
1809
            ->willReturn('Form error message');
1810
1811
        $form->expects($this->once())
1812
            ->method('getErrors')
1813
            ->with(true)
1814
            ->willReturn([$formError]);
1815
1816
        $this->request->setMethod('POST');
1817
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1818
        $this->request->headers->set('Accept', 'application/json');
1819
1820
        $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...
1821
        $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...
1822
    }
1823
1824
    /**
1825
     * @legacy
1826
     * @expectedDeprecation In next major version response will return 406 NOT ACCEPTABLE without `Accept: application/json`
1827
     */
1828
    public function testEditActionAjaxErrorWithoutAcceptApplicationJson(): void
1829
    {
1830
        $object = new \stdClass();
1831
1832
        $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...
1833
            ->method('getObject')
1834
            ->willReturn($object);
1835
1836
        $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...
1837
            ->method('checkAccess')
1838
            ->with($this->equalTo('edit'))
1839
            ->willReturn(true);
1840
1841
        $form = $this->createMock(Form::class);
1842
1843
        $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...
1844
            ->method('getForm')
1845
            ->willReturn($form);
1846
1847
        $form->expects($this->once())
1848
            ->method('isSubmitted')
1849
            ->willReturn(true);
1850
1851
        $form->expects($this->once())
1852
            ->method('isValid')
1853
            ->willReturn(false);
1854
1855
        $form->expects($this->once())
1856
            ->method('all')
1857
            ->willReturn(['field' => 'fielddata']);
1858
1859
        $this->request->setMethod('POST');
1860
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1861
1862
        $formView = $this->createMock(FormView::class);
1863
        $form
1864
            ->method('createView')
1865
            ->willReturn($formView);
1866
1867
        $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...
1868
        $this->assertSame($this->admin, $this->parameters['admin']);
1869
        $this->assertSame('@SonataAdmin/ajax_layout.html.twig', $this->parameters['base_template']);
1870
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1871
        $this->assertSame('edit', $this->parameters['action']);
1872
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1873
        $this->assertSame($object, $this->parameters['object']);
1874
        $this->assertSame(['sonata_flash_error' => [0 => null]], $this->session->getFlashBag()->all());
1875
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1876
    }
1877
1878
    /**
1879
     * @dataProvider getToStringValues
1880
     */
1881
    public function testEditActionWithModelManagerException($expectedToStringValue, $toStringValue): void
1882
    {
1883
        $object = new \stdClass();
1884
1885
        $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...
1886
            ->method('getObject')
1887
            ->willReturn($object);
1888
1889
        $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...
1890
            ->method('checkAccess')
1891
            ->with($this->equalTo('edit'))
1892
            ->willReturn(true);
1893
1894
        $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...
1895
            ->method('getClass')
1896
            ->willReturn('stdClass');
1897
1898
        $form = $this->createMock(Form::class);
1899
1900
        $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...
1901
            ->method('getForm')
1902
            ->willReturn($form);
1903
1904
        $form->expects($this->once())
1905
            ->method('isValid')
1906
            ->willReturn(true);
1907
1908
        $form->expects($this->once())
1909
            ->method('getData')
1910
            ->willReturn($object);
1911
1912
        $form->expects($this->once())
1913
            ->method('all')
1914
            ->willReturn(['field' => 'fielddata']);
1915
1916
        $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...
1917
            ->method('toString')
1918
            ->with($this->equalTo($object))
1919
            ->willReturn($toStringValue);
1920
1921
        $this->expectTranslate('flash_edit_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1922
1923
        $form->expects($this->once())
1924
            ->method('isSubmitted')
1925
            ->willReturn(true);
1926
        $this->request->setMethod('POST');
1927
1928
        $formView = $this->createMock(FormView::class);
1929
1930
        $form->expects($this->any())
1931
            ->method('createView')
1932
            ->willReturn($formView);
1933
1934
        $this->assertLoggerLogsModelManagerException($this->admin, 'update');
1935
        $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...
1936
1937
        $this->assertSame($this->admin, $this->parameters['admin']);
1938
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1939
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1940
1941
        $this->assertSame('edit', $this->parameters['action']);
1942
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1943
        $this->assertSame($object, $this->parameters['object']);
1944
1945
        $this->assertSame(['sonata_flash_error' => ['flash_edit_error']], $this->session->getFlashBag()->all());
1946
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1947
    }
1948
1949
    public function testEditActionWithPreview(): void
1950
    {
1951
        $object = new \stdClass();
1952
1953
        $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...
1954
            ->method('getObject')
1955
            ->willReturn($object);
1956
1957
        $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...
1958
            ->method('checkAccess')
1959
            ->with($this->equalTo('edit'))
1960
            ->willReturn(true);
1961
1962
        $form = $this->createMock(Form::class);
1963
1964
        $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...
1965
            ->method('getForm')
1966
            ->willReturn($form);
1967
1968
        $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...
1969
            ->method('supportsPreviewMode')
1970
            ->willReturn(true);
1971
1972
        $formView = $this->createMock(FormView::class);
1973
1974
        $form->expects($this->any())
1975
            ->method('createView')
1976
            ->willReturn($formView);
1977
1978
        $form->expects($this->once())
1979
            ->method('isSubmitted')
1980
            ->willReturn(true);
1981
1982
        $form->expects($this->once())
1983
            ->method('isValid')
1984
            ->willReturn(true);
1985
1986
        $form->expects($this->once())
1987
            ->method('all')
1988
            ->willReturn(['field' => 'fielddata']);
1989
1990
        $this->request->setMethod('POST');
1991
        $this->request->request->set('btn_preview', 'Preview');
1992
1993
        $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...
1994
1995
        $this->assertSame($this->admin, $this->parameters['admin']);
1996
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1997
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1998
1999
        $this->assertSame('edit', $this->parameters['action']);
2000
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2001
        $this->assertSame($object, $this->parameters['object']);
2002
2003
        $this->assertSame([], $this->session->getFlashBag()->all());
2004
        $this->assertSame('@SonataAdmin/CRUD/preview.html.twig', $this->template);
2005
    }
2006
2007
    public function testEditActionWithLockException(): void
2008
    {
2009
        $object = new \stdClass();
2010
        $class = \get_class($object);
2011
2012
        $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...
2013
            ->method('getObject')
2014
            ->willReturn($object);
2015
2016
        $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...
2017
            ->method('checkAccess')
2018
            ->with($this->equalTo('edit'))
2019
            ->willReturn(true);
2020
2021
        $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...
2022
            ->method('getClass')
2023
            ->willReturn($class);
2024
2025
        $form = $this->createMock(Form::class);
2026
2027
        $form->expects($this->any())
2028
            ->method('isValid')
2029
            ->willReturn(true);
2030
2031
        $form->expects($this->once())
2032
            ->method('getData')
2033
            ->willReturn($object);
2034
2035
        $form->expects($this->once())
2036
            ->method('all')
2037
            ->willReturn(['field' => 'fielddata']);
2038
2039
        $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...
2040
            ->method('getForm')
2041
            ->willReturn($form);
2042
2043
        $form->expects($this->any())
2044
            ->method('isSubmitted')
2045
            ->willReturn(true);
2046
        $this->request->setMethod('POST');
2047
2048
        $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...
2049
            ->method('update')
2050
            ->will($this->throwException(new LockException()));
2051
2052
        $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...
2053
            ->method('toString')
2054
            ->with($this->equalTo($object))
2055
            ->willReturn($class);
2056
2057
        $formView = $this->createMock(FormView::class);
2058
2059
        $form->expects($this->any())
2060
            ->method('createView')
2061
            ->willReturn($formView);
2062
2063
        $this->expectTranslate('flash_lock_error', [
2064
            '%name%' => $class,
2065
            '%link_start%' => '<a href="stdClass_edit">',
2066
            '%link_end%' => '</a>',
2067
        ], 'SonataAdminBundle');
2068
2069
        $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...
2070
    }
2071
2072
    public function testCreateActionAccessDenied(): void
2073
    {
2074
        $this->expectException(AccessDeniedException::class);
2075
2076
        $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...
2077
            ->method('checkAccess')
2078
            ->with($this->equalTo('create'))
2079
            ->will($this->throwException(new AccessDeniedException()));
2080
2081
        $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...
2082
    }
2083
2084
    public function testCreateActionRuntimeException(): void
2085
    {
2086
        $this->expectException(\RuntimeException::class);
2087
2088
        $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...
2089
            ->method('checkAccess')
2090
            ->with($this->equalTo('create'))
2091
            ->willReturn(true);
2092
2093
        $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...
2094
            ->method('getClass')
2095
            ->willReturn('stdClass');
2096
2097
        $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...
2098
            ->method('getNewInstance')
2099
            ->willReturn(new \stdClass());
2100
2101
        $form = $this->createMock(Form::class);
2102
2103
        $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...
2104
            ->method('getForm')
2105
            ->willReturn($form);
2106
2107
        $form->expects($this->once())
2108
            ->method('all')
2109
            ->willReturn([]);
2110
2111
        $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...
2112
    }
2113
2114
    public function testPreCreate(): void
2115
    {
2116
        $object = new \stdClass();
2117
        $object->foo = 123456;
2118
2119
        $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...
2120
            ->method('checkAccess')
2121
            ->with($this->equalTo('create'))
2122
            ->willReturn(true);
2123
2124
        $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...
2125
            ->method('getClass')
2126
            ->willReturn('stdClass');
2127
2128
        $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...
2129
            ->method('getNewInstance')
2130
            ->willReturn($object);
2131
2132
        $controller = new PreCRUDController();
2133
        $controller->setContainer($this->container);
2134
2135
        $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...
2136
        $this->assertInstanceOf(Response::class, $response);
2137
        $this->assertSame('preCreate called: 123456', $response->getContent());
2138
    }
2139
2140
    public function testCreateAction(): void
2141
    {
2142
        $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...
2143
            ->method('checkAccess')
2144
            ->with($this->equalTo('create'))
2145
            ->willReturn(true);
2146
2147
        $object = new \stdClass();
2148
2149
        $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...
2150
            ->method('getClass')
2151
            ->willReturn('stdClass');
2152
2153
        $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...
2154
            ->method('getNewInstance')
2155
            ->willReturn($object);
2156
2157
        $form = $this->createMock(Form::class);
2158
2159
        $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...
2160
            ->method('getForm')
2161
            ->willReturn($form);
2162
2163
        $form->expects($this->once())
2164
            ->method('all')
2165
            ->willReturn(['field' => 'fielddata']);
2166
2167
        $formView = $this->createMock(FormView::class);
2168
2169
        $form->expects($this->any())
2170
            ->method('createView')
2171
            ->willReturn($formView);
2172
2173
        $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...
2174
2175
        $this->assertSame($this->admin, $this->parameters['admin']);
2176
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2177
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2178
2179
        $this->assertSame('create', $this->parameters['action']);
2180
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2181
        $this->assertSame($object, $this->parameters['object']);
2182
2183
        $this->assertSame([], $this->session->getFlashBag()->all());
2184
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
2185
    }
2186
2187
    /**
2188
     * @dataProvider getToStringValues
2189
     */
2190
    public function testCreateActionSuccess($expectedToStringValue, $toStringValue): void
2191
    {
2192
        $object = new \stdClass();
2193
2194
        $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...
2195
            ->method('checkAccess')
2196
            ->willReturnCallback(static function ($name, $objectIn = null) use ($object) {
2197
                if ('edit' === $name) {
2198
                    return true;
2199
                }
2200
2201
                if ('create' !== $name) {
2202
                    return false;
2203
                }
2204
2205
                if (null === $objectIn) {
2206
                    return true;
2207
                }
2208
2209
                return $objectIn === $object;
2210
            });
2211
2212
        $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...
2213
            ->method('hasRoute')
2214
            ->with($this->equalTo('edit'))
2215
            ->willReturn(true);
2216
2217
        $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...
2218
            ->method('hasAccess')
2219
            ->with($this->equalTo('edit'))
2220
            ->willReturn(true);
2221
2222
        $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...
2223
            ->method('getNewInstance')
2224
            ->willReturn($object);
2225
2226
        $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...
2227
            ->method('create')
2228
            ->willReturnArgument(0);
2229
2230
        $form = $this->createMock(Form::class);
2231
2232
        $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...
2233
            ->method('getClass')
2234
            ->willReturn('stdClass');
2235
2236
        $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...
2237
            ->method('getForm')
2238
            ->willReturn($form);
2239
2240
        $form->expects($this->once())
2241
            ->method('all')
2242
            ->willReturn(['field' => 'fielddata']);
2243
2244
        $form->expects($this->once())
2245
            ->method('isSubmitted')
2246
            ->willReturn(true);
2247
2248
        $form->expects($this->once())
2249
            ->method('isValid')
2250
            ->willReturn(true);
2251
2252
        $form->expects($this->once())
2253
            ->method('getData')
2254
            ->willReturn($object);
2255
2256
        $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...
2257
            ->method('toString')
2258
            ->with($this->equalTo($object))
2259
            ->willReturn($toStringValue);
2260
2261
        $this->expectTranslate('flash_create_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
2262
2263
        $this->request->setMethod('POST');
2264
2265
        $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...
2266
2267
        $this->assertInstanceOf(RedirectResponse::class, $response);
2268
        $this->assertSame(['flash_create_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
2269
        $this->assertSame('stdClass_edit', $response->getTargetUrl());
2270
    }
2271
2272
    public function testCreateActionAccessDenied2(): void
2273
    {
2274
        $this->expectException(AccessDeniedException::class);
2275
2276
        $object = new \stdClass();
2277
2278
        $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...
2279
            ->method('checkAccess')
2280
            ->willReturnCallback(static function ($name, $object = null) {
2281
                if ('create' !== $name) {
2282
                    throw new AccessDeniedException();
2283
                }
2284
                if (null === $object) {
2285
                    return true;
2286
                }
2287
2288
                throw new AccessDeniedException();
2289
            });
2290
2291
        $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...
2292
            ->method('getNewInstance')
2293
            ->willReturn($object);
2294
2295
        $form = $this->createMock(Form::class);
2296
2297
        $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...
2298
            ->method('getClass')
2299
            ->willReturn('stdClass');
2300
2301
        $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...
2302
            ->method('getForm')
2303
            ->willReturn($form);
2304
2305
        $form->expects($this->once())
2306
            ->method('all')
2307
            ->willReturn(['field' => 'fielddata']);
2308
2309
        $form->expects($this->once())
2310
            ->method('isSubmitted')
2311
            ->willReturn(true);
2312
2313
        $form->expects($this->once())
2314
            ->method('getData')
2315
            ->willReturn($object);
2316
2317
        $form->expects($this->once())
2318
            ->method('isValid')
2319
            ->willReturn(true);
2320
2321
        $this->request->setMethod('POST');
2322
2323
        $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...
2324
    }
2325
2326
    /**
2327
     * @dataProvider getToStringValues
2328
     */
2329
    public function testCreateActionError($expectedToStringValue, $toStringValue): void
2330
    {
2331
        $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...
2332
            ->method('checkAccess')
2333
            ->with($this->equalTo('create'))
2334
            ->willReturn(true);
2335
2336
        $object = new \stdClass();
2337
2338
        $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...
2339
            ->method('getClass')
2340
            ->willReturn('stdClass');
2341
2342
        $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...
2343
            ->method('getNewInstance')
2344
            ->willReturn($object);
2345
2346
        $form = $this->createMock(Form::class);
2347
2348
        $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...
2349
            ->method('getForm')
2350
            ->willReturn($form);
2351
2352
        $form->expects($this->once())
2353
            ->method('all')
2354
            ->willReturn(['field' => 'fielddata']);
2355
2356
        $form->expects($this->once())
2357
            ->method('isSubmitted')
2358
            ->willReturn(true);
2359
2360
        $form->expects($this->once())
2361
            ->method('isValid')
2362
            ->willReturn(false);
2363
2364
        $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...
2365
            ->method('toString')
2366
            ->with($this->equalTo($object))
2367
            ->willReturn($toStringValue);
2368
2369
        $this->expectTranslate('flash_create_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
2370
2371
        $this->request->setMethod('POST');
2372
2373
        $formView = $this->createMock(FormView::class);
2374
2375
        $form->expects($this->any())
2376
            ->method('createView')
2377
            ->willReturn($formView);
2378
2379
        $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...
2380
2381
        $this->assertSame($this->admin, $this->parameters['admin']);
2382
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2383
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2384
2385
        $this->assertSame('create', $this->parameters['action']);
2386
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2387
        $this->assertSame($object, $this->parameters['object']);
2388
2389
        $this->assertSame(['sonata_flash_error' => ['flash_create_error']], $this->session->getFlashBag()->all());
2390
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
2391
    }
2392
2393
    /**
2394
     * @dataProvider getToStringValues
2395
     */
2396
    public function testCreateActionWithModelManagerException($expectedToStringValue, $toStringValue): void
2397
    {
2398
        $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...
2399
            ->method('checkAccess')
2400
            ->with($this->equalTo('create'))
2401
            ->willReturn(true);
2402
2403
        $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...
2404
            ->method('getClass')
2405
            ->willReturn('stdClass');
2406
2407
        $object = new \stdClass();
2408
2409
        $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...
2410
            ->method('getNewInstance')
2411
            ->willReturn($object);
2412
2413
        $form = $this->createMock(Form::class);
2414
2415
        $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...
2416
            ->method('getForm')
2417
            ->willReturn($form);
2418
2419
        $form->expects($this->once())
2420
            ->method('all')
2421
            ->willReturn(['field' => 'fielddata']);
2422
2423
        $form->expects($this->once())
2424
            ->method('isValid')
2425
            ->willReturn(true);
2426
2427
        $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...
2428
            ->method('toString')
2429
            ->with($this->equalTo($object))
2430
            ->willReturn($toStringValue);
2431
2432
        $this->expectTranslate('flash_create_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
2433
2434
        $form->expects($this->once())
2435
            ->method('isSubmitted')
2436
            ->willReturn(true);
2437
2438
        $form->expects($this->once())
2439
            ->method('getData')
2440
            ->willReturn($object);
2441
2442
        $this->request->setMethod('POST');
2443
2444
        $formView = $this->createMock(FormView::class);
2445
2446
        $form->expects($this->any())
2447
            ->method('createView')
2448
            ->willReturn($formView);
2449
2450
        $this->assertLoggerLogsModelManagerException($this->admin, 'create');
2451
2452
        $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...
2453
2454
        $this->assertSame($this->admin, $this->parameters['admin']);
2455
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2456
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2457
2458
        $this->assertSame('create', $this->parameters['action']);
2459
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2460
        $this->assertSame($object, $this->parameters['object']);
2461
2462
        $this->assertSame(['sonata_flash_error' => ['flash_create_error']], $this->session->getFlashBag()->all());
2463
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
2464
    }
2465
2466
    public function testCreateActionAjaxSuccess(): void
2467
    {
2468
        $object = new \stdClass();
2469
2470
        $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...
2471
            ->method('checkAccess')
2472
            ->willReturnCallback(static function ($name, $objectIn = null) use ($object) {
2473
                if ('create' !== $name) {
2474
                    return false;
2475
                }
2476
2477
                if (null === $objectIn) {
2478
                    return true;
2479
                }
2480
2481
                return $objectIn === $object;
2482
            });
2483
2484
        $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...
2485
            ->method('getNewInstance')
2486
            ->willReturn($object);
2487
2488
        $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...
2489
            ->method('create')
2490
            ->willReturnArgument(0);
2491
2492
        $form = $this->createMock(Form::class);
2493
2494
        $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...
2495
            ->method('getForm')
2496
            ->willReturn($form);
2497
2498
        $form->expects($this->once())
2499
            ->method('all')
2500
            ->willReturn(['field' => 'fielddata']);
2501
2502
        $form->expects($this->once())
2503
            ->method('isSubmitted')
2504
            ->willReturn(true);
2505
2506
        $form->expects($this->once())
2507
            ->method('isValid')
2508
            ->willReturn(true);
2509
2510
        $form->expects($this->once())
2511
            ->method('getData')
2512
            ->willReturn($object);
2513
2514
        $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...
2515
            ->method('getClass')
2516
            ->willReturn('stdClass');
2517
2518
        $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...
2519
            ->method('getNormalizedIdentifier')
2520
            ->with($this->equalTo($object))
2521
            ->willReturn('foo_normalized');
2522
2523
        $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...
2524
            ->method('toString')
2525
            ->willReturn('foo');
2526
2527
        $this->request->setMethod('POST');
2528
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
2529
2530
        $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...
2531
2532
        $this->assertInstanceOf(Response::class, $response);
2533
        $this->assertSame(json_encode(['result' => 'ok', 'objectId' => 'foo_normalized', 'objectName' => 'foo']), $response->getContent());
2534
        $this->assertSame([], $this->session->getFlashBag()->all());
2535
    }
2536
2537
    public function testCreateActionAjaxError(): void
2538
    {
2539
        $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...
2540
            ->method('checkAccess')
2541
            ->with($this->equalTo('create'))
2542
            ->willReturn(true);
2543
2544
        $object = new \stdClass();
2545
2546
        $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...
2547
            ->method('getNewInstance')
2548
            ->willReturn($object);
2549
2550
        $form = $this->createMock(Form::class);
2551
2552
        $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...
2553
            ->method('getClass')
2554
            ->willReturn('stdClass');
2555
2556
        $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...
2557
            ->method('getForm')
2558
            ->willReturn($form);
2559
2560
        $form->expects($this->once())
2561
            ->method('all')
2562
            ->willReturn(['field' => 'fielddata']);
2563
2564
        $form->expects($this->once())
2565
            ->method('isSubmitted')
2566
            ->willReturn(true);
2567
2568
        $form->expects($this->once())
2569
            ->method('isValid')
2570
            ->willReturn(false);
2571
2572
        $formError = $this->createMock(FormError::class);
2573
        $formError->expects($this->atLeastOnce())
2574
            ->method('getMessage')
2575
            ->willReturn('Form error message');
2576
2577
        $form->expects($this->once())
2578
            ->method('getErrors')
2579
            ->with(true)
2580
            ->willReturn([$formError]);
2581
2582
        $this->request->setMethod('POST');
2583
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
2584
        $this->request->headers->set('Accept', 'application/json');
2585
2586
        $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...
2587
        $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...
2588
    }
2589
2590
    /**
2591
     * @legacy
2592
     * @expectedDeprecation In next major version response will return 406 NOT ACCEPTABLE without `Accept: application/json`
2593
     */
2594
    public function testCreateActionAjaxErrorWithoutAcceptApplicationJson(): void
2595
    {
2596
        $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...
2597
            ->method('checkAccess')
2598
            ->with($this->equalTo('create'))
2599
            ->willReturn(true);
2600
2601
        $object = new \stdClass();
2602
2603
        $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...
2604
            ->method('getNewInstance')
2605
            ->willReturn($object);
2606
2607
        $form = $this->createMock(Form::class);
2608
2609
        $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...
2610
            ->method('getClass')
2611
            ->willReturn('stdClass');
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('getForm')
2615
            ->willReturn($form);
2616
2617
        $form->expects($this->once())
2618
            ->method('all')
2619
            ->willReturn(['field' => 'fielddata']);
2620
2621
        $form->expects($this->once())
2622
            ->method('isSubmitted')
2623
            ->willReturn(true);
2624
2625
        $form->expects($this->once())
2626
            ->method('isValid')
2627
            ->willReturn(false);
2628
2629
        $this->request->setMethod('POST');
2630
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
2631
2632
        $formView = $this->createMock(FormView::class);
2633
        $form
2634
            ->method('createView')
2635
            ->willReturn($formView);
2636
2637
        $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...
2638
        $this->assertSame($this->admin, $this->parameters['admin']);
2639
        $this->assertSame('@SonataAdmin/ajax_layout.html.twig', $this->parameters['base_template']);
2640
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2641
        $this->assertSame('create', $this->parameters['action']);
2642
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2643
        $this->assertSame($object, $this->parameters['object']);
2644
        $this->assertSame(['sonata_flash_error' => [0 => null]], $this->session->getFlashBag()->all());
2645
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
2646
    }
2647
2648
    public function testCreateActionWithPreview(): void
2649
    {
2650
        $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...
2651
            ->method('checkAccess')
2652
            ->with($this->equalTo('create'))
2653
            ->willReturn(true);
2654
2655
        $object = new \stdClass();
2656
2657
        $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...
2658
            ->method('getNewInstance')
2659
            ->willReturn($object);
2660
2661
        $form = $this->createMock(Form::class);
2662
2663
        $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...
2664
            ->method('getClass')
2665
            ->willReturn('stdClass');
2666
2667
        $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...
2668
            ->method('getForm')
2669
            ->willReturn($form);
2670
2671
        $form->expects($this->once())
2672
            ->method('all')
2673
            ->willReturn(['field' => 'fielddata']);
2674
2675
        $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...
2676
            ->method('supportsPreviewMode')
2677
            ->willReturn(true);
2678
2679
        $formView = $this->createMock(FormView::class);
2680
2681
        $form->expects($this->any())
2682
            ->method('createView')
2683
            ->willReturn($formView);
2684
2685
        $form->expects($this->once())
2686
            ->method('isSubmitted')
2687
            ->willReturn(true);
2688
2689
        $form->expects($this->once())
2690
            ->method('isValid')
2691
            ->willReturn(true);
2692
2693
        $this->request->setMethod('POST');
2694
        $this->request->request->set('btn_preview', 'Preview');
2695
2696
        $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...
2697
2698
        $this->assertSame($this->admin, $this->parameters['admin']);
2699
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2700
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2701
2702
        $this->assertSame('create', $this->parameters['action']);
2703
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2704
        $this->assertSame($object, $this->parameters['object']);
2705
2706
        $this->assertSame([], $this->session->getFlashBag()->all());
2707
        $this->assertSame('@SonataAdmin/CRUD/preview.html.twig', $this->template);
2708
    }
2709
2710
    public function testExportActionAccessDenied(): void
2711
    {
2712
        $this->expectException(AccessDeniedException::class);
2713
2714
        $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...
2715
            ->method('checkAccess')
2716
            ->with($this->equalTo('export'))
2717
            ->will($this->throwException(new AccessDeniedException()));
2718
2719
        $this->controller->exportAction($this->request);
2720
    }
2721
2722
    public function testExportActionWrongFormat(): void
2723
    {
2724
        $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...
2725
2726
        $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...
2727
            ->method('checkAccess')
2728
            ->with($this->equalTo('export'))
2729
            ->willReturn(true);
2730
2731
        $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...
2732
            ->method('getExportFormats')
2733
            ->willReturn(['json']);
2734
2735
        $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...
2736
            ->method('getClass')
2737
            ->willReturn('Foo');
2738
2739
        $this->request->query->set('format', 'csv');
2740
2741
        $this->controller->exportAction($this->request);
2742
    }
2743
2744
    public function testExportAction(): void
2745
    {
2746
        $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...
2747
            ->method('checkAccess')
2748
            ->with($this->equalTo('export'))
2749
            ->willReturn(true);
2750
2751
        $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...
2752
            ->method('getExportFormats')
2753
            ->willReturn(['json']);
2754
2755
        $dataSourceIterator = $this->createMock(SourceIteratorInterface::class);
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('getDataSourceIterator')
2759
            ->willReturn($dataSourceIterator);
2760
2761
        $this->request->query->set('format', 'json');
2762
2763
        $response = $this->controller->exportAction($this->request);
2764
        $this->assertInstanceOf(StreamedResponse::class, $response);
2765
        $this->assertSame(200, $response->getStatusCode());
2766
        $this->assertSame([], $this->session->getFlashBag()->all());
2767
    }
2768
2769
    public function testHistoryActionAccessDenied(): void
2770
    {
2771
        $this->expectException(AccessDeniedException::class);
2772
2773
        $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...
2774
            ->method('getObject')
2775
            ->willReturn(new \StdClass());
2776
2777
        $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...
2778
            ->method('checkAccess')
2779
            ->with($this->equalTo('history'))
2780
            ->will($this->throwException(new AccessDeniedException()));
2781
2782
        $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...
2783
    }
2784
2785
    public function testHistoryActionNotFoundException(): void
2786
    {
2787
        $this->expectException(NotFoundHttpException::class);
2788
2789
        $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...
2790
            ->method('getObject')
2791
            ->willReturn(false);
2792
2793
        $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...
2794
    }
2795
2796
    public function testHistoryActionNoReader(): void
2797
    {
2798
        $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...
2799
2800
        $this->request->query->set('id', 123);
2801
2802
        $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...
2803
            ->method('checkAccess')
2804
            ->with($this->equalTo('history'))
2805
            ->willReturn(true);
2806
2807
        $object = new \stdClass();
2808
2809
        $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...
2810
            ->method('getObject')
2811
            ->willReturn($object);
2812
2813
        $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...
2814
            ->method('getClass')
2815
            ->willReturn('Foo');
2816
2817
        $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...
2818
            ->method('hasReader')
2819
            ->with($this->equalTo('Foo'))
2820
            ->willReturn(false);
2821
2822
        $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...
2823
    }
2824
2825
    public function testHistoryAction(): void
2826
    {
2827
        $this->request->query->set('id', 123);
2828
2829
        $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...
2830
            ->method('checkAccess')
2831
            ->with($this->equalTo('history'))
2832
            ->willReturn(true);
2833
2834
        $object = new \stdClass();
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('getObject')
2838
            ->willReturn($object);
2839
2840
        $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...
2841
            ->method('getClass')
2842
            ->willReturn('Foo');
2843
2844
        $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...
2845
            ->method('hasReader')
2846
            ->with($this->equalTo('Foo'))
2847
            ->willReturn(true);
2848
2849
        $reader = $this->createMock(AuditReaderInterface::class);
2850
2851
        $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...
2852
            ->method('getReader')
2853
            ->with($this->equalTo('Foo'))
2854
            ->willReturn($reader);
2855
2856
        $reader->expects($this->once())
2857
            ->method('findRevisions')
2858
            ->with($this->equalTo('Foo'), $this->equalTo(123))
2859
            ->willReturn([]);
2860
2861
        $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...
2862
2863
        $this->assertSame($this->admin, $this->parameters['admin']);
2864
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2865
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2866
2867
        $this->assertSame('history', $this->parameters['action']);
2868
        $this->assertSame([], $this->parameters['revisions']);
2869
        $this->assertSame($object, $this->parameters['object']);
2870
2871
        $this->assertSame([], $this->session->getFlashBag()->all());
2872
        $this->assertSame('@SonataAdmin/CRUD/history.html.twig', $this->template);
2873
    }
2874
2875
    public function testAclActionAclNotEnabled(): void
2876
    {
2877
        $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...
2878
2879
        $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...
2880
    }
2881
2882
    public function testAclActionNotFoundException(): void
2883
    {
2884
        $this->expectException(NotFoundHttpException::class);
2885
2886
        $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...
2887
            ->method('isAclEnabled')
2888
            ->willReturn(true);
2889
2890
        $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...
2891
            ->method('getObject')
2892
            ->willReturn(false);
2893
2894
        $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...
2895
    }
2896
2897
    public function testAclActionAccessDenied(): void
2898
    {
2899
        $this->expectException(AccessDeniedException::class);
2900
2901
        $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...
2902
            ->method('isAclEnabled')
2903
            ->willReturn(true);
2904
2905
        $object = new \stdClass();
2906
2907
        $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...
2908
            ->method('getObject')
2909
            ->willReturn($object);
2910
2911
        $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...
2912
            ->method('checkAccess')
2913
            ->with($this->equalTo('acl'), $this->equalTo($object))
2914
            ->will($this->throwException(new AccessDeniedException()));
2915
2916
        $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...
2917
    }
2918
2919
    public function testAclAction(): void
2920
    {
2921
        $this->request->query->set('id', 123);
2922
2923
        $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...
2924
            ->method('isAclEnabled')
2925
            ->willReturn(true);
2926
2927
        $object = new \stdClass();
2928
2929
        $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...
2930
            ->method('getObject')
2931
            ->willReturn($object);
2932
2933
        $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...
2934
            ->method('checkAccess')
2935
            ->willReturn(true);
2936
2937
        $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...
2938
            ->method('getSecurityInformation')
2939
            ->willReturn([]);
2940
2941
        $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...
2942
            ->method('getMaskBuilderClass')
2943
            ->willReturn(AdminPermissionMap::class);
2944
2945
        $aclUsersForm = $this->getMockBuilder(Form::class)
2946
            ->disableOriginalConstructor()
2947
            ->getMock();
2948
2949
        $aclUsersForm->expects($this->once())
2950
            ->method('createView')
2951
            ->willReturn($this->createMock(FormView::class));
2952
2953
        $aclRolesForm = $this->getMockBuilder(Form::class)
2954
            ->disableOriginalConstructor()
2955
            ->getMock();
2956
2957
        $aclRolesForm->expects($this->once())
2958
            ->method('createView')
2959
            ->willReturn($this->createMock(FormView::class));
2960
2961
        $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...
2962
            ->method('createAclUsersForm')
2963
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2964
            ->willReturn($aclUsersForm);
2965
2966
        $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...
2967
            ->method('createAclRolesForm')
2968
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2969
            ->willReturn($aclRolesForm);
2970
2971
        $aclSecurityHandler = $this->getMockBuilder(AclSecurityHandler::class)
2972
            ->disableOriginalConstructor()
2973
            ->getMock();
2974
2975
        $aclSecurityHandler->expects($this->any())
2976
            ->method('getObjectPermissions')
2977
            ->willReturn([]);
2978
2979
        $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...
2980
            ->method('getSecurityHandler')
2981
            ->willReturn($aclSecurityHandler);
2982
2983
        $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...
2984
2985
        $this->assertSame($this->admin, $this->parameters['admin']);
2986
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2987
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2988
2989
        $this->assertSame('acl', $this->parameters['action']);
2990
        $this->assertSame([], $this->parameters['permissions']);
2991
        $this->assertSame($object, $this->parameters['object']);
2992
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['users']);
2993
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['roles']);
2994
        $this->assertInstanceOf(FormView::class, $this->parameters['aclUsersForm']);
2995
        $this->assertInstanceOf(FormView::class, $this->parameters['aclRolesForm']);
2996
2997
        $this->assertSame([], $this->session->getFlashBag()->all());
2998
        $this->assertSame('@SonataAdmin/CRUD/acl.html.twig', $this->template);
2999
    }
3000
3001
    public function testAclActionInvalidUpdate(): void
3002
    {
3003
        $this->request->query->set('id', 123);
3004
        $this->request->request->set(AdminObjectAclManipulator::ACL_USERS_FORM_NAME, []);
3005
3006
        $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...
3007
            ->method('isAclEnabled')
3008
            ->willReturn(true);
3009
3010
        $object = new \stdClass();
3011
3012
        $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...
3013
            ->method('getObject')
3014
            ->willReturn($object);
3015
3016
        $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...
3017
            ->method('checkAccess')
3018
            ->willReturn(true);
3019
3020
        $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...
3021
            ->method('getSecurityInformation')
3022
            ->willReturn([]);
3023
3024
        $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...
3025
            ->method('getMaskBuilderClass')
3026
            ->willReturn(AdminPermissionMap::class);
3027
3028
        $aclUsersForm = $this->getMockBuilder(Form::class)
3029
            ->disableOriginalConstructor()
3030
            ->getMock();
3031
3032
        $aclUsersForm->expects($this->once())
3033
            ->method('isValid')
3034
            ->willReturn(false);
3035
3036
        $aclUsersForm->expects($this->once())
3037
            ->method('createView')
3038
            ->willReturn($this->createMock(FormView::class));
3039
3040
        $aclRolesForm = $this->getMockBuilder(Form::class)
3041
            ->disableOriginalConstructor()
3042
            ->getMock();
3043
3044
        $aclRolesForm->expects($this->once())
3045
            ->method('createView')
3046
            ->willReturn($this->createMock(FormView::class));
3047
3048
        $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...
3049
            ->method('createAclUsersForm')
3050
            ->with($this->isInstanceOf(AdminObjectAclData::class))
3051
            ->willReturn($aclUsersForm);
3052
3053
        $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...
3054
            ->method('createAclRolesForm')
3055
            ->with($this->isInstanceOf(AdminObjectAclData::class))
3056
            ->willReturn($aclRolesForm);
3057
3058
        $aclSecurityHandler = $this->getMockBuilder(AclSecurityHandler::class)
3059
            ->disableOriginalConstructor()
3060
            ->getMock();
3061
3062
        $aclSecurityHandler->expects($this->any())
3063
            ->method('getObjectPermissions')
3064
            ->willReturn([]);
3065
3066
        $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...
3067
            ->method('getSecurityHandler')
3068
            ->willReturn($aclSecurityHandler);
3069
3070
        $this->request->setMethod('POST');
3071
3072
        $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...
3073
3074
        $this->assertSame($this->admin, $this->parameters['admin']);
3075
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
3076
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3077
3078
        $this->assertSame('acl', $this->parameters['action']);
3079
        $this->assertSame([], $this->parameters['permissions']);
3080
        $this->assertSame($object, $this->parameters['object']);
3081
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['users']);
3082
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['roles']);
3083
        $this->assertInstanceOf(FormView::class, $this->parameters['aclUsersForm']);
3084
        $this->assertInstanceOf(FormView::class, $this->parameters['aclRolesForm']);
3085
3086
        $this->assertSame([], $this->session->getFlashBag()->all());
3087
        $this->assertSame('@SonataAdmin/CRUD/acl.html.twig', $this->template);
3088
    }
3089
3090
    public function testAclActionSuccessfulUpdate(): void
3091
    {
3092
        $this->request->query->set('id', 123);
3093
        $this->request->request->set(AdminObjectAclManipulator::ACL_ROLES_FORM_NAME, []);
3094
3095
        $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...
3096
            ->method('isAclEnabled')
3097
            ->willReturn(true);
3098
3099
        $object = new \stdClass();
3100
3101
        $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...
3102
            ->method('getObject')
3103
            ->willReturn($object);
3104
3105
        $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...
3106
            ->method('checkAccess')
3107
            ->willReturn(true);
3108
3109
        $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...
3110
            ->method('getSecurityInformation')
3111
            ->willReturn([]);
3112
3113
        $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...
3114
            ->method('getMaskBuilderClass')
3115
            ->willReturn(AdminPermissionMap::class);
3116
3117
        $aclUsersForm = $this->getMockBuilder(Form::class)
3118
            ->disableOriginalConstructor()
3119
            ->getMock();
3120
3121
        $aclUsersForm->expects($this->any())
3122
            ->method('createView')
3123
            ->willReturn($this->createMock(FormView::class));
3124
3125
        $aclRolesForm = $this->getMockBuilder(Form::class)
3126
            ->disableOriginalConstructor()
3127
            ->getMock();
3128
3129
        $aclRolesForm->expects($this->any())
3130
            ->method('createView')
3131
            ->willReturn($this->createMock(FormView::class));
3132
3133
        $aclRolesForm->expects($this->once())
3134
            ->method('isValid')
3135
            ->willReturn(true);
3136
3137
        $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...
3138
            ->method('createAclUsersForm')
3139
            ->with($this->isInstanceOf(AdminObjectAclData::class))
3140
            ->willReturn($aclUsersForm);
3141
3142
        $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...
3143
            ->method('createAclRolesForm')
3144
            ->with($this->isInstanceOf(AdminObjectAclData::class))
3145
            ->willReturn($aclRolesForm);
3146
3147
        $aclSecurityHandler = $this->getMockBuilder(AclSecurityHandler::class)
3148
            ->disableOriginalConstructor()
3149
            ->getMock();
3150
3151
        $aclSecurityHandler->expects($this->any())
3152
            ->method('getObjectPermissions')
3153
            ->willReturn([]);
3154
3155
        $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...
3156
            ->method('getSecurityHandler')
3157
            ->willReturn($aclSecurityHandler);
3158
3159
        $this->expectTranslate('flash_acl_edit_success', [], 'SonataAdminBundle');
3160
3161
        $this->request->setMethod('POST');
3162
3163
        $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...
3164
3165
        $this->assertInstanceOf(RedirectResponse::class, $response);
3166
3167
        $this->assertSame(['flash_acl_edit_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3168
        $this->assertSame('stdClass_acl', $response->getTargetUrl());
3169
    }
3170
3171
    public function testHistoryViewRevisionActionAccessDenied(): void
3172
    {
3173
        $this->expectException(AccessDeniedException::class);
3174
3175
        $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...
3176
            ->method('getObject')
3177
            ->willReturn(new \StdClass());
3178
3179
        $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...
3180
            ->method('checkAccess')
3181
            ->with($this->equalTo('historyViewRevision'))
3182
            ->will($this->throwException(new AccessDeniedException()));
3183
3184
        $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...
3185
    }
3186
3187
    public function testHistoryViewRevisionActionNotFoundException(): void
3188
    {
3189
        $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...
3190
3191
        $this->request->query->set('id', 123);
3192
3193
        $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...
3194
            ->method('getObject')
3195
            ->willReturn(false);
3196
3197
        $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...
3198
    }
3199
3200
    public function testHistoryViewRevisionActionNoReader(): void
3201
    {
3202
        $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...
3203
3204
        $this->request->query->set('id', 123);
3205
3206
        $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...
3207
            ->method('checkAccess')
3208
            ->with($this->equalTo('historyViewRevision'))
3209
            ->willReturn(true);
3210
3211
        $object = new \stdClass();
3212
3213
        $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...
3214
            ->method('getObject')
3215
            ->willReturn($object);
3216
3217
        $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...
3218
            ->method('getClass')
3219
            ->willReturn('Foo');
3220
3221
        $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...
3222
            ->method('hasReader')
3223
            ->with($this->equalTo('Foo'))
3224
            ->willReturn(false);
3225
3226
        $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...
3227
    }
3228
3229
    public function testHistoryViewRevisionActionNotFoundRevision(): void
3230
    {
3231
        $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...
3232
3233
        $this->request->query->set('id', 123);
3234
3235
        $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...
3236
            ->method('checkAccess')
3237
            ->with($this->equalTo('historyViewRevision'))
3238
            ->willReturn(true);
3239
3240
        $object = new \stdClass();
3241
3242
        $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...
3243
            ->method('getObject')
3244
            ->willReturn($object);
3245
3246
        $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...
3247
            ->method('getClass')
3248
            ->willReturn('Foo');
3249
3250
        $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...
3251
            ->method('hasReader')
3252
            ->with($this->equalTo('Foo'))
3253
            ->willReturn(true);
3254
3255
        $reader = $this->createMock(AuditReaderInterface::class);
3256
3257
        $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...
3258
            ->method('getReader')
3259
            ->with($this->equalTo('Foo'))
3260
            ->willReturn($reader);
3261
3262
        $reader->expects($this->once())
3263
            ->method('find')
3264
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3265
            ->willReturn(null);
3266
3267
        $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...
3268
    }
3269
3270
    public function testHistoryViewRevisionAction(): void
3271
    {
3272
        $this->request->query->set('id', 123);
3273
3274
        $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...
3275
            ->method('checkAccess')
3276
            ->with($this->equalTo('historyViewRevision'))
3277
            ->willReturn(true);
3278
3279
        $object = new \stdClass();
3280
3281
        $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...
3282
            ->method('getObject')
3283
            ->willReturn($object);
3284
3285
        $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...
3286
            ->method('getClass')
3287
            ->willReturn('Foo');
3288
3289
        $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...
3290
            ->method('hasReader')
3291
            ->with($this->equalTo('Foo'))
3292
            ->willReturn(true);
3293
3294
        $reader = $this->createMock(AuditReaderInterface::class);
3295
3296
        $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...
3297
            ->method('getReader')
3298
            ->with($this->equalTo('Foo'))
3299
            ->willReturn($reader);
3300
3301
        $objectRevision = new \stdClass();
3302
        $objectRevision->revision = 456;
3303
3304
        $reader->expects($this->once())
3305
            ->method('find')
3306
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3307
            ->willReturn($objectRevision);
3308
3309
        $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...
3310
            ->method('setSubject')
3311
            ->with($this->equalTo($objectRevision))
3312
            ->willReturn(null);
3313
3314
        $fieldDescriptionCollection = new FieldDescriptionCollection();
3315
        $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...
3316
            ->method('getShow')
3317
            ->willReturn($fieldDescriptionCollection);
3318
3319
        $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...
3320
3321
        $this->assertSame($this->admin, $this->parameters['admin']);
3322
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
3323
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3324
3325
        $this->assertSame('show', $this->parameters['action']);
3326
        $this->assertSame($objectRevision, $this->parameters['object']);
3327
        $this->assertSame($fieldDescriptionCollection, $this->parameters['elements']);
3328
3329
        $this->assertSame([], $this->session->getFlashBag()->all());
3330
        $this->assertSame('@SonataAdmin/CRUD/show.html.twig', $this->template);
3331
    }
3332
3333
    public function testHistoryCompareRevisionsActionAccessDenied(): void
3334
    {
3335
        $this->expectException(AccessDeniedException::class);
3336
3337
        $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...
3338
            ->method('checkAccess')
3339
            ->with($this->equalTo('historyCompareRevisions'))
3340
            ->will($this->throwException(new AccessDeniedException()));
3341
3342
        $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...
3343
    }
3344
3345
    public function testHistoryCompareRevisionsActionNotFoundException(): void
3346
    {
3347
        $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...
3348
3349
        $this->request->query->set('id', 123);
3350
3351
        $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...
3352
            ->method('checkAccess')
3353
            ->with($this->equalTo('historyCompareRevisions'))
3354
            ->willReturn(true);
3355
3356
        $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...
3357
            ->method('getObject')
3358
            ->willReturn(false);
3359
3360
        $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...
3361
    }
3362
3363
    public function testHistoryCompareRevisionsActionNoReader(): void
3364
    {
3365
        $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...
3366
3367
        $this->request->query->set('id', 123);
3368
3369
        $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...
3370
            ->method('checkAccess')
3371
            ->with($this->equalTo('historyCompareRevisions'))
3372
            ->willReturn(true);
3373
3374
        $object = new \stdClass();
3375
3376
        $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...
3377
            ->method('getObject')
3378
            ->willReturn($object);
3379
3380
        $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...
3381
            ->method('getClass')
3382
            ->willReturn('Foo');
3383
3384
        $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...
3385
            ->method('hasReader')
3386
            ->with($this->equalTo('Foo'))
3387
            ->willReturn(false);
3388
3389
        $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...
3390
    }
3391
3392
    public function testHistoryCompareRevisionsActionNotFoundBaseRevision(): void
3393
    {
3394
        $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...
3395
3396
        $this->request->query->set('id', 123);
3397
3398
        $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...
3399
            ->method('checkAccess')
3400
            ->with($this->equalTo('historyCompareRevisions'))
3401
            ->willReturn(true);
3402
3403
        $object = new \stdClass();
3404
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('getObject')
3407
            ->willReturn($object);
3408
3409
        $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...
3410
            ->method('getClass')
3411
            ->willReturn('Foo');
3412
3413
        $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...
3414
            ->method('hasReader')
3415
            ->with($this->equalTo('Foo'))
3416
            ->willReturn(true);
3417
3418
        $reader = $this->createMock(AuditReaderInterface::class);
3419
3420
        $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...
3421
            ->method('getReader')
3422
            ->with($this->equalTo('Foo'))
3423
            ->willReturn($reader);
3424
3425
        // once because it will not be found and therefore the second call won't be executed
3426
        $reader->expects($this->once())
3427
            ->method('find')
3428
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3429
            ->willReturn(null);
3430
3431
        $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...
3432
    }
3433
3434
    public function testHistoryCompareRevisionsActionNotFoundCompareRevision(): void
3435
    {
3436
        $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...
3437
3438
        $this->request->query->set('id', 123);
3439
3440
        $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...
3441
            ->method('checkAccess')
3442
            ->with($this->equalTo('historyCompareRevisions'))
3443
            ->willReturn(true);
3444
3445
        $object = new \stdClass();
3446
3447
        $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...
3448
            ->method('getObject')
3449
            ->willReturn($object);
3450
3451
        $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...
3452
            ->method('getClass')
3453
            ->willReturn('Foo');
3454
3455
        $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...
3456
            ->method('hasReader')
3457
            ->with($this->equalTo('Foo'))
3458
            ->willReturn(true);
3459
3460
        $reader = $this->createMock(AuditReaderInterface::class);
3461
3462
        $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...
3463
            ->method('getReader')
3464
            ->with($this->equalTo('Foo'))
3465
            ->willReturn($reader);
3466
3467
        $objectRevision = new \stdClass();
3468
        $objectRevision->revision = 456;
3469
3470
        // first call should return, so the second call will throw an exception
3471
        $reader->expects($this->at(0))
3472
            ->method('find')
3473
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3474
            ->willReturn($objectRevision);
3475
3476
        $reader->expects($this->at(1))
3477
            ->method('find')
3478
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(789))
3479
            ->willReturn(null);
3480
3481
        $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...
3482
    }
3483
3484
    public function testHistoryCompareRevisionsActionAction(): void
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
        $objectRevision = new \stdClass();
3516
        $objectRevision->revision = 456;
3517
3518
        $compareObjectRevision = new \stdClass();
3519
        $compareObjectRevision->revision = 789;
3520
3521
        $reader->expects($this->at(0))
3522
            ->method('find')
3523
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3524
            ->willReturn($objectRevision);
3525
3526
        $reader->expects($this->at(1))
3527
            ->method('find')
3528
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(789))
3529
            ->willReturn($compareObjectRevision);
3530
3531
        $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...
3532
            ->method('setSubject')
3533
            ->with($this->equalTo($objectRevision))
3534
            ->willReturn(null);
3535
3536
        $fieldDescriptionCollection = new FieldDescriptionCollection();
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('getShow')
3539
            ->willReturn($fieldDescriptionCollection);
3540
3541
        $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...
3542
3543
        $this->assertSame($this->admin, $this->parameters['admin']);
3544
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
3545
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3546
3547
        $this->assertSame('show', $this->parameters['action']);
3548
        $this->assertSame($objectRevision, $this->parameters['object']);
3549
        $this->assertSame($compareObjectRevision, $this->parameters['object_compare']);
3550
        $this->assertSame($fieldDescriptionCollection, $this->parameters['elements']);
3551
3552
        $this->assertSame([], $this->session->getFlashBag()->all());
3553
        $this->assertSame('@SonataAdmin/CRUD/show_compare.html.twig', $this->template);
3554
    }
3555
3556
    public function testBatchActionWrongMethod(): void
3557
    {
3558
        $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...
3559
3560
        $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...
3561
    }
3562
3563
    /**
3564
     * NEXT_MAJOR: Remove this legacy group.
3565
     *
3566
     * @group legacy
3567
     */
3568
    public function testBatchActionActionNotDefined(): void
3569
    {
3570
        $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...
3571
3572
        $batchActions = [];
3573
3574
        $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...
3575
            ->method('getBatchActions')
3576
            ->willReturn($batchActions);
3577
3578
        $this->request->setMethod('POST');
3579
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3580
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3581
3582
        $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...
3583
    }
3584
3585
    public function testBatchActionActionInvalidCsrfToken(): void
3586
    {
3587
        $this->request->setMethod('POST');
3588
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3589
        $this->request->request->set('_sonata_csrf_token', 'CSRF-INVALID');
3590
3591
        try {
3592
            $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...
3593
        } catch (HttpException $e) {
3594
            $this->assertSame('The csrf token is not valid, CSRF attack?', $e->getMessage());
3595
            $this->assertSame(400, $e->getStatusCode());
3596
        }
3597
    }
3598
3599
    /**
3600
     * NEXT_MAJOR: Remove this legacy group.
3601
     *
3602
     * @group legacy
3603
     */
3604
    public function testBatchActionMethodNotExist(): void
3605
    {
3606
        $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...
3607
3608
        $batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3609
3610
        $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...
3611
            ->method('getBatchActions')
3612
            ->willReturn($batchActions);
3613
3614
        $datagrid = $this->createMock(DatagridInterface::class);
3615
        $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...
3616
            ->method('getDatagrid')
3617
            ->willReturn($datagrid);
3618
3619
        $this->request->setMethod('POST');
3620
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3621
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3622
3623
        $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...
3624
    }
3625
3626
    /**
3627
     * NEXT_MAJOR: Remove this legacy group.
3628
     *
3629
     * @group legacy
3630
     */
3631
    public function testBatchActionWithoutConfirmation(): void
3632
    {
3633
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3634
3635
        $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...
3636
            ->method('getBatchActions')
3637
            ->willReturn($batchActions);
3638
3639
        $datagrid = $this->createMock(DatagridInterface::class);
3640
3641
        $query = $this->createMock(ProxyQueryInterface::class);
3642
        $datagrid->expects($this->once())
3643
            ->method('getQuery')
3644
            ->willReturn($query);
3645
3646
        $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...
3647
            ->method('getDatagrid')
3648
            ->willReturn($datagrid);
3649
3650
        $modelManager = $this->createMock(ModelManagerInterface::class);
3651
3652
        $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...
3653
            ->method('checkAccess')
3654
            ->with($this->equalTo('batchDelete'))
3655
            ->willReturn(true);
3656
3657
        $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...
3658
            ->method('getModelManager')
3659
            ->willReturn($modelManager);
3660
3661
        $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...
3662
            ->method('getClass')
3663
            ->willReturn('Foo');
3664
3665
        $modelManager->expects($this->once())
3666
            ->method('addIdentifiersToQuery')
3667
            ->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456']))
3668
            ->willReturn(true);
3669
3670
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
3671
3672
        $this->request->setMethod('POST');
3673
        $this->request->request->set('data', json_encode(['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false]));
3674
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3675
3676
        $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...
3677
3678
        $this->assertInstanceOf(RedirectResponse::class, $result);
3679
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3680
        $this->assertSame('list', $result->getTargetUrl());
3681
    }
3682
3683
    /**
3684
     * NEXT_MAJOR: Remove this legacy group.
3685
     *
3686
     * @group legacy
3687
     */
3688
    public function testBatchActionWithoutConfirmation2(): void
3689
    {
3690
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3691
3692
        $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...
3693
            ->method('getBatchActions')
3694
            ->willReturn($batchActions);
3695
3696
        $datagrid = $this->createMock(DatagridInterface::class);
3697
3698
        $query = $this->createMock(ProxyQueryInterface::class);
3699
        $datagrid->expects($this->once())
3700
            ->method('getQuery')
3701
            ->willReturn($query);
3702
3703
        $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...
3704
            ->method('getDatagrid')
3705
            ->willReturn($datagrid);
3706
3707
        $modelManager = $this->createMock(ModelManagerInterface::class);
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('checkAccess')
3711
            ->with($this->equalTo('batchDelete'))
3712
            ->willReturn(true);
3713
3714
        $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...
3715
            ->method('getModelManager')
3716
            ->willReturn($modelManager);
3717
3718
        $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...
3719
            ->method('getClass')
3720
            ->willReturn('Foo');
3721
3722
        $modelManager->expects($this->once())
3723
            ->method('addIdentifiersToQuery')
3724
            ->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456']))
3725
            ->willReturn(true);
3726
3727
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
3728
3729
        $this->request->setMethod('POST');
3730
        $this->request->request->set('action', 'delete');
3731
        $this->request->request->set('idx', ['123', '456']);
3732
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3733
3734
        $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...
3735
3736
        $this->assertInstanceOf(RedirectResponse::class, $result);
3737
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3738
        $this->assertSame('list', $result->getTargetUrl());
3739
    }
3740
3741
    /**
3742
     * NEXT_MAJOR: Remove this legacy group.
3743
     *
3744
     * @group legacy
3745
     */
3746
    public function testBatchActionWithConfirmation(): void
3747
    {
3748
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'translation_domain' => 'FooBarBaz', 'ask_confirmation' => true]];
3749
3750
        $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...
3751
            ->method('getBatchActions')
3752
            ->willReturn($batchActions);
3753
3754
        $data = ['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false];
3755
3756
        $this->request->setMethod('POST');
3757
        $this->request->request->set('data', json_encode($data));
3758
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3759
3760
        $datagrid = $this->createMock(DatagridInterface::class);
3761
3762
        $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...
3763
            ->method('getDatagrid')
3764
            ->willReturn($datagrid);
3765
3766
        $form = $this->getMockBuilder(Form::class)
3767
            ->disableOriginalConstructor()
3768
            ->getMock();
3769
3770
        $form->expects($this->once())
3771
            ->method('createView')
3772
            ->willReturn($this->createMock(FormView::class));
3773
3774
        $datagrid->expects($this->once())
3775
            ->method('getForm')
3776
            ->willReturn($form);
3777
3778
        $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...
3779
3780
        $this->assertSame($this->admin, $this->parameters['admin']);
3781
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
3782
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3783
3784
        $this->assertSame('list', $this->parameters['action']);
3785
        $this->assertSame($datagrid, $this->parameters['datagrid']);
3786
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
3787
        $this->assertSame($data, $this->parameters['data']);
3788
        $this->assertSame('csrf-token-123_sonata.batch', $this->parameters['csrf_token']);
3789
        $this->assertSame('Foo Bar', $this->parameters['action_label']);
3790
3791
        $this->assertSame([], $this->session->getFlashBag()->all());
3792
        $this->assertSame('@SonataAdmin/CRUD/batch_confirmation.html.twig', $this->template);
3793
    }
3794
3795
    /**
3796
     * NEXT_MAJOR: Remove this legacy group.
3797
     *
3798
     * @group legacy
3799
     */
3800
    public function testBatchActionNonRelevantAction(): void
3801
    {
3802
        $controller = new BatchAdminController();
3803
        $controller->setContainer($this->container);
3804
3805
        $batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3806
3807
        $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...
3808
            ->method('getBatchActions')
3809
            ->willReturn($batchActions);
3810
3811
        $datagrid = $this->createMock(DatagridInterface::class);
3812
3813
        $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...
3814
            ->method('getDatagrid')
3815
            ->willReturn($datagrid);
3816
3817
        $this->expectTranslate('flash_batch_empty', [], 'SonataAdminBundle');
3818
3819
        $this->request->setMethod('POST');
3820
        $this->request->request->set('action', 'foo');
3821
        $this->request->request->set('idx', ['789']);
3822
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3823
3824
        $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...
3825
3826
        $this->assertInstanceOf(RedirectResponse::class, $result);
3827
        $this->assertSame(['flash_batch_empty'], $this->session->getFlashBag()->get('sonata_flash_info'));
3828
        $this->assertSame('list', $result->getTargetUrl());
3829
    }
3830
3831
    public function testBatchActionWithCustomConfirmationTemplate(): void
3832
    {
3833
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => true, 'template' => 'custom_template.html.twig']];
3834
3835
        $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...
3836
            ->method('getBatchActions')
3837
            ->willReturn($batchActions);
3838
3839
        $data = ['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false];
3840
3841
        $this->request->setMethod('POST');
3842
        $this->request->request->set('data', json_encode($data));
3843
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3844
3845
        $datagrid = $this->createMock(DatagridInterface::class);
3846
3847
        $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...
3848
            ->method('getDatagrid')
3849
            ->willReturn($datagrid);
3850
3851
        $form = $this->createMock(Form::class);
3852
3853
        $form->expects($this->once())
3854
            ->method('createView')
3855
            ->willReturn($this->createMock(FormView::class));
3856
3857
        $datagrid->expects($this->once())
3858
            ->method('getForm')
3859
            ->willReturn($form);
3860
3861
        $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...
3862
3863
        $this->assertSame('custom_template.html.twig', $this->template);
3864
    }
3865
3866
    /**
3867
     * NEXT_MAJOR: Remove this legacy group.
3868
     *
3869
     * @group legacy
3870
     */
3871
    public function testBatchActionNonRelevantAction2(): void
3872
    {
3873
        $controller = new BatchAdminController();
3874
        $controller->setContainer($this->container);
3875
3876
        $batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3877
3878
        $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...
3879
            ->method('getBatchActions')
3880
            ->willReturn($batchActions);
3881
3882
        $datagrid = $this->createMock(DatagridInterface::class);
3883
3884
        $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...
3885
            ->method('getDatagrid')
3886
            ->willReturn($datagrid);
3887
3888
        $this->expectTranslate('flash_foo_error', [], 'SonataAdminBundle');
3889
3890
        $this->request->setMethod('POST');
3891
        $this->request->request->set('action', 'foo');
3892
        $this->request->request->set('idx', ['999']);
3893
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3894
3895
        $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...
3896
3897
        $this->assertInstanceOf(RedirectResponse::class, $result);
3898
        $this->assertSame(['flash_foo_error'], $this->session->getFlashBag()->get('sonata_flash_info'));
3899
        $this->assertSame('list', $result->getTargetUrl());
3900
    }
3901
3902
    /**
3903
     * NEXT_MAJOR: Remove this legacy group.
3904
     *
3905
     * @group legacy
3906
     */
3907
    public function testBatchActionNoItems(): void
3908
    {
3909
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => true]];
3910
3911
        $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...
3912
            ->method('getBatchActions')
3913
            ->willReturn($batchActions);
3914
3915
        $datagrid = $this->createMock(DatagridInterface::class);
3916
3917
        $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...
3918
            ->method('getDatagrid')
3919
            ->willReturn($datagrid);
3920
3921
        $this->expectTranslate('flash_batch_empty', [], 'SonataAdminBundle');
3922
3923
        $this->request->setMethod('POST');
3924
        $this->request->request->set('action', 'delete');
3925
        $this->request->request->set('idx', []);
3926
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3927
3928
        $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...
3929
3930
        $this->assertInstanceOf(RedirectResponse::class, $result);
3931
        $this->assertSame(['flash_batch_empty'], $this->session->getFlashBag()->get('sonata_flash_info'));
3932
        $this->assertSame('list', $result->getTargetUrl());
3933
    }
3934
3935
    /**
3936
     * NEXT_MAJOR: Remove this legacy group.
3937
     *
3938
     * @group legacy
3939
     */
3940
    public function testBatchActionNoItemsEmptyQuery(): void
3941
    {
3942
        $controller = new BatchAdminController();
3943
        $controller->setContainer($this->container);
3944
3945
        $batchActions = ['bar' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3946
3947
        $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...
3948
            ->method('getBatchActions')
3949
            ->willReturn($batchActions);
3950
3951
        $datagrid = $this->createMock(DatagridInterface::class);
3952
3953
        $query = $this->createMock(ProxyQueryInterface::class);
3954
        $datagrid->expects($this->once())
3955
            ->method('getQuery')
3956
            ->willReturn($query);
3957
3958
        $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...
3959
            ->method('getDatagrid')
3960
            ->willReturn($datagrid);
3961
3962
        $modelManager = $this->createMock(ModelManagerInterface::class);
3963
3964
        $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...
3965
            ->method('getModelManager')
3966
            ->willReturn($modelManager);
3967
3968
        $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...
3969
            ->method('getClass')
3970
            ->willReturn('Foo');
3971
3972
        $this->request->setMethod('POST');
3973
        $this->request->request->set('action', 'bar');
3974
        $this->request->request->set('idx', []);
3975
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3976
3977
        $this->expectTranslate('flash_batch_no_elements_processed', [], 'SonataAdminBundle');
3978
        $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...
3979
3980
        $this->assertInstanceOf(Response::class, $result);
3981
        $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...
3982
    }
3983
3984
    /**
3985
     * NEXT_MAJOR: Remove this legacy group.
3986
     *
3987
     * @group legacy
3988
     */
3989
    public function testBatchActionWithRequesData(): void
3990
    {
3991
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3992
3993
        $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...
3994
            ->method('getBatchActions')
3995
            ->willReturn($batchActions);
3996
3997
        $datagrid = $this->createMock(DatagridInterface::class);
3998
3999
        $query = $this->createMock(ProxyQueryInterface::class);
4000
        $datagrid->expects($this->once())
4001
            ->method('getQuery')
4002
            ->willReturn($query);
4003
4004
        $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...
4005
            ->method('getDatagrid')
4006
            ->willReturn($datagrid);
4007
4008
        $modelManager = $this->createMock(ModelManagerInterface::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('checkAccess')
4012
            ->with($this->equalTo('batchDelete'))
4013
            ->willReturn(true);
4014
4015
        $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...
4016
            ->method('getModelManager')
4017
            ->willReturn($modelManager);
4018
4019
        $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...
4020
            ->method('getClass')
4021
            ->willReturn('Foo');
4022
4023
        $modelManager->expects($this->once())
4024
            ->method('addIdentifiersToQuery')
4025
            ->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456']))
4026
            ->willReturn(true);
4027
4028
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
4029
4030
        $this->request->setMethod('POST');
4031
        $this->request->request->set('data', json_encode(['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false]));
4032
        $this->request->request->set('foo', 'bar');
4033
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
4034
4035
        $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...
4036
4037
        $this->assertInstanceOf(RedirectResponse::class, $result);
4038
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
4039
        $this->assertSame('list', $result->getTargetUrl());
4040
        $this->assertSame('bar', $this->request->request->get('foo'));
4041
    }
4042
4043
    public function testItThrowsWhenCallingAnUndefinedMethod(): void
4044
    {
4045
        $this->expectException(
4046
            \LogicException::class
4047
        );
4048
        $this->expectExceptionMessage(
4049
            'Call to undefined method Sonata\AdminBundle\Controller\CRUDController::doesNotExist'
4050
        );
4051
        $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...
4052
    }
4053
4054
    /**
4055
     * @expectedDeprecation Method Sonata\AdminBundle\Controller\CRUDController::render has been renamed to Sonata\AdminBundle\Controller\CRUDController::renderWithExtraParams.
4056
     */
4057
    public function testRenderIsDeprecated(): void
4058
    {
4059
        $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...
4060
    }
4061
4062
    public function getCsrfProvider()
4063
    {
4064
        return $this->csrfProvider;
4065
    }
4066
4067
    public function getToStringValues()
4068
    {
4069
        return [
4070
            ['', ''],
4071
            ['Foo', 'Foo'],
4072
            ['&lt;a href=&quot;http://foo&quot;&gt;Bar&lt;/a&gt;', '<a href="http://foo">Bar</a>'],
4073
            ['&lt;&gt;&amp;&quot;&#039;abcdefghijklmnopqrstuvwxyz*-+.,?_()[]\/', '<>&"\'abcdefghijklmnopqrstuvwxyz*-+.,?_()[]\/'],
4074
        ];
4075
    }
4076
4077
    private function assertLoggerLogsModelManagerException($subject, string $method): void
4078
    {
4079
        $exception = new ModelManagerException(
4080
            $message = 'message',
4081
            1234,
4082
            new \Exception($previousExceptionMessage = 'very useful message')
4083
        );
4084
4085
        $subject->expects($this->once())
4086
            ->method($method)
4087
            ->willReturnCallback(static function () use ($exception): void {
4088
                throw $exception;
4089
            });
4090
4091
        $this->logger->expects($this->once())
4092
            ->method('error')
4093
            ->with($message, [
4094
                'exception' => $exception,
4095
                'previous_exception_message' => $previousExceptionMessage,
4096
            ]);
4097
    }
4098
4099
    private function expectTranslate(
4100
        string $id,
4101
        array $parameters = [],
4102
        ?string $domain = null,
4103
        ?string $locale = null
4104
    ): void {
4105
        $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...
4106
            ->method('trans')
4107
            ->with($this->equalTo($id), $this->equalTo($parameters), $this->equalTo($domain), $this->equalTo($locale))
4108
            ->willReturn($id);
4109
    }
4110
}
4111