Completed
Pull Request — master (#5391)
by Grégoire
03:40
created

testBatchActionMethodNotExist()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.584
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\AdminBundle\Tests\Controller;
15
16
use Exporter\Exporter;
17
use Exporter\Source\SourceIteratorInterface;
18
use Exporter\Writer\JsonWriter;
19
use PHPUnit\Framework\TestCase;
20
use Psr\Log\LoggerInterface;
21
use Sonata\AdminBundle\Admin\AdminInterface;
22
use Sonata\AdminBundle\Admin\FieldDescriptionCollection;
23
use Sonata\AdminBundle\Admin\Pool;
24
use Sonata\AdminBundle\Controller\CRUDController;
25
use Sonata\AdminBundle\Datagrid\DatagridInterface;
26
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
27
use Sonata\AdminBundle\Exception\LockException;
28
use Sonata\AdminBundle\Exception\ModelManagerException;
29
use Sonata\AdminBundle\Export\Exporter as SonataExporter;
30
use Sonata\AdminBundle\Model\AuditManager;
31
use Sonata\AdminBundle\Model\AuditReaderInterface;
32
use Sonata\AdminBundle\Model\ModelManagerInterface;
33
use Sonata\AdminBundle\Security\Acl\Permission\AdminPermissionMap;
34
use Sonata\AdminBundle\Security\Handler\AclSecurityHandler;
35
use Sonata\AdminBundle\Templating\TemplateRegistryInterface;
36
use Sonata\AdminBundle\Tests\Fixtures\Controller\BatchAdminController;
37
use Sonata\AdminBundle\Tests\Fixtures\Controller\PreCRUDController;
38
use Sonata\AdminBundle\Util\AdminObjectAclData;
39
use Sonata\AdminBundle\Util\AdminObjectAclManipulator;
40
use Symfony\Bridge\Twig\Extension\FormExtension;
41
use Symfony\Bridge\Twig\Form\TwigRenderer;
42
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
43
use Symfony\Bundle\FrameworkBundle\Templating\DelegatingEngine;
44
use Symfony\Component\DependencyInjection\ContainerInterface;
45
use Symfony\Component\Form\Form;
46
use Symfony\Component\Form\FormRenderer;
47
use Symfony\Component\Form\FormView;
48
use Symfony\Component\HttpFoundation\RedirectResponse;
49
use Symfony\Component\HttpFoundation\Request;
50
use Symfony\Component\HttpFoundation\RequestStack;
51
use Symfony\Component\HttpFoundation\Response;
52
use Symfony\Component\HttpFoundation\Session\Session;
53
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
54
use Symfony\Component\HttpFoundation\StreamedResponse;
55
use Symfony\Component\HttpKernel\Exception\HttpException;
56
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
57
use Symfony\Component\HttpKernel\KernelInterface;
58
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
59
use Symfony\Component\Security\Csrf\CsrfToken;
60
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
61
use Symfony\Component\Translation\TranslatorInterface;
62
63
/**
64
 * Test for CRUDController.
65
 *
66
 * @author Andrej Hudec <[email protected]>
67
 *
68
 * @group legacy
69
 */
70
class CRUDControllerTest extends TestCase
71
{
72
    /**
73
     * @var CRUDController
74
     */
75
    private $controller;
76
77
    /**
78
     * @var Request
79
     */
80
    private $request;
81
82
    /**
83
     * @var AdminInterface
84
     */
85
    private $admin;
86
87
    /**
88
     * @var TemplateRegistryInterface
89
     */
90
    private $templateRegistry;
91
92
    /**
93
     * @var Pool
94
     */
95
    private $pool;
96
97
    /**
98
     * @var array
99
     */
100
    private $parameters;
101
102
    /**
103
     * @var Session
104
     */
105
    private $session;
106
107
    /**
108
     * @var AuditManager
109
     */
110
    private $auditManager;
111
112
    /**
113
     * @var ContainerInterface
114
     */
115
    private $container;
116
117
    /**
118
     * @var AdminObjectAclManipulator
119
     */
120
    private $adminObjectAclManipulator;
121
122
    /**
123
     * @var string
124
     */
125
    private $template;
126
127
    /**
128
     * @var array
129
     */
130
    private $protectedTestedMethods;
131
132
    /**
133
     * @var CsrfTokenManagerInterface
134
     */
135
    private $csrfProvider;
136
137
    /**
138
     * @var KernelInterface
139
     */
140
    private $kernel;
141
142
    /**
143
     * @var TranslatorInterface
144
     */
145
    private $translator;
146
147
    /**
148
     * {@inheritdoc}
149
     */
150
    protected function setUp(): void
151
    {
152
        $this->container = $this->createMock(ContainerInterface::class);
153
154
        $this->request = new Request();
155
        $this->pool = new Pool($this->container, 'title', 'logo.png');
156
        $this->pool->setAdminServiceIds(['foo.admin']);
157
        $this->request->attributes->set('_sonata_admin', 'foo.admin');
158
        $this->admin = $this->getMockBuilder(AdminInterface::class)
159
            ->disableOriginalConstructor()
160
            ->getMock();
161
        $this->translator = $this->createMock(TranslatorInterface::class);
162
        $this->parameters = [];
163
        $this->template = '';
164
165
        $this->templateRegistry = $this->prophesize(TemplateRegistryInterface::class);
166
167
        $templating = $this->getMockBuilder(DelegatingEngine::class)
168
            ->setConstructorArgs([$this->container, []])
169
            ->getMock();
170
171
        $templatingRenderReturnCallback = $this->returnCallback(function (
172
            $view,
173
            array $parameters = [],
174
            Response $response = null
175
        ) {
176
            $this->template = $view;
177
178
            if (null === $response) {
179
                $response = new Response();
180
            }
181
182
            $this->parameters = $parameters;
183
184
            return $response;
185
        });
186
187
        // SF < 3.3.10 BC
188
        $templating->expects($this->any())
189
            ->method('renderResponse')
190
            ->will($templatingRenderReturnCallback);
191
192
        $templating->expects($this->any())
193
            ->method('render')
194
            ->will($templatingRenderReturnCallback);
195
196
        $this->session = new Session(new MockArraySessionStorage());
197
198
        $twig = $this->getMockBuilder(\Twig_Environment::class)
199
            ->disableOriginalConstructor()
200
            ->getMock();
201
202
        $twig->expects($this->any())
203
            ->method('getExtension')
204
            ->will($this->returnCallback(function ($name) {
205
                switch ($name) {
206
                    case FormExtension::class:
207
                        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...
208
                }
209
            }));
210
211
        $twig->expects($this->any())
212
            ->method('getRuntime')
213
            ->will($this->returnCallback(function ($name) {
214
                switch ($name) {
215
                    case TwigRenderer::class:
216
                        return $this->createMock(TwigRenderer::class);
217
                    case FormRenderer::class:
218
                        return $this->createMock(FormRenderer::class);
219
                }
220
            }));
221
222
        // NEXT_MAJOR : require sonata/exporter ^1.7 and remove conditional
223
        if (class_exists(Exporter::class)) {
224
            $exporter = new Exporter([new JsonWriter('/tmp/sonataadmin/export.json')]);
225
        } else {
226
            $exporter = $this->createMock(SonataExporter::class);
227
228
            $exporter->expects($this->any())
229
                ->method('getResponse')
230
                ->will($this->returnValue(new StreamedResponse()));
231
        }
232
233
        $this->auditManager = $this->getMockBuilder(AuditManager::class)
234
            ->disableOriginalConstructor()
235
            ->getMock();
236
237
        $this->adminObjectAclManipulator = $this->getMockBuilder(AdminObjectAclManipulator::class)
238
            ->disableOriginalConstructor()
239
            ->getMock();
240
241
        $this->csrfProvider = $this->getMockBuilder(CsrfTokenManagerInterface::class)
242
            ->getMock();
243
244
        $this->csrfProvider->expects($this->any())
245
            ->method('getToken')
246
            ->will($this->returnCallback(function ($intention) {
247
                return new CsrfToken($intention, 'csrf-token-123_'.$intention);
248
            }));
249
250
        $this->csrfProvider->expects($this->any())
251
            ->method('isTokenValid')
252
            ->will($this->returnCallback(function (CsrfToken $token) {
253
                if ($token->getValue() == 'csrf-token-123_'.$token->getId()) {
254
                    return true;
255
                }
256
257
                return false;
258
            }));
259
260
        $this->logger = $this->createMock(LoggerInterface::class);
261
262
        $requestStack = new RequestStack();
263
        $requestStack->push($this->request);
264
265
        $this->kernel = $this->createMock(KernelInterface::class);
266
267
        $this->container->expects($this->any())
268
            ->method('get')
269
            ->will($this->returnCallback(function ($id) use (
270
                $templating,
271
                $twig,
272
                $exporter,
273
                $requestStack
274
            ) {
275
                switch ($id) {
276
                    case 'sonata.admin.pool':
277
                        return $this->pool;
278
                    case 'request_stack':
279
                        return $requestStack;
280
                    case 'foo.admin':
281
                        return $this->admin;
282
                    case 'foo.admin.template_registry':
283
                        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...
284
                    case 'templating':
285
                        return $templating;
286
                    case 'twig':
287
                        return $twig;
288
                    case 'session':
289
                        return $this->session;
290
                    case 'sonata.admin.exporter':
291
                        return $exporter;
292
                    case 'sonata.admin.audit.manager':
293
                        return $this->auditManager;
294
                    case 'sonata.admin.object.manipulator.acl.admin':
295
                        return $this->adminObjectAclManipulator;
296
                    case 'security.csrf.token_manager':
297
                        return $this->csrfProvider;
298
                    case 'logger':
299
                        return $this->logger;
300
                    case 'kernel':
301
                        return $this->kernel;
302
                    case 'translator':
303
                        return $this->translator;
304
                }
305
            }));
306
307
        $this->container->expects($this->any())
308
            ->method('has')
309
            ->will($this->returnCallback(function ($id) {
310
                if ('security.csrf.token_manager' == $id && null !== $this->getCsrfProvider()) {
311
                    return true;
312
                }
313
314
                if ('logger' == $id) {
315
                    return true;
316
                }
317
318
                if ('session' == $id) {
319
                    return true;
320
                }
321
322
                if ('templating' == $id) {
323
                    return true;
324
                }
325
326
                if ('translator' == $id) {
327
                    return true;
328
                }
329
330
                return false;
331
            }));
332
333
        $this->container->expects($this->any())
334
            ->method('getParameter')
335
            ->will($this->returnCallback(function ($name) {
336
                switch ($name) {
337
                    case 'security.role_hierarchy.roles':
338
                       return ['ROLE_SUPER_ADMIN' => ['ROLE_USER', 'ROLE_SONATA_ADMIN', 'ROLE_ADMIN']];
339
                }
340
            }));
341
342
        $this->templateRegistry->getTemplate('ajax')->willReturn('@SonataAdmin/ajax_layout.html.twig');
343
        $this->templateRegistry->getTemplate('layout')->willReturn('@SonataAdmin/standard_layout.html.twig');
344
        $this->templateRegistry->getTemplate('show')->willReturn('@SonataAdmin/CRUD/show.html.twig');
345
        $this->templateRegistry->getTemplate('show_compare')->willReturn('@SonataAdmin/CRUD/show_compare.html.twig');
346
        $this->templateRegistry->getTemplate('edit')->willReturn('@SonataAdmin/CRUD/edit.html.twig');
347
        $this->templateRegistry->getTemplate('dashboard')->willReturn('@SonataAdmin/Core/dashboard.html.twig');
348
        $this->templateRegistry->getTemplate('search')->willReturn('@SonataAdmin/Core/search.html.twig');
349
        $this->templateRegistry->getTemplate('list')->willReturn('@SonataAdmin/CRUD/list.html.twig');
350
        $this->templateRegistry->getTemplate('preview')->willReturn('@SonataAdmin/CRUD/preview.html.twig');
351
        $this->templateRegistry->getTemplate('history')->willReturn('@SonataAdmin/CRUD/history.html.twig');
352
        $this->templateRegistry->getTemplate('acl')->willReturn('@SonataAdmin/CRUD/acl.html.twig');
353
        $this->templateRegistry->getTemplate('delete')->willReturn('@SonataAdmin/CRUD/delete.html.twig');
354
        $this->templateRegistry->getTemplate('batch')->willReturn('@SonataAdmin/CRUD/list__batch.html.twig');
355
        $this->templateRegistry->getTemplate('batch_confirmation')->willReturn('@SonataAdmin/CRUD/batch_confirmation.html.twig');
356
357
        // NEXT_MAJOR: Remove this call
358
        $this->admin->method('getTemplate')->willReturnMap([
359
            ['ajax', '@SonataAdmin/ajax_layout.html.twig'],
360
            ['layout', '@SonataAdmin/standard_layout.html.twig'],
361
            ['show', '@SonataAdmin/CRUD/show.html.twig'],
362
            ['show_compare', '@SonataAdmin/CRUD/show_compare.html.twig'],
363
            ['edit', '@SonataAdmin/CRUD/edit.html.twig'],
364
            ['dashboard', '@SonataAdmin/Core/dashboard.html.twig'],
365
            ['search', '@SonataAdmin/Core/search.html.twig'],
366
            ['list', '@SonataAdmin/CRUD/list.html.twig'],
367
            ['preview', '@SonataAdmin/CRUD/preview.html.twig'],
368
            ['history', '@SonataAdmin/CRUD/history.html.twig'],
369
            ['acl', '@SonataAdmin/CRUD/acl.html.twig'],
370
            ['delete', '@SonataAdmin/CRUD/delete.html.twig'],
371
            ['batch', '@SonataAdmin/CRUD/list__batch.html.twig'],
372
            ['batch_confirmation', '@SonataAdmin/CRUD/batch_confirmation.html.twig'],
373
        ]);
374
375
        $this->admin->expects($this->any())
376
            ->method('getIdParameter')
377
            ->will($this->returnValue('id'));
378
379
        $this->admin->expects($this->any())
380
            ->method('getAccessMapping')
381
            ->will($this->returnValue([]));
382
383
        $this->admin->expects($this->any())
384
            ->method('generateUrl')
385
            ->will(
386
                $this->returnCallback(
387
                    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...
388
                        $result = $name;
389
                        if (!empty($parameters)) {
390
                            $result .= '?'.http_build_query($parameters);
391
                        }
392
393
                        return $result;
394
                    }
395
                )
396
            );
397
398
        $this->admin->expects($this->any())
399
            ->method('generateObjectUrl')
400
            ->will(
401
                $this->returnCallback(
402
                    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...
403
                        $result = \get_class($object).'_'.$name;
404
                        if (!empty($parameters)) {
405
                            $result .= '?'.http_build_query($parameters);
406
                        }
407
408
                        return $result;
409
                    }
410
                )
411
            );
412
413
        $this->admin->expects($this->any())
414
            ->method('getCode')
415
            ->willReturn('foo.admin');
416
417
        $this->controller = new CRUDController();
418
        $this->controller->setContainer($this->container);
419
420
        // Make some methods public to test them
421
        $testedMethods = [
422
            'renderJson',
423
            'isXmlHttpRequest',
424
            'configure',
425
            'getBaseTemplate',
426
            'redirectTo',
427
            'addFlash',
428
        ];
429
        foreach ($testedMethods as $testedMethod) {
430
            // NEXT_MAJOR: Remove this check and only use CRUDController
431
            if (method_exists(CRUDController::class, $testedMethod)) {
432
                $method = new \ReflectionMethod(CRUDController::class, $testedMethod);
433
            } else {
434
                $method = new \ReflectionMethod(Controller::class, $testedMethod);
435
            }
436
437
            $method->setAccessible(true);
438
            $this->protectedTestedMethods[$testedMethod] = $method;
439
        }
440
    }
441
442
    public function testRenderJson1(): void
443
    {
444
        $data = ['example' => '123', 'foo' => 'bar'];
445
446
        $this->request->headers->set('Content-Type', 'application/x-www-form-urlencoded');
447
        $response = $this->protectedTestedMethods['renderJson']->invoke($this->controller, $data, 200, [], $this->request);
448
449
        $this->assertSame($response->headers->get('Content-Type'), 'application/json');
450
        $this->assertSame(json_encode($data), $response->getContent());
451
    }
452
453
    public function testRenderJson2(): void
454
    {
455
        $data = ['example' => '123', 'foo' => 'bar'];
456
457
        $this->request->headers->set('Content-Type', 'multipart/form-data');
458
        $response = $this->protectedTestedMethods['renderJson']->invoke($this->controller, $data, 200, [], $this->request);
459
460
        $this->assertSame($response->headers->get('Content-Type'), 'application/json');
461
        $this->assertSame(json_encode($data), $response->getContent());
462
    }
463
464
    public function testRenderJsonAjax(): void
465
    {
466
        $data = ['example' => '123', 'foo' => 'bar'];
467
468
        $this->request->attributes->set('_xml_http_request', true);
469
        $this->request->headers->set('Content-Type', 'multipart/form-data');
470
        $response = $this->protectedTestedMethods['renderJson']->invoke($this->controller, $data, 200, [], $this->request);
471
472
        $this->assertSame($response->headers->get('Content-Type'), 'application/json');
473
        $this->assertSame(json_encode($data), $response->getContent());
474
    }
475
476
    public function testIsXmlHttpRequest(): void
477
    {
478
        $this->assertFalse($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
479
480
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
481
482
        $this->assertTrue($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
483
484
        $this->request->headers->remove('X-Requested-With');
485
        $this->assertFalse($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
486
487
        $this->request->attributes->set('_xml_http_request', true);
488
        $this->assertTrue($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
489
    }
490
491
    public function testConfigure(): void
492
    {
493
        $uniqueId = '';
494
495
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
496
            ->method('setUniqid')
497
            ->will($this->returnCallback(function ($uniqid) use (&$uniqueId): void {
498
                $uniqueId = $uniqid;
499
            }));
500
501
        $this->request->query->set('uniqid', 123456);
502
        $this->protectedTestedMethods['configure']->invoke($this->controller);
503
504
        $this->assertSame(123456, $uniqueId);
505
        $this->assertAttributeSame($this->admin, 'admin', $this->controller);
506
    }
507
508
    public function testConfigureChild(): void
509
    {
510
        $uniqueId = '';
511
512
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
513
            ->method('setUniqid')
514
            ->will($this->returnCallback(function ($uniqid) use (&$uniqueId): void {
515
                $uniqueId = $uniqid;
516
            }));
517
518
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
519
            ->method('isChild')
520
            ->will($this->returnValue(true));
521
522
        $adminParent = $this->getMockBuilder(AdminInterface::class)
523
            ->disableOriginalConstructor()
524
            ->getMock();
525
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
526
            ->method('getParent')
527
            ->will($this->returnValue($adminParent));
528
529
        $this->request->query->set('uniqid', 123456);
530
        $this->protectedTestedMethods['configure']->invoke($this->controller);
531
532
        $this->assertSame(123456, $uniqueId);
533
        $this->assertAttributeInstanceOf(\get_class($adminParent), 'admin', $this->controller);
534
    }
535
536
    public function testConfigureWithException(): void
537
    {
538
        $this->expectException(
539
            \RuntimeException::class,
540
            'There is no `_sonata_admin` defined for the controller `Sonata\AdminBundle\Controller\CRUDController`'
541
        );
542
543
        $this->request->attributes->remove('_sonata_admin');
544
        $this->protectedTestedMethods['configure']->invoke($this->controller);
545
    }
546
547
    public function testConfigureWithException2(): void
548
    {
549
        $this->expectException(
550
            \InvalidArgumentException::class,
551
            'Found service "nonexistent.admin" is not a valid admin service'
552
        );
553
554
        $this->pool->setAdminServiceIds(['nonexistent.admin']);
555
        $this->request->attributes->set('_sonata_admin', 'nonexistent.admin');
556
        $this->protectedTestedMethods['configure']->invoke($this->controller);
557
    }
558
559
    public function testGetBaseTemplate(): void
560
    {
561
        $this->assertSame(
562
            '@SonataAdmin/standard_layout.html.twig',
563
            $this->protectedTestedMethods['getBaseTemplate']->invoke($this->controller, $this->request)
564
        );
565
566
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
567
        $this->assertSame(
568
            '@SonataAdmin/ajax_layout.html.twig',
569
            $this->protectedTestedMethods['getBaseTemplate']->invoke($this->controller, $this->request)
570
        );
571
572
        $this->request->headers->remove('X-Requested-With');
573
        $this->assertSame(
574
            '@SonataAdmin/standard_layout.html.twig',
575
            $this->protectedTestedMethods['getBaseTemplate']->invoke($this->controller, $this->request)
576
        );
577
578
        $this->request->attributes->set('_xml_http_request', true);
579
        $this->assertSame(
580
            '@SonataAdmin/ajax_layout.html.twig',
581
            $this->protectedTestedMethods['getBaseTemplate']->invoke($this->controller, $this->request)
582
        );
583
    }
584
585
    public function testRender(): void
586
    {
587
        $this->parameters = [];
588
        $this->assertInstanceOf(
589
            Response::class,
590
            $this->controller->renderWithExtraParams('@FooAdmin/foo.html.twig', [], null)
591
        );
592
        $this->assertSame($this->admin, $this->parameters['admin']);
593
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
594
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
595
        $this->assertSame('@FooAdmin/foo.html.twig', $this->template);
596
    }
597
598
    public function testRenderWithResponse(): void
599
    {
600
        $this->parameters = [];
601
        $response = $response = new Response();
602
        $response->headers->set('X-foo', 'bar');
603
        $responseResult = $this->controller->renderWithExtraParams('@FooAdmin/foo.html.twig', [], $response);
604
605
        $this->assertSame($response, $responseResult);
606
        $this->assertSame('bar', $responseResult->headers->get('X-foo'));
607
        $this->assertSame($this->admin, $this->parameters['admin']);
608
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
609
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
610
        $this->assertSame('@FooAdmin/foo.html.twig', $this->template);
611
    }
612
613
    public function testRenderCustomParams(): void
614
    {
615
        $this->parameters = [];
616
        $this->assertInstanceOf(
617
            Response::class,
618
            $this->controller->renderWithExtraParams(
619
                '@FooAdmin/foo.html.twig',
620
                ['foo' => 'bar'],
621
                null
622
            )
623
        );
624
        $this->assertSame($this->admin, $this->parameters['admin']);
625
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
626
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
627
        $this->assertSame('bar', $this->parameters['foo']);
628
        $this->assertSame('@FooAdmin/foo.html.twig', $this->template);
629
    }
630
631
    public function testRenderAjax(): void
632
    {
633
        $this->parameters = [];
634
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
635
        $this->assertInstanceOf(
636
            Response::class,
637
            $this->controller->renderWithExtraParams(
638
                '@FooAdmin/foo.html.twig',
639
                ['foo' => 'bar'],
640
                null
641
            )
642
        );
643
        $this->assertSame($this->admin, $this->parameters['admin']);
644
        $this->assertSame('@SonataAdmin/ajax_layout.html.twig', $this->parameters['base_template']);
645
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
646
        $this->assertSame('bar', $this->parameters['foo']);
647
        $this->assertSame('@FooAdmin/foo.html.twig', $this->template);
648
    }
649
650
    public function testListActionAccessDenied(): void
651
    {
652
        $this->expectException(AccessDeniedException::class);
653
654
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
655
            ->method('checkAccess')
656
            ->with($this->equalTo('list'))
657
            ->will($this->throwException(new AccessDeniedException()));
658
659
        $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...
660
    }
661
662
    public function testPreList(): void
663
    {
664
        $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\AdminInterface>.

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

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

Loading history...
665
            ->method('hasRoute')
666
            ->with($this->equalTo('list'))
667
            ->will($this->returnValue(true));
668
669
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
670
            ->method('checkAccess')
671
            ->with($this->equalTo('list'))
672
            ->will($this->returnValue(true));
673
674
        $controller = new PreCRUDController();
675
        $controller->setContainer($this->container);
676
677
        $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...
678
        $this->assertInstanceOf(Response::class, $response);
679
        $this->assertSame('preList called', $response->getContent());
680
    }
681
682
    public function testListAction(): void
683
    {
684
        $datagrid = $this->createMock(DatagridInterface::class);
685
686
        $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\AdminInterface>.

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

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

Loading history...
687
            ->method('hasRoute')
688
            ->with($this->equalTo('list'))
689
            ->will($this->returnValue(true));
690
691
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
692
            ->method('checkAccess')
693
            ->with($this->equalTo('list'))
694
            ->will($this->returnValue(true));
695
696
        $form = $this->getMockBuilder(Form::class)
697
            ->disableOriginalConstructor()
698
            ->getMock();
699
700
        $form->expects($this->once())
701
            ->method('createView')
702
            ->will($this->returnValue($this->createMock(FormView::class)));
703
704
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
705
            ->method('getDatagrid')
706
            ->will($this->returnValue($datagrid));
707
708
        $datagrid->expects($this->once())
709
            ->method('getForm')
710
            ->will($this->returnValue($form));
711
712
        $this->parameters = [];
713
        $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...
714
715
        $this->assertSame($this->admin, $this->parameters['admin']);
716
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
717
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
718
719
        $this->assertSame('list', $this->parameters['action']);
720
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
721
        $this->assertInstanceOf(DatagridInterface::class, $this->parameters['datagrid']);
722
        $this->assertSame('csrf-token-123_sonata.batch', $this->parameters['csrf_token']);
723
        $this->assertSame([], $this->session->getFlashBag()->all());
724
        $this->assertSame('@SonataAdmin/CRUD/list.html.twig', $this->template);
725
    }
726
727
    public function testBatchActionDeleteAccessDenied(): void
728
    {
729
        $this->expectException(AccessDeniedException::class);
730
731
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
732
            ->method('checkAccess')
733
            ->with($this->equalTo('batchDelete'))
734
            ->will($this->throwException(new AccessDeniedException()));
735
736
        $this->controller->batchActionDelete($this->createMock(ProxyQueryInterface::class));
737
    }
738
739
    public function testBatchActionDelete(): void
740
    {
741
        $modelManager = $this->createMock(ModelManagerInterface::class);
742
743
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
744
            ->method('checkAccess')
745
            ->with($this->equalTo('batchDelete'))
746
            ->will($this->returnValue(true));
747
748
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
749
            ->method('getModelManager')
750
            ->will($this->returnValue($modelManager));
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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getFilterParameters')
754
            ->will($this->returnValue(['foo' => 'bar']));
755
756
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
757
758
        $result = $this->controller->batchActionDelete($this->createMock(ProxyQueryInterface::class));
759
760
        $this->assertInstanceOf(RedirectResponse::class, $result);
761
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
762
        $this->assertSame('list?filter%5Bfoo%5D=bar', $result->getTargetUrl());
763
    }
764
765
    public function testBatchActionDeleteWithModelManagerException(): void
766
    {
767
        $modelManager = $this->createMock(ModelManagerInterface::class);
768
        $this->assertLoggerLogsModelManagerException($modelManager, 'batchDelete');
769
770
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
771
            ->method('getModelManager')
772
            ->will($this->returnValue($modelManager));
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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getFilterParameters')
776
            ->will($this->returnValue(['foo' => 'bar']));
777
778
        $this->expectTranslate('flash_batch_delete_error', [], 'SonataAdminBundle');
779
780
        $result = $this->controller->batchActionDelete($this->createMock(ProxyQueryInterface::class));
781
782
        $this->assertInstanceOf(RedirectResponse::class, $result);
783
        $this->assertSame(['flash_batch_delete_error'], $this->session->getFlashBag()->get('sonata_flash_error'));
784
        $this->assertSame('list?filter%5Bfoo%5D=bar', $result->getTargetUrl());
785
    }
786
787
    public function testBatchActionDeleteWithModelManagerExceptionInDebugMode(): void
788
    {
789
        $modelManager = $this->createMock(ModelManagerInterface::class);
790
        $this->expectException(ModelManagerException::class);
791
792
        $modelManager->expects($this->once())
793
            ->method('batchDelete')
794
            ->will($this->returnCallback(function (): void {
795
                throw new ModelManagerException();
796
            }));
797
798
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
799
            ->method('getModelManager')
800
            ->will($this->returnValue($modelManager));
801
802
        $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...
803
            ->method('isDebug')
804
            ->will($this->returnValue(true));
805
806
        $this->controller->batchActionDelete($this->createMock(ProxyQueryInterface::class));
807
    }
808
809
    public function testShowActionNotFoundException(): void
810
    {
811
        $this->expectException(NotFoundHttpException::class);
812
813
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
814
            ->method('getObject')
815
            ->will($this->returnValue(false));
816
817
        $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...
818
    }
819
820
    public function testShowActionAccessDenied(): void
821
    {
822
        $this->expectException(AccessDeniedException::class);
823
824
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
825
            ->method('getObject')
826
            ->will($this->returnValue(new \stdClass()));
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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('checkAccess')
830
            ->with($this->equalTo('show'))
831
            ->will($this->throwException(new AccessDeniedException()));
832
833
        $this->controller->showAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::showAction() has too many arguments starting with $this->request.

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

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

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

Loading history...
834
    }
835
836
    /**
837
     * @group legacy
838
     * @expectedDeprecation Calling this method without implementing "configureShowFields" is not supported since 3.x and will no longer be possible in 4.0
839
     */
840
    public function testShowActionDeprecation(): void
841
    {
842
        $object = new \stdClass();
843
844
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
845
            ->method('getObject')
846
            ->will($this->returnValue($object));
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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('checkAccess')
850
            ->with($this->equalTo('show'))
851
            ->will($this->returnValue(true));
852
853
        $show = $this->createMock(FieldDescriptionCollection::class);
854
855
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
856
            ->method('getShow')
857
            ->will($this->returnValue($show));
858
859
        $show->expects($this->once())
860
            ->method('getElements')
861
            ->willReturn([]);
862
863
        $show->expects($this->once())
864
            ->method('count')
865
            ->willReturn(0);
866
867
        $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...
868
    }
869
870
    public function testPreShow(): void
871
    {
872
        $object = new \stdClass();
873
        $object->foo = 123456;
874
875
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
876
            ->method('getObject')
877
            ->will($this->returnValue($object));
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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('checkAccess')
881
            ->with($this->equalTo('show'))
882
            ->will($this->returnValue(true));
883
884
        $controller = new PreCRUDController();
885
        $controller->setContainer($this->container);
886
887
        $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...
888
        $this->assertInstanceOf(Response::class, $response);
889
        $this->assertSame('preShow called: 123456', $response->getContent());
890
    }
891
892
    public function testShowAction(): void
893
    {
894
        $object = new \stdClass();
895
896
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
897
            ->method('getObject')
898
            ->will($this->returnValue($object));
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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('checkAccess')
902
            ->with($this->equalTo('show'))
903
            ->will($this->returnValue(true));
904
905
        $show = $this->createMock(FieldDescriptionCollection::class);
906
907
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
908
            ->method('getShow')
909
            ->will($this->returnValue($show));
910
911
        $show->expects($this->once())
912
            ->method('getElements')
913
            ->willReturn(['field' => 'fielddata']);
914
915
        $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...
916
917
        $this->assertSame($this->admin, $this->parameters['admin']);
918
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
919
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
920
921
        $this->assertSame('show', $this->parameters['action']);
922
        $this->assertInstanceOf(FieldDescriptionCollection::class, $this->parameters['elements']);
923
        $this->assertSame($object, $this->parameters['object']);
924
925
        $this->assertSame([], $this->session->getFlashBag()->all());
926
        $this->assertSame('@SonataAdmin/CRUD/show.html.twig', $this->template);
927
    }
928
929
    /**
930
     * @dataProvider getRedirectToTests
931
     */
932
    public function testRedirectTo($expected, $route, $queryParams, $hasActiveSubclass): void
933
    {
934
        $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\AdminInterface>.

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

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

Loading history...
935
            ->method('hasActiveSubclass')
936
            ->will($this->returnValue($hasActiveSubclass));
937
938
        $object = new \stdClass();
939
940
        foreach ($queryParams as $key => $value) {
941
            $this->request->query->set($key, $value);
942
        }
943
944
        $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\AdminInterface>.

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

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

Loading history...
945
            ->method('hasRoute')
946
            ->with($this->equalTo($route))
947
            ->will($this->returnValue(true));
948
949
        $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\AdminInterface>.

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

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

Loading history...
950
            ->method('hasAccess')
951
            ->with($this->equalTo($route))
952
            ->will($this->returnValue(true));
953
954
        $response = $this->protectedTestedMethods['redirectTo']->invoke($this->controller, $object, $this->request);
955
        $this->assertInstanceOf(RedirectResponse::class, $response);
956
        $this->assertSame($expected, $response->getTargetUrl());
957
    }
958
959
    public function testRedirectToWithObject(): void
960
    {
961
        $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\AdminInterface>.

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

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

Loading history...
962
            ->method('hasActiveSubclass')
963
            ->will($this->returnValue(false));
964
965
        $object = new \stdClass();
966
967
        $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\AdminInterface>.

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

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

Loading history...
968
            ->method('hasRoute')
969
            ->with($this->equalTo('edit'))
970
            ->will($this->returnValue(true));
971
972
        $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\AdminInterface>.

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

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

Loading history...
973
            ->method('hasAccess')
974
            ->with($this->equalTo('edit'), $object)
975
            ->will($this->returnValue(false));
976
977
        $response = $this->protectedTestedMethods['redirectTo']->invoke($this->controller, $object, $this->request);
978
        $this->assertInstanceOf(RedirectResponse::class, $response);
979
        $this->assertSame('list', $response->getTargetUrl());
980
    }
981
982
    public function getRedirectToTests()
983
    {
984
        return [
985
            ['stdClass_edit', 'edit', [], false],
986
            ['list', 'list', ['btn_update_and_list' => true], false],
987
            ['list', 'list', ['btn_create_and_list' => true], false],
988
            ['create', 'create', ['btn_create_and_create' => true], false],
989
            ['create?subclass=foo', 'create', ['btn_create_and_create' => true, 'subclass' => 'foo'], true],
990
        ];
991
    }
992
993
    public function testDeleteActionNotFoundException(): void
994
    {
995
        $this->expectException(NotFoundHttpException::class);
996
997
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
998
            ->method('getObject')
999
            ->will($this->returnValue(false));
1000
1001
        $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...
1002
    }
1003
1004
    public function testDeleteActionAccessDenied(): void
1005
    {
1006
        $this->expectException(AccessDeniedException::class);
1007
1008
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1009
            ->method('getObject')
1010
            ->will($this->returnValue(new \stdClass()));
1011
1012
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1013
            ->method('checkAccess')
1014
            ->with($this->equalTo('delete'))
1015
            ->will($this->throwException(new AccessDeniedException()));
1016
1017
        $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...
1018
    }
1019
1020
    public function testPreDelete(): void
1021
    {
1022
        $object = new \stdClass();
1023
        $object->foo = 123456;
1024
1025
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1026
            ->method('getObject')
1027
            ->will($this->returnValue($object));
1028
1029
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1030
            ->method('checkAccess')
1031
            ->with($this->equalTo('delete'))
1032
            ->will($this->returnValue(true));
1033
1034
        $controller = new PreCRUDController();
1035
        $controller->setContainer($this->container);
1036
1037
        $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...
1038
        $this->assertInstanceOf(Response::class, $response);
1039
        $this->assertSame('preDelete called: 123456', $response->getContent());
1040
    }
1041
1042
    public function testDeleteAction(): void
1043
    {
1044
        $object = new \stdClass();
1045
1046
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1047
            ->method('getObject')
1048
            ->will($this->returnValue($object));
1049
1050
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1051
            ->method('checkAccess')
1052
            ->with($this->equalTo('delete'))
1053
            ->will($this->returnValue(true));
1054
1055
        $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...
1056
1057
        $this->assertSame($this->admin, $this->parameters['admin']);
1058
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1059
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1060
1061
        $this->assertSame('delete', $this->parameters['action']);
1062
        $this->assertSame($object, $this->parameters['object']);
1063
        $this->assertSame('csrf-token-123_sonata.delete', $this->parameters['csrf_token']);
1064
1065
        $this->assertSame([], $this->session->getFlashBag()->all());
1066
        $this->assertSame('@SonataAdmin/CRUD/delete.html.twig', $this->template);
1067
    }
1068
1069
    public function testDeleteActionNoCsrfToken(): void
1070
    {
1071
        $this->csrfProvider = null;
1072
1073
        $object = new \stdClass();
1074
1075
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1076
            ->method('getObject')
1077
            ->will($this->returnValue($object));
1078
1079
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1080
            ->method('checkAccess')
1081
            ->with($this->equalTo('delete'))
1082
            ->will($this->returnValue(true));
1083
1084
        $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...
1085
1086
        $this->assertSame($this->admin, $this->parameters['admin']);
1087
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1088
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1089
1090
        $this->assertSame('delete', $this->parameters['action']);
1091
        $this->assertSame($object, $this->parameters['object']);
1092
        $this->assertFalse($this->parameters['csrf_token']);
1093
1094
        $this->assertSame([], $this->session->getFlashBag()->all());
1095
        $this->assertSame('@SonataAdmin/CRUD/delete.html.twig', $this->template);
1096
    }
1097
1098
    public function testDeleteActionAjaxSuccess1(): void
1099
    {
1100
        $object = new \stdClass();
1101
1102
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1103
            ->method('getObject')
1104
            ->will($this->returnValue($object));
1105
1106
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1107
            ->method('checkAccess')
1108
            ->with($this->equalTo('delete'))
1109
            ->will($this->returnValue(true));
1110
1111
        $this->request->setMethod('DELETE');
1112
1113
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1114
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1115
1116
        $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...
1117
1118
        $this->assertInstanceOf(Response::class, $response);
1119
        $this->assertSame(json_encode(['result' => 'ok']), $response->getContent());
1120
        $this->assertSame([], $this->session->getFlashBag()->all());
1121
    }
1122
1123
    public function testDeleteActionAjaxSuccess2(): void
1124
    {
1125
        $object = new \stdClass();
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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getObject')
1129
            ->will($this->returnValue($object));
1130
1131
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1132
            ->method('checkAccess')
1133
            ->with($this->equalTo('delete'))
1134
            ->will($this->returnValue(true));
1135
1136
        $this->request->setMethod('POST');
1137
        $this->request->request->set('_method', 'DELETE');
1138
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1139
1140
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1141
1142
        $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...
1143
1144
        $this->assertInstanceOf(Response::class, $response);
1145
        $this->assertSame(json_encode(['result' => 'ok']), $response->getContent());
1146
        $this->assertSame([], $this->session->getFlashBag()->all());
1147
    }
1148
1149
    public function testDeleteActionAjaxError(): void
1150
    {
1151
        $object = new \stdClass();
1152
1153
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1154
            ->method('getObject')
1155
            ->will($this->returnValue($object));
1156
1157
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1158
            ->method('checkAccess')
1159
            ->with($this->equalTo('delete'))
1160
            ->will($this->returnValue(true));
1161
1162
        $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\AdminInterface>.

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

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

Loading history...
1163
            ->method('getClass')
1164
            ->will($this->returnValue('stdClass'));
1165
1166
        $this->assertLoggerLogsModelManagerException($this->admin, 'delete');
1167
1168
        $this->request->setMethod('DELETE');
1169
1170
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1171
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1172
1173
        $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...
1174
1175
        $this->assertInstanceOf(Response::class, $response);
1176
        $this->assertSame(json_encode(['result' => 'error']), $response->getContent());
1177
        $this->assertSame([], $this->session->getFlashBag()->all());
1178
    }
1179
1180
    public function testDeleteActionWithModelManagerExceptionInDebugMode(): void
1181
    {
1182
        $this->expectException(ModelManagerException::class);
1183
1184
        $object = new \stdClass();
1185
1186
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1187
            ->method('getObject')
1188
            ->will($this->returnValue($object));
1189
1190
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1191
            ->method('checkAccess')
1192
            ->with($this->equalTo('delete'))
1193
            ->will($this->returnValue(true));
1194
1195
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1196
            ->method('delete')
1197
            ->will($this->returnCallback(function (): void {
1198
                throw new ModelManagerException();
1199
            }));
1200
1201
        $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...
1202
            ->method('isDebug')
1203
            ->will($this->returnValue(true));
1204
1205
        $this->request->setMethod('DELETE');
1206
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1207
1208
        $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...
1209
    }
1210
1211
    /**
1212
     * @dataProvider getToStringValues
1213
     */
1214
    public function testDeleteActionSuccess1($expectedToStringValue, $toStringValue): 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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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
            ->will($this->returnValue($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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('toString')
1224
            ->with($this->equalTo($object))
1225
            ->will($this->returnValue($toStringValue));
1226
1227
        $this->expectTranslate('flash_delete_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1228
1229
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1230
            ->method('checkAccess')
1231
            ->with($this->equalTo('delete'))
1232
            ->will($this->returnValue(true));
1233
1234
        $this->request->setMethod('DELETE');
1235
1236
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
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(RedirectResponse::class, $response);
1241
        $this->assertSame(['flash_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1242
        $this->assertSame('list', $response->getTargetUrl());
1243
    }
1244
1245
    /**
1246
     * @dataProvider getToStringValues
1247
     */
1248
    public function testDeleteActionSuccess2($expectedToStringValue, $toStringValue): void
1249
    {
1250
        $object = new \stdClass();
1251
1252
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1253
            ->method('getObject')
1254
            ->will($this->returnValue($object));
1255
1256
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1257
            ->method('checkAccess')
1258
            ->with($this->equalTo('delete'))
1259
            ->will($this->returnValue(true));
1260
1261
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1262
            ->method('toString')
1263
            ->with($this->equalTo($object))
1264
            ->will($this->returnValue($toStringValue));
1265
1266
        $this->expectTranslate('flash_delete_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1267
1268
        $this->request->setMethod('POST');
1269
        $this->request->request->set('_method', 'DELETE');
1270
1271
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1272
1273
        $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...
1274
1275
        $this->assertInstanceOf(RedirectResponse::class, $response);
1276
        $this->assertSame(['flash_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1277
        $this->assertSame('list', $response->getTargetUrl());
1278
    }
1279
1280
    /**
1281
     * @dataProvider getToStringValues
1282
     */
1283
    public function testDeleteActionSuccessNoCsrfTokenProvider($expectedToStringValue, $toStringValue): void
1284
    {
1285
        $this->csrfProvider = null;
1286
1287
        $object = new \stdClass();
1288
1289
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1290
            ->method('getObject')
1291
            ->will($this->returnValue($object));
1292
1293
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1294
            ->method('checkAccess')
1295
            ->with($this->equalTo('delete'))
1296
            ->will($this->returnValue(true));
1297
1298
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1299
            ->method('toString')
1300
            ->with($this->equalTo($object))
1301
            ->will($this->returnValue($toStringValue));
1302
1303
        $this->expectTranslate('flash_delete_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1304
1305
        $this->request->setMethod('POST');
1306
        $this->request->request->set('_method', 'DELETE');
1307
1308
        $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...
1309
1310
        $this->assertInstanceOf(RedirectResponse::class, $response);
1311
        $this->assertSame(['flash_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1312
        $this->assertSame('list', $response->getTargetUrl());
1313
    }
1314
1315
    public function testDeleteActionWrongRequestMethod(): void
1316
    {
1317
        $object = new \stdClass();
1318
1319
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1320
            ->method('getObject')
1321
            ->will($this->returnValue($object));
1322
1323
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1324
            ->method('checkAccess')
1325
            ->with($this->equalTo('delete'))
1326
            ->will($this->returnValue(true));
1327
1328
        //without POST request parameter "_method" should not be used as real REST method
1329
        $this->request->query->set('_method', 'DELETE');
1330
1331
        $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...
1332
1333
        $this->assertSame($this->admin, $this->parameters['admin']);
1334
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1335
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1336
1337
        $this->assertSame('delete', $this->parameters['action']);
1338
        $this->assertSame($object, $this->parameters['object']);
1339
        $this->assertSame('csrf-token-123_sonata.delete', $this->parameters['csrf_token']);
1340
1341
        $this->assertSame([], $this->session->getFlashBag()->all());
1342
        $this->assertSame('@SonataAdmin/CRUD/delete.html.twig', $this->template);
1343
    }
1344
1345
    /**
1346
     * @dataProvider getToStringValues
1347
     */
1348
    public function testDeleteActionError($expectedToStringValue, $toStringValue): void
1349
    {
1350
        $object = new \stdClass();
1351
1352
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1353
            ->method('getObject')
1354
            ->will($this->returnValue($object));
1355
1356
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1357
            ->method('checkAccess')
1358
            ->with($this->equalTo('delete'))
1359
            ->will($this->returnValue(true));
1360
1361
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1362
            ->method('toString')
1363
            ->with($this->equalTo($object))
1364
            ->will($this->returnValue($toStringValue));
1365
1366
        $this->expectTranslate('flash_delete_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1367
1368
        $this->assertLoggerLogsModelManagerException($this->admin, 'delete');
1369
1370
        $this->request->setMethod('DELETE');
1371
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.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_error'], $this->session->getFlashBag()->get('sonata_flash_error'));
1377
        $this->assertSame('list', $response->getTargetUrl());
1378
    }
1379
1380
    public function testDeleteActionInvalidCsrfToken(): 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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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
            ->will($this->returnValue($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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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
            ->will($this->returnValue(true));
1392
1393
        $this->request->setMethod('POST');
1394
        $this->request->request->set('_method', 'DELETE');
1395
        $this->request->request->set('_sonata_csrf_token', 'CSRF-INVALID');
1396
1397
        try {
1398
            $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...
1399
        } catch (HttpException $e) {
1400
            $this->assertSame('The csrf token is not valid, CSRF attack?', $e->getMessage());
1401
            $this->assertSame(400, $e->getStatusCode());
1402
        }
1403
    }
1404
1405
    public function testEditActionNotFoundException(): void
1406
    {
1407
        $this->expectException(NotFoundHttpException::class);
1408
1409
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1410
            ->method('getObject')
1411
            ->will($this->returnValue(false));
1412
1413
        $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...
1414
    }
1415
1416
    public function testEditActionRuntimeException(): void
1417
    {
1418
        $this->expectException(\RuntimeException::class);
1419
1420
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1421
            ->method('getObject')
1422
            ->will($this->returnValue(new \stdClass()));
1423
1424
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1425
            ->method('checkAccess')
1426
            ->with($this->equalTo('edit'))
1427
            ->will($this->returnValue(true));
1428
1429
        $form = $this->createMock(Form::class);
1430
1431
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1432
            ->method('getForm')
1433
            ->will($this->returnValue($form));
1434
1435
        $form->expects($this->once())
1436
            ->method('all')
1437
            ->willReturn([]);
1438
1439
        $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...
1440
    }
1441
1442
    public function testEditActionAccessDenied(): void
1443
    {
1444
        $this->expectException(AccessDeniedException::class);
1445
1446
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1447
            ->method('getObject')
1448
            ->will($this->returnValue(new \stdClass()));
1449
1450
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1451
            ->method('checkAccess')
1452
            ->with($this->equalTo('edit'))
1453
            ->will($this->throwException(new AccessDeniedException()));
1454
1455
        $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...
1456
    }
1457
1458
    public function testPreEdit(): void
1459
    {
1460
        $object = new \stdClass();
1461
        $object->foo = 123456;
1462
1463
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1464
            ->method('getObject')
1465
            ->will($this->returnValue($object));
1466
1467
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1468
            ->method('checkAccess')
1469
            ->with($this->equalTo('edit'))
1470
            ->will($this->returnValue(true));
1471
1472
        $controller = new PreCRUDController();
1473
        $controller->setContainer($this->container);
1474
1475
        $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...
1476
        $this->assertInstanceOf(Response::class, $response);
1477
        $this->assertSame('preEdit called: 123456', $response->getContent());
1478
    }
1479
1480
    public function testEditAction(): void
1481
    {
1482
        $object = new \stdClass();
1483
1484
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1485
            ->method('getObject')
1486
            ->will($this->returnValue($object));
1487
1488
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1489
            ->method('checkAccess')
1490
            ->with($this->equalTo('edit'))
1491
            ->will($this->returnValue(true));
1492
1493
        $form = $this->createMock(Form::class);
1494
1495
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1496
            ->method('getForm')
1497
            ->will($this->returnValue($form));
1498
1499
        $formView = $this->createMock(FormView::class);
1500
1501
        $form->expects($this->any())
1502
            ->method('createView')
1503
            ->will($this->returnValue($formView));
1504
1505
        $form->expects($this->once())
1506
            ->method('all')
1507
            ->willReturn(['field' => 'fielddata']);
1508
1509
        $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...
1510
1511
        $this->assertSame($this->admin, $this->parameters['admin']);
1512
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1513
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1514
1515
        $this->assertSame('edit', $this->parameters['action']);
1516
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1517
        $this->assertSame($object, $this->parameters['object']);
1518
        $this->assertSame([], $this->session->getFlashBag()->all());
1519
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1520
    }
1521
1522
    /**
1523
     * @dataProvider getToStringValues
1524
     */
1525
    public function testEditActionSuccess($expectedToStringValue, $toStringValue): void
1526
    {
1527
        $object = new \stdClass();
1528
1529
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1530
            ->method('getObject')
1531
            ->will($this->returnValue($object));
1532
1533
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1534
            ->method('update')
1535
            ->will($this->returnArgument(0));
1536
1537
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1538
            ->method('checkAccess')
1539
            ->with($this->equalTo('edit'));
1540
1541
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1542
            ->method('hasRoute')
1543
            ->with($this->equalTo('edit'))
1544
            ->will($this->returnValue(true));
1545
1546
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1547
            ->method('hasAccess')
1548
            ->with($this->equalTo('edit'))
1549
            ->will($this->returnValue(true));
1550
1551
        $form = $this->createMock(Form::class);
1552
1553
        $form->expects($this->once())
1554
            ->method('getData')
1555
            ->will($this->returnValue($object));
1556
1557
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1558
            ->method('getForm')
1559
            ->will($this->returnValue($form));
1560
1561
        $form->expects($this->once())
1562
            ->method('isSubmitted')
1563
            ->will($this->returnValue(true));
1564
1565
        $form->expects($this->once())
1566
            ->method('isValid')
1567
            ->will($this->returnValue(true));
1568
1569
        $form->expects($this->once())
1570
            ->method('all')
1571
            ->willReturn(['field' => 'fielddata']);
1572
1573
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1574
            ->method('toString')
1575
            ->with($this->equalTo($object))
1576
            ->will($this->returnValue($toStringValue));
1577
1578
        $this->expectTranslate('flash_edit_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1579
1580
        $this->request->setMethod('POST');
1581
1582
        $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...
1583
1584
        $this->assertInstanceOf(RedirectResponse::class, $response);
1585
        $this->assertSame(['flash_edit_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1586
        $this->assertSame('stdClass_edit', $response->getTargetUrl());
1587
    }
1588
1589
    /**
1590
     * @dataProvider getToStringValues
1591
     */
1592
    public function testEditActionError($expectedToStringValue, $toStringValue): void
1593
    {
1594
        $object = new \stdClass();
1595
1596
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1597
            ->method('getObject')
1598
            ->will($this->returnValue($object));
1599
1600
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1601
            ->method('checkAccess')
1602
            ->with($this->equalTo('edit'))
1603
            ->will($this->returnValue(true));
1604
1605
        $form = $this->createMock(Form::class);
1606
1607
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1608
            ->method('getForm')
1609
            ->will($this->returnValue($form));
1610
1611
        $form->expects($this->once())
1612
            ->method('isSubmitted')
1613
            ->will($this->returnValue(true));
1614
1615
        $form->expects($this->once())
1616
            ->method('isValid')
1617
            ->will($this->returnValue(false));
1618
1619
        $form->expects($this->once())
1620
            ->method('all')
1621
            ->willReturn(['field' => 'fielddata']);
1622
1623
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1624
            ->method('toString')
1625
            ->with($this->equalTo($object))
1626
            ->will($this->returnValue($toStringValue));
1627
1628
        $this->expectTranslate('flash_edit_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1629
1630
        $this->request->setMethod('POST');
1631
1632
        $formView = $this->createMock(FormView::class);
1633
1634
        $form->expects($this->any())
1635
            ->method('createView')
1636
            ->will($this->returnValue($formView));
1637
1638
        $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...
1639
1640
        $this->assertSame($this->admin, $this->parameters['admin']);
1641
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1642
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1643
1644
        $this->assertSame('edit', $this->parameters['action']);
1645
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1646
        $this->assertSame($object, $this->parameters['object']);
1647
1648
        $this->assertSame(['sonata_flash_error' => ['flash_edit_error']], $this->session->getFlashBag()->all());
1649
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1650
    }
1651
1652
    public function testEditActionAjaxSuccess(): void
1653
    {
1654
        $object = new \stdClass();
1655
1656
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1657
            ->method('getObject')
1658
            ->will($this->returnValue($object));
1659
1660
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1661
            ->method('update')
1662
            ->will($this->returnArgument(0));
1663
1664
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1665
            ->method('checkAccess')
1666
            ->with($this->equalTo('edit'))
1667
            ->will($this->returnValue(true));
1668
1669
        $form = $this->createMock(Form::class);
1670
1671
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1672
            ->method('getForm')
1673
            ->will($this->returnValue($form));
1674
1675
        $form->expects($this->once())
1676
            ->method('isSubmitted')
1677
            ->will($this->returnValue(true));
1678
1679
        $form->expects($this->once())
1680
            ->method('isValid')
1681
            ->will($this->returnValue(true));
1682
1683
        $form->expects($this->once())
1684
            ->method('getData')
1685
            ->will($this->returnValue($object));
1686
1687
        $form->expects($this->once())
1688
            ->method('all')
1689
            ->willReturn(['field' => 'fielddata']);
1690
1691
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1692
            ->method('getNormalizedIdentifier')
1693
            ->with($this->equalTo($object))
1694
            ->will($this->returnValue('foo_normalized'));
1695
1696
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1697
            ->method('toString')
1698
            ->will($this->returnValue('foo'));
1699
1700
        $this->request->setMethod('POST');
1701
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1702
1703
        $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...
1704
1705
        $this->assertInstanceOf(Response::class, $response);
1706
        $this->assertSame(json_encode(['result' => 'ok', 'objectId' => 'foo_normalized', 'objectName' => 'foo']), $response->getContent());
1707
        $this->assertSame([], $this->session->getFlashBag()->all());
1708
    }
1709
1710
    public function testEditActionAjaxError(): void
1711
    {
1712
        $object = new \stdClass();
1713
1714
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1715
            ->method('getObject')
1716
            ->will($this->returnValue($object));
1717
1718
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1719
            ->method('checkAccess')
1720
            ->with($this->equalTo('edit'))
1721
            ->will($this->returnValue(true));
1722
1723
        $form = $this->createMock(Form::class);
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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getForm')
1727
            ->will($this->returnValue($form));
1728
1729
        $form->expects($this->once())
1730
            ->method('isSubmitted')
1731
            ->will($this->returnValue(true));
1732
1733
        $form->expects($this->once())
1734
            ->method('isValid')
1735
            ->will($this->returnValue(false));
1736
1737
        $form->expects($this->once())
1738
            ->method('all')
1739
            ->willReturn(['field' => 'fielddata']);
1740
1741
        $this->request->setMethod('POST');
1742
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1743
1744
        $formView = $this->createMock(FormView::class);
1745
1746
        $form->expects($this->any())
1747
            ->method('createView')
1748
            ->will($this->returnValue($formView));
1749
1750
        $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...
1751
1752
        $this->assertSame($this->admin, $this->parameters['admin']);
1753
        $this->assertSame('@SonataAdmin/ajax_layout.html.twig', $this->parameters['base_template']);
1754
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1755
1756
        $this->assertSame('edit', $this->parameters['action']);
1757
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1758
        $this->assertSame($object, $this->parameters['object']);
1759
1760
        $this->assertSame([], $this->session->getFlashBag()->all());
1761
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1762
    }
1763
1764
    /**
1765
     * @dataProvider getToStringValues
1766
     */
1767
    public function testEditActionWithModelManagerException($expectedToStringValue, $toStringValue): void
1768
    {
1769
        $object = new \stdClass();
1770
1771
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1772
            ->method('getObject')
1773
            ->will($this->returnValue($object));
1774
1775
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1776
            ->method('checkAccess')
1777
            ->with($this->equalTo('edit'))
1778
            ->will($this->returnValue(true));
1779
1780
        $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\AdminInterface>.

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

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

Loading history...
1781
            ->method('getClass')
1782
            ->will($this->returnValue('stdClass'));
1783
1784
        $form = $this->createMock(Form::class);
1785
1786
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1787
            ->method('getForm')
1788
            ->will($this->returnValue($form));
1789
1790
        $form->expects($this->once())
1791
            ->method('isValid')
1792
            ->will($this->returnValue(true));
1793
1794
        $form->expects($this->once())
1795
            ->method('getData')
1796
            ->will($this->returnValue($object));
1797
1798
        $form->expects($this->once())
1799
            ->method('all')
1800
            ->willReturn(['field' => 'fielddata']);
1801
1802
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1803
            ->method('toString')
1804
            ->with($this->equalTo($object))
1805
            ->will($this->returnValue($toStringValue));
1806
1807
        $this->expectTranslate('flash_edit_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1808
1809
        $form->expects($this->once())
1810
            ->method('isSubmitted')
1811
            ->will($this->returnValue(true));
1812
        $this->request->setMethod('POST');
1813
1814
        $formView = $this->createMock(FormView::class);
1815
1816
        $form->expects($this->any())
1817
            ->method('createView')
1818
            ->will($this->returnValue($formView));
1819
1820
        $this->assertLoggerLogsModelManagerException($this->admin, 'update');
1821
        $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...
1822
1823
        $this->assertSame($this->admin, $this->parameters['admin']);
1824
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1825
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1826
1827
        $this->assertSame('edit', $this->parameters['action']);
1828
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1829
        $this->assertSame($object, $this->parameters['object']);
1830
1831
        $this->assertSame(['sonata_flash_error' => ['flash_edit_error']], $this->session->getFlashBag()->all());
1832
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1833
    }
1834
1835
    public function testEditActionWithPreview(): void
1836
    {
1837
        $object = new \stdClass();
1838
1839
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1840
            ->method('getObject')
1841
            ->will($this->returnValue($object));
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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('checkAccess')
1845
            ->with($this->equalTo('edit'))
1846
            ->will($this->returnValue(true));
1847
1848
        $form = $this->createMock(Form::class);
1849
1850
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1851
            ->method('getForm')
1852
            ->will($this->returnValue($form));
1853
1854
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1855
            ->method('supportsPreviewMode')
1856
            ->will($this->returnValue(true));
1857
1858
        $formView = $this->createMock(FormView::class);
1859
1860
        $form->expects($this->any())
1861
            ->method('createView')
1862
            ->will($this->returnValue($formView));
1863
1864
        $form->expects($this->once())
1865
            ->method('isSubmitted')
1866
            ->will($this->returnValue(true));
1867
1868
        $form->expects($this->once())
1869
            ->method('isValid')
1870
            ->will($this->returnValue(true));
1871
1872
        $form->expects($this->once())
1873
            ->method('all')
1874
            ->willReturn(['field' => 'fielddata']);
1875
1876
        $this->request->setMethod('POST');
1877
        $this->request->request->set('btn_preview', 'Preview');
1878
1879
        $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...
1880
1881
        $this->assertSame($this->admin, $this->parameters['admin']);
1882
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1883
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1884
1885
        $this->assertSame('edit', $this->parameters['action']);
1886
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1887
        $this->assertSame($object, $this->parameters['object']);
1888
1889
        $this->assertSame([], $this->session->getFlashBag()->all());
1890
        $this->assertSame('@SonataAdmin/CRUD/preview.html.twig', $this->template);
1891
    }
1892
1893
    public function testEditActionWithLockException(): void
1894
    {
1895
        $object = new \stdClass();
1896
        $class = \get_class($object);
1897
1898
        $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\AdminInterface>.

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

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

Loading history...
1899
            ->method('getObject')
1900
            ->will($this->returnValue($object));
1901
1902
        $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\AdminInterface>.

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

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

Loading history...
1903
            ->method('checkAccess')
1904
            ->with($this->equalTo('edit'))
1905
            ->will($this->returnValue(true));
1906
1907
        $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\AdminInterface>.

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

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

Loading history...
1908
            ->method('getClass')
1909
            ->will($this->returnValue($class));
1910
1911
        $form = $this->createMock(Form::class);
1912
1913
        $form->expects($this->any())
1914
            ->method('isValid')
1915
            ->will($this->returnValue(true));
1916
1917
        $form->expects($this->once())
1918
            ->method('getData')
1919
            ->will($this->returnValue($object));
1920
1921
        $form->expects($this->once())
1922
            ->method('all')
1923
            ->willReturn(['field' => 'fielddata']);
1924
1925
        $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\AdminInterface>.

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

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

Loading history...
1926
            ->method('getForm')
1927
            ->will($this->returnValue($form));
1928
1929
        $form->expects($this->any())
1930
            ->method('isSubmitted')
1931
            ->will($this->returnValue(true));
1932
        $this->request->setMethod('POST');
1933
1934
        $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\AdminInterface>.

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

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

Loading history...
1935
            ->method('update')
1936
            ->will($this->throwException(new LockException()));
1937
1938
        $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\AdminInterface>.

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

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

Loading history...
1939
            ->method('toString')
1940
            ->with($this->equalTo($object))
1941
            ->will($this->returnValue($class));
1942
1943
        $formView = $this->createMock(FormView::class);
1944
1945
        $form->expects($this->any())
1946
            ->method('createView')
1947
            ->will($this->returnValue($formView));
1948
1949
        $this->expectTranslate('flash_lock_error', [
1950
            '%name%' => $class,
1951
            '%link_start%' => '<a href="stdClass_edit">',
1952
            '%link_end%' => '</a>',
1953
        ], 'SonataAdminBundle');
1954
1955
        $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...
1956
    }
1957
1958
    public function testCreateActionAccessDenied(): void
1959
    {
1960
        $this->expectException(AccessDeniedException::class);
1961
1962
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1963
            ->method('checkAccess')
1964
            ->with($this->equalTo('create'))
1965
            ->will($this->throwException(new AccessDeniedException()));
1966
1967
        $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...
1968
    }
1969
1970
    public function testCreateActionRuntimeException(): void
1971
    {
1972
        $this->expectException(\RuntimeException::class);
1973
1974
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1975
            ->method('checkAccess')
1976
            ->with($this->equalTo('create'))
1977
            ->will($this->returnValue(true));
1978
1979
        $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\AdminInterface>.

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

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

Loading history...
1980
            ->method('getClass')
1981
            ->will($this->returnValue('stdClass'));
1982
1983
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1984
            ->method('getNewInstance')
1985
            ->will($this->returnValue(new \stdClass()));
1986
1987
        $form = $this->createMock(Form::class);
1988
1989
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1990
            ->method('getForm')
1991
            ->will($this->returnValue($form));
1992
1993
        $form->expects($this->once())
1994
            ->method('all')
1995
            ->willReturn([]);
1996
1997
        $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...
1998
    }
1999
2000
    public function testPreCreate(): void
2001
    {
2002
        $object = new \stdClass();
2003
        $object->foo = 123456;
2004
2005
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2006
            ->method('checkAccess')
2007
            ->with($this->equalTo('create'))
2008
            ->will($this->returnValue(true));
2009
2010
        $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\AdminInterface>.

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

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

Loading history...
2011
            ->method('getClass')
2012
            ->will($this->returnValue('stdClass'));
2013
2014
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2015
            ->method('getNewInstance')
2016
            ->will($this->returnValue($object));
2017
2018
        $controller = new PreCRUDController();
2019
        $controller->setContainer($this->container);
2020
2021
        $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...
2022
        $this->assertInstanceOf(Response::class, $response);
2023
        $this->assertSame('preCreate called: 123456', $response->getContent());
2024
    }
2025
2026
    public function testCreateAction(): void
2027
    {
2028
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2029
            ->method('checkAccess')
2030
            ->with($this->equalTo('create'))
2031
            ->will($this->returnValue(true));
2032
2033
        $object = new \stdClass();
2034
2035
        $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\AdminInterface>.

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

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

Loading history...
2036
            ->method('getClass')
2037
            ->will($this->returnValue('stdClass'));
2038
2039
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getNewInstance')
2041
            ->will($this->returnValue($object));
2042
2043
        $form = $this->createMock(Form::class);
2044
2045
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2046
            ->method('getForm')
2047
            ->will($this->returnValue($form));
2048
2049
        $form->expects($this->once())
2050
            ->method('all')
2051
            ->willReturn(['field' => 'fielddata']);
2052
2053
        $formView = $this->createMock(FormView::class);
2054
2055
        $form->expects($this->any())
2056
            ->method('createView')
2057
            ->will($this->returnValue($formView));
2058
2059
        $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...
2060
2061
        $this->assertSame($this->admin, $this->parameters['admin']);
2062
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2063
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2064
2065
        $this->assertSame('create', $this->parameters['action']);
2066
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2067
        $this->assertSame($object, $this->parameters['object']);
2068
2069
        $this->assertSame([], $this->session->getFlashBag()->all());
2070
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
2071
    }
2072
2073
    /**
2074
     * @dataProvider getToStringValues
2075
     */
2076
    public function testCreateActionSuccess($expectedToStringValue, $toStringValue): void
2077
    {
2078
        $object = new \stdClass();
2079
2080
        $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\AdminInterface>.

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

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

Loading history...
2081
            ->method('checkAccess')
2082
            ->will($this->returnCallback(function ($name, $objectIn = null) use ($object) {
2083
                if ('edit' == $name) {
2084
                    return true;
2085
                }
2086
2087
                if ('create' != $name) {
2088
                    return false;
2089
                }
2090
2091
                if (null === $objectIn) {
2092
                    return true;
2093
                }
2094
2095
                return $objectIn === $object;
2096
            }));
2097
2098
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2099
            ->method('hasRoute')
2100
            ->with($this->equalTo('edit'))
2101
            ->will($this->returnValue(true));
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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('hasAccess')
2105
            ->with($this->equalTo('edit'))
2106
            ->will($this->returnValue(true));
2107
2108
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2109
            ->method('getNewInstance')
2110
            ->will($this->returnValue($object));
2111
2112
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2113
            ->method('create')
2114
            ->will($this->returnArgument(0));
2115
2116
        $form = $this->createMock(Form::class);
2117
2118
        $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\AdminInterface>.

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

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

Loading history...
2119
            ->method('getClass')
2120
            ->will($this->returnValue('stdClass'));
2121
2122
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2123
            ->method('getForm')
2124
            ->will($this->returnValue($form));
2125
2126
        $form->expects($this->once())
2127
            ->method('all')
2128
            ->willReturn(['field' => 'fielddata']);
2129
2130
        $form->expects($this->once())
2131
            ->method('isSubmitted')
2132
            ->will($this->returnValue(true));
2133
2134
        $form->expects($this->once())
2135
            ->method('isValid')
2136
            ->will($this->returnValue(true));
2137
2138
        $form->expects($this->once())
2139
            ->method('getData')
2140
            ->will($this->returnValue($object));
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\AdminInterface>.

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

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

Loading history...
2143
            ->method('toString')
2144
            ->with($this->equalTo($object))
2145
            ->will($this->returnValue($toStringValue));
2146
2147
        $this->expectTranslate('flash_create_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
2148
2149
        $this->request->setMethod('POST');
2150
2151
        $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...
2152
2153
        $this->assertInstanceOf(RedirectResponse::class, $response);
2154
        $this->assertSame(['flash_create_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
2155
        $this->assertSame('stdClass_edit', $response->getTargetUrl());
2156
    }
2157
2158
    public function testCreateActionAccessDenied2(): void
2159
    {
2160
        $this->expectException(AccessDeniedException::class);
2161
2162
        $object = new \stdClass();
2163
2164
        $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\AdminInterface>.

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

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

Loading history...
2165
            ->method('checkAccess')
2166
            ->will($this->returnCallback(function ($name, $object = null) {
2167
                if ('create' != $name) {
2168
                    throw new AccessDeniedException();
2169
                }
2170
                if (null === $object) {
2171
                    return true;
2172
                }
2173
2174
                throw new AccessDeniedException();
2175
            }));
2176
2177
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2178
            ->method('getNewInstance')
2179
            ->will($this->returnValue($object));
2180
2181
        $form = $this->createMock(Form::class);
2182
2183
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2184
            ->method('getClass')
2185
            ->will($this->returnValue('stdClass'));
2186
2187
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2188
            ->method('getForm')
2189
            ->will($this->returnValue($form));
2190
2191
        $form->expects($this->once())
2192
            ->method('all')
2193
            ->willReturn(['field' => 'fielddata']);
2194
2195
        $form->expects($this->once())
2196
            ->method('isSubmitted')
2197
            ->will($this->returnValue(true));
2198
2199
        $form->expects($this->once())
2200
            ->method('getData')
2201
            ->will($this->returnValue($object));
2202
2203
        $form->expects($this->once())
2204
            ->method('isValid')
2205
            ->will($this->returnValue(true));
2206
2207
        $this->request->setMethod('POST');
2208
2209
        $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...
2210
    }
2211
2212
    /**
2213
     * @dataProvider getToStringValues
2214
     */
2215
    public function testCreateActionError($expectedToStringValue, $toStringValue): void
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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('checkAccess')
2219
            ->with($this->equalTo('create'))
2220
            ->will($this->returnValue(true));
2221
2222
        $object = new \stdClass();
2223
2224
        $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\AdminInterface>.

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

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

Loading history...
2225
            ->method('getClass')
2226
            ->will($this->returnValue('stdClass'));
2227
2228
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2229
            ->method('getNewInstance')
2230
            ->will($this->returnValue($object));
2231
2232
        $form = $this->createMock(Form::class);
2233
2234
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2235
            ->method('getForm')
2236
            ->will($this->returnValue($form));
2237
2238
        $form->expects($this->once())
2239
            ->method('all')
2240
            ->willReturn(['field' => 'fielddata']);
2241
2242
        $form->expects($this->once())
2243
            ->method('isSubmitted')
2244
            ->will($this->returnValue(true));
2245
2246
        $form->expects($this->once())
2247
            ->method('isValid')
2248
            ->will($this->returnValue(false));
2249
2250
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2251
            ->method('toString')
2252
            ->with($this->equalTo($object))
2253
            ->will($this->returnValue($toStringValue));
2254
2255
        $this->expectTranslate('flash_create_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
2256
2257
        $this->request->setMethod('POST');
2258
2259
        $formView = $this->createMock(FormView::class);
2260
2261
        $form->expects($this->any())
2262
            ->method('createView')
2263
            ->will($this->returnValue($formView));
2264
2265
        $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...
2266
2267
        $this->assertSame($this->admin, $this->parameters['admin']);
2268
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2269
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2270
2271
        $this->assertSame('create', $this->parameters['action']);
2272
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2273
        $this->assertSame($object, $this->parameters['object']);
2274
2275
        $this->assertSame(['sonata_flash_error' => ['flash_create_error']], $this->session->getFlashBag()->all());
2276
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
2277
    }
2278
2279
    /**
2280
     * @dataProvider getToStringValues
2281
     */
2282
    public function testCreateActionWithModelManagerException($expectedToStringValue, $toStringValue): void
2283
    {
2284
        $this->admin->expects($this->exactly(2))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2285
            ->method('checkAccess')
2286
            ->with($this->equalTo('create'))
2287
            ->will($this->returnValue(true));
2288
2289
        $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\AdminInterface>.

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

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

Loading history...
2290
            ->method('getClass')
2291
            ->will($this->returnValue('stdClass'));
2292
2293
        $object = new \stdClass();
2294
2295
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2296
            ->method('getNewInstance')
2297
            ->will($this->returnValue($object));
2298
2299
        $form = $this->createMock(Form::class);
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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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
            ->will($this->returnValue($form));
2304
2305
        $form->expects($this->once())
2306
            ->method('all')
2307
            ->willReturn(['field' => 'fielddata']);
2308
2309
        $form->expects($this->once())
2310
            ->method('isValid')
2311
            ->will($this->returnValue(true));
2312
2313
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2314
            ->method('toString')
2315
            ->with($this->equalTo($object))
2316
            ->will($this->returnValue($toStringValue));
2317
2318
        $this->expectTranslate('flash_create_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
2319
2320
        $form->expects($this->once())
2321
            ->method('isSubmitted')
2322
            ->will($this->returnValue(true));
2323
2324
        $form->expects($this->once())
2325
            ->method('getData')
2326
            ->will($this->returnValue($object));
2327
2328
        $this->request->setMethod('POST');
2329
2330
        $formView = $this->createMock(FormView::class);
2331
2332
        $form->expects($this->any())
2333
            ->method('createView')
2334
            ->will($this->returnValue($formView));
2335
2336
        $this->assertLoggerLogsModelManagerException($this->admin, 'create');
2337
2338
        $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...
2339
2340
        $this->assertSame($this->admin, $this->parameters['admin']);
2341
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2342
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2343
2344
        $this->assertSame('create', $this->parameters['action']);
2345
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2346
        $this->assertSame($object, $this->parameters['object']);
2347
2348
        $this->assertSame(['sonata_flash_error' => ['flash_create_error']], $this->session->getFlashBag()->all());
2349
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
2350
    }
2351
2352
    public function testCreateActionAjaxSuccess(): void
2353
    {
2354
        $object = new \stdClass();
2355
2356
        $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\AdminInterface>.

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

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

Loading history...
2357
            ->method('checkAccess')
2358
            ->will($this->returnCallback(function ($name, $objectIn = null) use ($object) {
2359
                if ('create' != $name) {
2360
                    return false;
2361
                }
2362
2363
                if (null === $objectIn) {
2364
                    return true;
2365
                }
2366
2367
                return $objectIn === $object;
2368
            }));
2369
2370
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2371
            ->method('getNewInstance')
2372
            ->will($this->returnValue($object));
2373
2374
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2375
            ->method('create')
2376
            ->will($this->returnArgument(0));
2377
2378
        $form = $this->createMock(Form::class);
2379
2380
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2381
            ->method('getForm')
2382
            ->will($this->returnValue($form));
2383
2384
        $form->expects($this->once())
2385
            ->method('all')
2386
            ->willReturn(['field' => 'fielddata']);
2387
2388
        $form->expects($this->once())
2389
            ->method('isSubmitted')
2390
            ->will($this->returnValue(true));
2391
2392
        $form->expects($this->once())
2393
            ->method('isValid')
2394
            ->will($this->returnValue(true));
2395
2396
        $form->expects($this->once())
2397
            ->method('getData')
2398
            ->will($this->returnValue($object));
2399
2400
        $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\AdminInterface>.

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

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

Loading history...
2401
            ->method('getClass')
2402
            ->will($this->returnValue('stdClass'));
2403
2404
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2405
            ->method('getNormalizedIdentifier')
2406
            ->with($this->equalTo($object))
2407
            ->will($this->returnValue('foo_normalized'));
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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('toString')
2411
            ->will($this->returnValue('foo'));
2412
2413
        $this->request->setMethod('POST');
2414
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
2415
2416
        $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...
2417
2418
        $this->assertInstanceOf(Response::class, $response);
2419
        $this->assertSame(json_encode(['result' => 'ok', 'objectId' => 'foo_normalized', 'objectName' => 'foo']), $response->getContent());
2420
        $this->assertSame([], $this->session->getFlashBag()->all());
2421
    }
2422
2423
    public function testCreateActionAjaxError(): void
2424
    {
2425
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2426
            ->method('checkAccess')
2427
            ->with($this->equalTo('create'))
2428
            ->will($this->returnValue(true));
2429
2430
        $object = new \stdClass();
2431
2432
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2433
            ->method('getNewInstance')
2434
            ->will($this->returnValue($object));
2435
2436
        $form = $this->createMock(Form::class);
2437
2438
        $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\AdminInterface>.

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

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

Loading history...
2439
            ->method('getClass')
2440
            ->will($this->returnValue('stdClass'));
2441
2442
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2443
            ->method('getForm')
2444
            ->will($this->returnValue($form));
2445
2446
        $form->expects($this->once())
2447
            ->method('all')
2448
            ->willReturn(['field' => 'fielddata']);
2449
2450
        $form->expects($this->once())
2451
            ->method('isSubmitted')
2452
            ->will($this->returnValue(true));
2453
2454
        $form->expects($this->once())
2455
            ->method('isValid')
2456
            ->will($this->returnValue(false));
2457
2458
        $this->request->setMethod('POST');
2459
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
2460
2461
        $formView = $this->createMock(FormView::class);
2462
2463
        $form->expects($this->any())
2464
            ->method('createView')
2465
            ->will($this->returnValue($formView));
2466
2467
        $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...
2468
2469
        $this->assertSame($this->admin, $this->parameters['admin']);
2470
        $this->assertSame('@SonataAdmin/ajax_layout.html.twig', $this->parameters['base_template']);
2471
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2472
2473
        $this->assertSame('create', $this->parameters['action']);
2474
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2475
        $this->assertSame($object, $this->parameters['object']);
2476
2477
        $this->assertSame([], $this->session->getFlashBag()->all());
2478
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
2479
    }
2480
2481
    public function testCreateActionWithPreview(): void
2482
    {
2483
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2484
            ->method('checkAccess')
2485
            ->with($this->equalTo('create'))
2486
            ->will($this->returnValue(true));
2487
2488
        $object = new \stdClass();
2489
2490
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2491
            ->method('getNewInstance')
2492
            ->will($this->returnValue($object));
2493
2494
        $form = $this->createMock(Form::class);
2495
2496
        $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\AdminInterface>.

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

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

Loading history...
2497
            ->method('getClass')
2498
            ->will($this->returnValue('stdClass'));
2499
2500
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2501
            ->method('getForm')
2502
            ->will($this->returnValue($form));
2503
2504
        $form->expects($this->once())
2505
            ->method('all')
2506
            ->willReturn(['field' => 'fielddata']);
2507
2508
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2509
            ->method('supportsPreviewMode')
2510
            ->will($this->returnValue(true));
2511
2512
        $formView = $this->createMock(FormView::class);
2513
2514
        $form->expects($this->any())
2515
            ->method('createView')
2516
            ->will($this->returnValue($formView));
2517
2518
        $form->expects($this->once())
2519
            ->method('isSubmitted')
2520
            ->will($this->returnValue(true));
2521
2522
        $form->expects($this->once())
2523
            ->method('isValid')
2524
            ->will($this->returnValue(true));
2525
2526
        $this->request->setMethod('POST');
2527
        $this->request->request->set('btn_preview', 'Preview');
2528
2529
        $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...
2530
2531
        $this->assertSame($this->admin, $this->parameters['admin']);
2532
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2533
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2534
2535
        $this->assertSame('create', $this->parameters['action']);
2536
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2537
        $this->assertSame($object, $this->parameters['object']);
2538
2539
        $this->assertSame([], $this->session->getFlashBag()->all());
2540
        $this->assertSame('@SonataAdmin/CRUD/preview.html.twig', $this->template);
2541
    }
2542
2543
    public function testExportActionAccessDenied(): void
2544
    {
2545
        $this->expectException(AccessDeniedException::class);
2546
2547
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2548
            ->method('checkAccess')
2549
            ->with($this->equalTo('export'))
2550
            ->will($this->throwException(new AccessDeniedException()));
2551
2552
        $this->controller->exportAction($this->request);
2553
    }
2554
2555
    public function testExportActionWrongFormat(): void
2556
    {
2557
        $this->expectException(\RuntimeException::class, 'Export in format `csv` is not allowed for class: `Foo`. Allowed formats are: `json`');
2558
2559
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2560
            ->method('checkAccess')
2561
            ->with($this->equalTo('export'))
2562
            ->will($this->returnValue(true));
2563
2564
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2565
            ->method('getExportFormats')
2566
            ->will($this->returnValue(['json']));
2567
2568
        $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\AdminInterface>.

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

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

Loading history...
2569
            ->method('getClass')
2570
            ->will($this->returnValue('Foo'));
2571
2572
        $this->request->query->set('format', 'csv');
2573
2574
        $this->controller->exportAction($this->request);
2575
    }
2576
2577
    public function testExportAction(): void
2578
    {
2579
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2580
            ->method('checkAccess')
2581
            ->with($this->equalTo('export'))
2582
            ->will($this->returnValue(true));
2583
2584
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2585
            ->method('getExportFormats')
2586
            ->will($this->returnValue(['json']));
2587
2588
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2589
            ->method('getClass')
2590
            ->will($this->returnValue(\stdClass::class));
2591
2592
        $dataSourceIterator = $this->createMock(SourceIteratorInterface::class);
2593
2594
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2595
            ->method('getDataSourceIterator')
2596
            ->will($this->returnValue($dataSourceIterator));
2597
2598
        $this->request->query->set('format', 'json');
2599
2600
        $response = $this->controller->exportAction($this->request);
2601
        $this->assertInstanceOf(StreamedResponse::class, $response);
2602
        $this->assertSame(200, $response->getStatusCode());
2603
        $this->assertSame([], $this->session->getFlashBag()->all());
2604
    }
2605
2606
    public function testHistoryActionAccessDenied(): void
2607
    {
2608
        $this->expectException(AccessDeniedException::class);
2609
2610
        $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\AdminInterface>.

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

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

Loading history...
2611
            ->method('getObject')
2612
            ->will($this->returnValue(new \StdClass()));
2613
2614
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2615
            ->method('checkAccess')
2616
            ->with($this->equalTo('history'))
2617
            ->will($this->throwException(new AccessDeniedException()));
2618
2619
        $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...
2620
    }
2621
2622
    public function testHistoryActionNotFoundException(): void
2623
    {
2624
        $this->expectException(NotFoundHttpException::class);
2625
2626
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2627
            ->method('getObject')
2628
            ->will($this->returnValue(false));
2629
2630
        $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...
2631
    }
2632
2633
    public function testHistoryActionNoReader(): void
2634
    {
2635
        $this->expectException(NotFoundHttpException::class, 'unable to find the audit reader for class : Foo');
2636
2637
        $this->request->query->set('id', 123);
2638
2639
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2640
            ->method('checkAccess')
2641
            ->with($this->equalTo('history'))
2642
            ->will($this->returnValue(true));
2643
2644
        $object = new \stdClass();
2645
2646
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2647
            ->method('getObject')
2648
            ->will($this->returnValue($object));
2649
2650
        $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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getClass')
2652
            ->will($this->returnValue('Foo'));
2653
2654
        $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...
2655
            ->method('hasReader')
2656
            ->with($this->equalTo('Foo'))
2657
            ->will($this->returnValue(false));
2658
2659
        $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...
2660
    }
2661
2662
    public function testHistoryAction(): void
2663
    {
2664
        $this->request->query->set('id', 123);
2665
2666
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2667
            ->method('checkAccess')
2668
            ->with($this->equalTo('history'))
2669
            ->will($this->returnValue(true));
2670
2671
        $object = new \stdClass();
2672
2673
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2674
            ->method('getObject')
2675
            ->will($this->returnValue($object));
2676
2677
        $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\AdminInterface>.

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

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

Loading history...
2678
            ->method('getClass')
2679
            ->will($this->returnValue('Foo'));
2680
2681
        $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...
2682
            ->method('hasReader')
2683
            ->with($this->equalTo('Foo'))
2684
            ->will($this->returnValue(true));
2685
2686
        $reader = $this->createMock(AuditReaderInterface::class);
2687
2688
        $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...
2689
            ->method('getReader')
2690
            ->with($this->equalTo('Foo'))
2691
            ->will($this->returnValue($reader));
2692
2693
        $reader->expects($this->once())
2694
            ->method('findRevisions')
2695
            ->with($this->equalTo('Foo'), $this->equalTo(123))
2696
            ->will($this->returnValue([]));
2697
2698
        $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...
2699
2700
        $this->assertSame($this->admin, $this->parameters['admin']);
2701
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2702
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2703
2704
        $this->assertSame('history', $this->parameters['action']);
2705
        $this->assertSame([], $this->parameters['revisions']);
2706
        $this->assertSame($object, $this->parameters['object']);
2707
2708
        $this->assertSame([], $this->session->getFlashBag()->all());
2709
        $this->assertSame('@SonataAdmin/CRUD/history.html.twig', $this->template);
2710
    }
2711
2712
    public function testAclActionAclNotEnabled(): void
2713
    {
2714
        $this->expectException(NotFoundHttpException::class, 'ACL are not enabled for this admin');
2715
2716
        $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...
2717
    }
2718
2719
    public function testAclActionNotFoundException(): void
2720
    {
2721
        $this->expectException(NotFoundHttpException::class);
2722
2723
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2724
            ->method('isAclEnabled')
2725
            ->will($this->returnValue(true));
2726
2727
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2728
            ->method('getObject')
2729
            ->will($this->returnValue(false));
2730
2731
        $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...
2732
    }
2733
2734
    public function testAclActionAccessDenied(): void
2735
    {
2736
        $this->expectException(AccessDeniedException::class);
2737
2738
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2739
            ->method('isAclEnabled')
2740
            ->will($this->returnValue(true));
2741
2742
        $object = new \stdClass();
2743
2744
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2745
            ->method('getObject')
2746
            ->will($this->returnValue($object));
2747
2748
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2749
            ->method('checkAccess')
2750
            ->with($this->equalTo('acl'), $this->equalTo($object))
2751
            ->will($this->throwException(new AccessDeniedException()));
2752
2753
        $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...
2754
    }
2755
2756
    public function testAclAction(): void
2757
    {
2758
        $this->request->query->set('id', 123);
2759
2760
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2761
            ->method('isAclEnabled')
2762
            ->will($this->returnValue(true));
2763
2764
        $object = new \stdClass();
2765
2766
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2767
            ->method('getObject')
2768
            ->will($this->returnValue($object));
2769
2770
        $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\AdminInterface>.

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

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

Loading history...
2771
            ->method('checkAccess')
2772
            ->will($this->returnValue(true));
2773
2774
        $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\AdminInterface>.

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

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

Loading history...
2775
            ->method('getSecurityInformation')
2776
            ->will($this->returnValue([]));
2777
2778
        $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...
2779
            ->method('getMaskBuilderClass')
2780
            ->will($this->returnValue(AdminPermissionMap::class));
2781
2782
        $aclUsersForm = $this->getMockBuilder(Form::class)
2783
            ->disableOriginalConstructor()
2784
            ->getMock();
2785
2786
        $aclUsersForm->expects($this->once())
2787
            ->method('createView')
2788
            ->will($this->returnValue($this->createMock(FormView::class)));
2789
2790
        $aclRolesForm = $this->getMockBuilder(Form::class)
2791
            ->disableOriginalConstructor()
2792
            ->getMock();
2793
2794
        $aclRolesForm->expects($this->once())
2795
            ->method('createView')
2796
            ->will($this->returnValue($this->createMock(FormView::class)));
2797
2798
        $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...
2799
            ->method('createAclUsersForm')
2800
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2801
            ->will($this->returnValue($aclUsersForm));
2802
2803
        $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...
2804
            ->method('createAclRolesForm')
2805
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2806
            ->will($this->returnValue($aclRolesForm));
2807
2808
        $aclSecurityHandler = $this->getMockBuilder(AclSecurityHandler::class)
2809
            ->disableOriginalConstructor()
2810
            ->getMock();
2811
2812
        $aclSecurityHandler->expects($this->any())
2813
            ->method('getObjectPermissions')
2814
            ->will($this->returnValue([]));
2815
2816
        $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\AdminInterface>.

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

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

Loading history...
2817
            ->method('getSecurityHandler')
2818
            ->will($this->returnValue($aclSecurityHandler));
2819
2820
        $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...
2821
2822
        $this->assertSame($this->admin, $this->parameters['admin']);
2823
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2824
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2825
2826
        $this->assertSame('acl', $this->parameters['action']);
2827
        $this->assertSame([], $this->parameters['permissions']);
2828
        $this->assertSame($object, $this->parameters['object']);
2829
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['users']);
2830
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['roles']);
2831
        $this->assertInstanceOf(FormView::class, $this->parameters['aclUsersForm']);
2832
        $this->assertInstanceOf(FormView::class, $this->parameters['aclRolesForm']);
2833
2834
        $this->assertSame([], $this->session->getFlashBag()->all());
2835
        $this->assertSame('@SonataAdmin/CRUD/acl.html.twig', $this->template);
2836
    }
2837
2838
    public function testAclActionInvalidUpdate(): void
2839
    {
2840
        $this->request->query->set('id', 123);
2841
        $this->request->request->set(AdminObjectAclManipulator::ACL_USERS_FORM_NAME, []);
2842
2843
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2844
            ->method('isAclEnabled')
2845
            ->will($this->returnValue(true));
2846
2847
        $object = new \stdClass();
2848
2849
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2850
            ->method('getObject')
2851
            ->will($this->returnValue($object));
2852
2853
        $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\AdminInterface>.

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

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

Loading history...
2854
            ->method('checkAccess')
2855
            ->will($this->returnValue(true));
2856
2857
        $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\AdminInterface>.

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

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

Loading history...
2858
            ->method('getSecurityInformation')
2859
            ->will($this->returnValue([]));
2860
2861
        $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...
2862
            ->method('getMaskBuilderClass')
2863
            ->will($this->returnValue(AdminPermissionMap::class));
2864
2865
        $aclUsersForm = $this->getMockBuilder(Form::class)
2866
            ->disableOriginalConstructor()
2867
            ->getMock();
2868
2869
        $aclUsersForm->expects($this->once())
2870
            ->method('isValid')
2871
            ->will($this->returnValue(false));
2872
2873
        $aclUsersForm->expects($this->once())
2874
            ->method('createView')
2875
            ->will($this->returnValue($this->createMock(FormView::class)));
2876
2877
        $aclRolesForm = $this->getMockBuilder(Form::class)
2878
            ->disableOriginalConstructor()
2879
            ->getMock();
2880
2881
        $aclRolesForm->expects($this->once())
2882
            ->method('createView')
2883
            ->will($this->returnValue($this->createMock(FormView::class)));
2884
2885
        $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...
2886
            ->method('createAclUsersForm')
2887
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2888
            ->will($this->returnValue($aclUsersForm));
2889
2890
        $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...
2891
            ->method('createAclRolesForm')
2892
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2893
            ->will($this->returnValue($aclRolesForm));
2894
2895
        $aclSecurityHandler = $this->getMockBuilder(AclSecurityHandler::class)
2896
            ->disableOriginalConstructor()
2897
            ->getMock();
2898
2899
        $aclSecurityHandler->expects($this->any())
2900
            ->method('getObjectPermissions')
2901
            ->will($this->returnValue([]));
2902
2903
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2904
            ->method('getSecurityHandler')
2905
            ->will($this->returnValue($aclSecurityHandler));
2906
2907
        $this->request->setMethod('POST');
2908
2909
        $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...
2910
2911
        $this->assertSame($this->admin, $this->parameters['admin']);
2912
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2913
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2914
2915
        $this->assertSame('acl', $this->parameters['action']);
2916
        $this->assertSame([], $this->parameters['permissions']);
2917
        $this->assertSame($object, $this->parameters['object']);
2918
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['users']);
2919
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['roles']);
2920
        $this->assertInstanceOf(FormView::class, $this->parameters['aclUsersForm']);
2921
        $this->assertInstanceOf(FormView::class, $this->parameters['aclRolesForm']);
2922
2923
        $this->assertSame([], $this->session->getFlashBag()->all());
2924
        $this->assertSame('@SonataAdmin/CRUD/acl.html.twig', $this->template);
2925
    }
2926
2927
    public function testAclActionSuccessfulUpdate(): void
2928
    {
2929
        $this->request->query->set('id', 123);
2930
        $this->request->request->set(AdminObjectAclManipulator::ACL_ROLES_FORM_NAME, []);
2931
2932
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2933
            ->method('isAclEnabled')
2934
            ->will($this->returnValue(true));
2935
2936
        $object = new \stdClass();
2937
2938
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2939
            ->method('getObject')
2940
            ->will($this->returnValue($object));
2941
2942
        $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\AdminInterface>.

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

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

Loading history...
2943
            ->method('checkAccess')
2944
            ->will($this->returnValue(true));
2945
2946
        $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\AdminInterface>.

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

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

Loading history...
2947
            ->method('getSecurityInformation')
2948
            ->will($this->returnValue([]));
2949
2950
        $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...
2951
            ->method('getMaskBuilderClass')
2952
            ->will($this->returnValue(AdminPermissionMap::class));
2953
2954
        $aclUsersForm = $this->getMockBuilder(Form::class)
2955
            ->disableOriginalConstructor()
2956
            ->getMock();
2957
2958
        $aclUsersForm->expects($this->any())
2959
            ->method('createView')
2960
            ->will($this->returnValue($this->createMock(FormView::class)));
2961
2962
        $aclRolesForm = $this->getMockBuilder(Form::class)
2963
            ->disableOriginalConstructor()
2964
            ->getMock();
2965
2966
        $aclRolesForm->expects($this->any())
2967
            ->method('createView')
2968
            ->will($this->returnValue($this->createMock(FormView::class)));
2969
2970
        $aclRolesForm->expects($this->once())
2971
            ->method('isValid')
2972
            ->will($this->returnValue(true));
2973
2974
        $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...
2975
            ->method('createAclUsersForm')
2976
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2977
            ->will($this->returnValue($aclUsersForm));
2978
2979
        $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...
2980
            ->method('createAclRolesForm')
2981
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2982
            ->will($this->returnValue($aclRolesForm));
2983
2984
        $aclSecurityHandler = $this->getMockBuilder(AclSecurityHandler::class)
2985
            ->disableOriginalConstructor()
2986
            ->getMock();
2987
2988
        $aclSecurityHandler->expects($this->any())
2989
            ->method('getObjectPermissions')
2990
            ->will($this->returnValue([]));
2991
2992
        $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\AdminInterface>.

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

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

Loading history...
2993
            ->method('getSecurityHandler')
2994
            ->will($this->returnValue($aclSecurityHandler));
2995
2996
        $this->expectTranslate('flash_acl_edit_success', [], 'SonataAdminBundle');
2997
2998
        $this->request->setMethod('POST');
2999
3000
        $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...
3001
3002
        $this->assertInstanceOf(RedirectResponse::class, $response);
3003
3004
        $this->assertSame(['flash_acl_edit_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3005
        $this->assertSame('stdClass_acl', $response->getTargetUrl());
3006
    }
3007
3008
    public function testHistoryViewRevisionActionAccessDenied(): void
3009
    {
3010
        $this->expectException(AccessDeniedException::class);
3011
3012
        $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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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
            ->will($this->returnValue(new \StdClass()));
3015
3016
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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
            ->with($this->equalTo('historyViewRevision'))
3019
            ->will($this->throwException(new AccessDeniedException()));
3020
3021
        $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...
3022
    }
3023
3024
    public function testHistoryViewRevisionActionNotFoundException(): void
3025
    {
3026
        $this->expectException(NotFoundHttpException::class, 'unable to find the object with id: 123');
3027
3028
        $this->request->query->set('id', 123);
3029
3030
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3031
            ->method('getObject')
3032
            ->will($this->returnValue(false));
3033
3034
        $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...
3035
    }
3036
3037
    public function testHistoryViewRevisionActionNoReader(): void
3038
    {
3039
        $this->expectException(NotFoundHttpException::class, 'unable to find the audit reader for class : Foo');
3040
3041
        $this->request->query->set('id', 123);
3042
3043
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3044
            ->method('checkAccess')
3045
            ->with($this->equalTo('historyViewRevision'))
3046
            ->will($this->returnValue(true));
3047
3048
        $object = new \stdClass();
3049
3050
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3051
            ->method('getObject')
3052
            ->will($this->returnValue($object));
3053
3054
        $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\AdminInterface>.

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

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

Loading history...
3055
            ->method('getClass')
3056
            ->will($this->returnValue('Foo'));
3057
3058
        $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...
3059
            ->method('hasReader')
3060
            ->with($this->equalTo('Foo'))
3061
            ->will($this->returnValue(false));
3062
3063
        $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...
3064
    }
3065
3066
    public function testHistoryViewRevisionActionNotFoundRevision(): void
3067
    {
3068
        $this->expectException(NotFoundHttpException::class, 'unable to find the targeted object `123` from the revision `456` with classname : `Foo`');
3069
3070
        $this->request->query->set('id', 123);
3071
3072
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3073
            ->method('checkAccess')
3074
            ->with($this->equalTo('historyViewRevision'))
3075
            ->will($this->returnValue(true));
3076
3077
        $object = new \stdClass();
3078
3079
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3080
            ->method('getObject')
3081
            ->will($this->returnValue($object));
3082
3083
        $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\AdminInterface>.

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

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

Loading history...
3084
            ->method('getClass')
3085
            ->will($this->returnValue('Foo'));
3086
3087
        $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...
3088
            ->method('hasReader')
3089
            ->with($this->equalTo('Foo'))
3090
            ->will($this->returnValue(true));
3091
3092
        $reader = $this->createMock(AuditReaderInterface::class);
3093
3094
        $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...
3095
            ->method('getReader')
3096
            ->with($this->equalTo('Foo'))
3097
            ->will($this->returnValue($reader));
3098
3099
        $reader->expects($this->once())
3100
            ->method('find')
3101
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3102
            ->will($this->returnValue(null));
3103
3104
        $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...
3105
    }
3106
3107
    public function testHistoryViewRevisionAction(): void
3108
    {
3109
        $this->request->query->set('id', 123);
3110
3111
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3112
            ->method('checkAccess')
3113
            ->with($this->equalTo('historyViewRevision'))
3114
            ->will($this->returnValue(true));
3115
3116
        $object = new \stdClass();
3117
3118
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3119
            ->method('getObject')
3120
            ->will($this->returnValue($object));
3121
3122
        $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\AdminInterface>.

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

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

Loading history...
3123
            ->method('getClass')
3124
            ->will($this->returnValue('Foo'));
3125
3126
        $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...
3127
            ->method('hasReader')
3128
            ->with($this->equalTo('Foo'))
3129
            ->will($this->returnValue(true));
3130
3131
        $reader = $this->createMock(AuditReaderInterface::class);
3132
3133
        $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...
3134
            ->method('getReader')
3135
            ->with($this->equalTo('Foo'))
3136
            ->will($this->returnValue($reader));
3137
3138
        $objectRevision = new \stdClass();
3139
        $objectRevision->revision = 456;
3140
3141
        $reader->expects($this->once())
3142
            ->method('find')
3143
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3144
            ->will($this->returnValue($objectRevision));
3145
3146
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3147
            ->method('setSubject')
3148
            ->with($this->equalTo($objectRevision))
3149
            ->will($this->returnValue(null));
3150
3151
        $fieldDescriptionCollection = new FieldDescriptionCollection();
3152
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3153
            ->method('getShow')
3154
            ->will($this->returnValue($fieldDescriptionCollection));
3155
3156
        $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...
3157
3158
        $this->assertSame($this->admin, $this->parameters['admin']);
3159
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
3160
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3161
3162
        $this->assertSame('show', $this->parameters['action']);
3163
        $this->assertSame($objectRevision, $this->parameters['object']);
3164
        $this->assertSame($fieldDescriptionCollection, $this->parameters['elements']);
3165
3166
        $this->assertSame([], $this->session->getFlashBag()->all());
3167
        $this->assertSame('@SonataAdmin/CRUD/show.html.twig', $this->template);
3168
    }
3169
3170
    public function testHistoryCompareRevisionsActionAccessDenied(): void
3171
    {
3172
        $this->expectException(AccessDeniedException::class);
3173
3174
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3175
            ->method('checkAccess')
3176
            ->with($this->equalTo('historyCompareRevisions'))
3177
            ->will($this->throwException(new AccessDeniedException()));
3178
3179
        $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...
3180
    }
3181
3182
    public function testHistoryCompareRevisionsActionNotFoundException(): void
3183
    {
3184
        $this->expectException(NotFoundHttpException::class, 'unable to find the object with id: 123');
3185
3186
        $this->request->query->set('id', 123);
3187
3188
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3189
            ->method('checkAccess')
3190
            ->with($this->equalTo('historyCompareRevisions'))
3191
            ->will($this->returnValue(true));
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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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
            ->will($this->returnValue(false));
3196
3197
        $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...
3198
    }
3199
3200
    public function testHistoryCompareRevisionsActionNoReader(): void
3201
    {
3202
        $this->expectException(NotFoundHttpException::class, 'unable to find the audit reader for class : Foo');
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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('historyCompareRevisions'))
3209
            ->will($this->returnValue(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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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
            ->will($this->returnValue($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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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
            ->will($this->returnValue('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
            ->will($this->returnValue(false));
3225
3226
        $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...
3227
    }
3228
3229
    public function testHistoryCompareRevisionsActionNotFoundBaseRevision(): void
3230
    {
3231
        $this->expectException(NotFoundHttpException::class, 'unable to find the targeted object `123` from the revision `456` with classname : `Foo`');
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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('historyCompareRevisions'))
3238
            ->will($this->returnValue(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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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
            ->will($this->returnValue($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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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
            ->will($this->returnValue('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
            ->will($this->returnValue(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
            ->will($this->returnValue($reader));
3261
3262
        // once because it will not be found and therefore the second call won't be executed
3263
        $reader->expects($this->once())
3264
            ->method('find')
3265
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3266
            ->will($this->returnValue(null));
3267
3268
        $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...
3269
    }
3270
3271
    public function testHistoryCompareRevisionsActionNotFoundCompareRevision(): void
3272
    {
3273
        $this->expectException(NotFoundHttpException::class, 'unable to find the targeted object `123` from the revision `789` with classname : `Foo`');
3274
3275
        $this->request->query->set('id', 123);
3276
3277
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3278
            ->method('checkAccess')
3279
            ->with($this->equalTo('historyCompareRevisions'))
3280
            ->will($this->returnValue(true));
3281
3282
        $object = new \stdClass();
3283
3284
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3285
            ->method('getObject')
3286
            ->will($this->returnValue($object));
3287
3288
        $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\AdminInterface>.

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

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

Loading history...
3289
            ->method('getClass')
3290
            ->will($this->returnValue('Foo'));
3291
3292
        $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...
3293
            ->method('hasReader')
3294
            ->with($this->equalTo('Foo'))
3295
            ->will($this->returnValue(true));
3296
3297
        $reader = $this->createMock(AuditReaderInterface::class);
3298
3299
        $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...
3300
            ->method('getReader')
3301
            ->with($this->equalTo('Foo'))
3302
            ->will($this->returnValue($reader));
3303
3304
        $objectRevision = new \stdClass();
3305
        $objectRevision->revision = 456;
3306
3307
        // first call should return, so the second call will throw an exception
3308
        $reader->expects($this->at(0))
3309
            ->method('find')
3310
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3311
            ->will($this->returnValue($objectRevision));
3312
3313
        $reader->expects($this->at(1))
3314
            ->method('find')
3315
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(789))
3316
            ->will($this->returnValue(null));
3317
3318
        $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...
3319
    }
3320
3321
    public function testHistoryCompareRevisionsActionAction(): void
3322
    {
3323
        $this->request->query->set('id', 123);
3324
3325
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3326
            ->method('checkAccess')
3327
            ->with($this->equalTo('historyCompareRevisions'))
3328
            ->will($this->returnValue(true));
3329
3330
        $object = new \stdClass();
3331
3332
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3333
            ->method('getObject')
3334
            ->will($this->returnValue($object));
3335
3336
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3337
            ->method('getClass')
3338
            ->will($this->returnValue('Foo'));
3339
3340
        $this->auditManager->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Model\AuditManager>.

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

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

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

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

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

Loading history...
3348
            ->method('getReader')
3349
            ->with($this->equalTo('Foo'))
3350
            ->will($this->returnValue($reader));
3351
3352
        $objectRevision = new \stdClass();
3353
        $objectRevision->revision = 456;
3354
3355
        $compareObjectRevision = new \stdClass();
3356
        $compareObjectRevision->revision = 789;
3357
3358
        $reader->expects($this->at(0))
3359
            ->method('find')
3360
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3361
            ->will($this->returnValue($objectRevision));
3362
3363
        $reader->expects($this->at(1))
3364
            ->method('find')
3365
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(789))
3366
            ->will($this->returnValue($compareObjectRevision));
3367
3368
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3369
            ->method('setSubject')
3370
            ->with($this->equalTo($objectRevision))
3371
            ->will($this->returnValue(null));
3372
3373
        $fieldDescriptionCollection = new FieldDescriptionCollection();
3374
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3375
            ->method('getShow')
3376
            ->will($this->returnValue($fieldDescriptionCollection));
3377
3378
        $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...
3379
3380
        $this->assertSame($this->admin, $this->parameters['admin']);
3381
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
3382
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3383
3384
        $this->assertSame('show', $this->parameters['action']);
3385
        $this->assertSame($objectRevision, $this->parameters['object']);
3386
        $this->assertSame($compareObjectRevision, $this->parameters['object_compare']);
3387
        $this->assertSame($fieldDescriptionCollection, $this->parameters['elements']);
3388
3389
        $this->assertSame([], $this->session->getFlashBag()->all());
3390
        $this->assertSame('@SonataAdmin/CRUD/show_compare.html.twig', $this->template);
3391
    }
3392
3393
    public function testBatchActionWrongMethod(): void
3394
    {
3395
        $this->expectException(NotFoundHttpException::class, 'Invalid request type "GET", POST expected');
3396
3397
        $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...
3398
    }
3399
3400
    public function testBatchActionActionNotDefined(): void
3401
    {
3402
        $this->expectException(\RuntimeException::class, 'The `foo` batch action is not defined');
3403
3404
        $batchActions = [];
3405
3406
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3407
            ->method('getBatchActions')
3408
            ->will($this->returnValue($batchActions));
3409
3410
        $this->request->setMethod('POST');
3411
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3412
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3413
3414
        $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...
3415
    }
3416
3417
    public function testBatchActionActionInvalidCsrfToken(): void
3418
    {
3419
        $this->request->setMethod('POST');
3420
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3421
        $this->request->request->set('_sonata_csrf_token', 'CSRF-INVALID');
3422
3423
        try {
3424
            $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...
3425
        } catch (HttpException $e) {
3426
            $this->assertSame('The csrf token is not valid, CSRF attack?', $e->getMessage());
3427
            $this->assertSame(400, $e->getStatusCode());
3428
        }
3429
    }
3430
3431
    public function testBatchActionMethodNotExist(): void
3432
    {
3433
        $this->expectException(\RuntimeException::class, 'A `Sonata\AdminBundle\Controller\CRUDController::batchActionFoo` method must be callable');
3434
3435
        $batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3436
3437
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3438
            ->method('getBatchActions')
3439
            ->will($this->returnValue($batchActions));
3440
3441
        $datagrid = $this->createMock(DatagridInterface::class);
3442
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3443
            ->method('getDatagrid')
3444
            ->will($this->returnValue($datagrid));
3445
3446
        $this->request->setMethod('POST');
3447
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3448
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3449
3450
        $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...
3451
    }
3452
3453
    public function testBatchActionWithoutConfirmation(): void
3454
    {
3455
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3456
3457
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3458
            ->method('getBatchActions')
3459
            ->will($this->returnValue($batchActions));
3460
3461
        $datagrid = $this->createMock(DatagridInterface::class);
3462
3463
        $query = $this->createMock(ProxyQueryInterface::class);
3464
        $datagrid->expects($this->once())
3465
            ->method('getQuery')
3466
            ->will($this->returnValue($query));
3467
3468
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3469
            ->method('getDatagrid')
3470
            ->will($this->returnValue($datagrid));
3471
3472
        $modelManager = $this->createMock(ModelManagerInterface::class);
3473
3474
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3475
            ->method('checkAccess')
3476
            ->with($this->equalTo('batchDelete'))
3477
            ->will($this->returnValue(true));
3478
3479
        $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\AdminInterface>.

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

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

Loading history...
3480
            ->method('getModelManager')
3481
            ->will($this->returnValue($modelManager));
3482
3483
        $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\AdminInterface>.

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

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

Loading history...
3484
            ->method('getClass')
3485
            ->will($this->returnValue('Foo'));
3486
3487
        $modelManager->expects($this->once())
3488
            ->method('addIdentifiersToQuery')
3489
            ->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456']))
3490
            ->will($this->returnValue(true));
3491
3492
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
3493
3494
        $this->request->setMethod('POST');
3495
        $this->request->request->set('data', json_encode(['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false]));
3496
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3497
3498
        $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...
3499
3500
        $this->assertInstanceOf(RedirectResponse::class, $result);
3501
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3502
        $this->assertSame('list', $result->getTargetUrl());
3503
    }
3504
3505
    public function testBatchActionWithoutConfirmation2(): void
3506
    {
3507
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3508
3509
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3510
            ->method('getBatchActions')
3511
            ->will($this->returnValue($batchActions));
3512
3513
        $datagrid = $this->createMock(DatagridInterface::class);
3514
3515
        $query = $this->createMock(ProxyQueryInterface::class);
3516
        $datagrid->expects($this->once())
3517
            ->method('getQuery')
3518
            ->will($this->returnValue($query));
3519
3520
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3521
            ->method('getDatagrid')
3522
            ->will($this->returnValue($datagrid));
3523
3524
        $modelManager = $this->createMock(ModelManagerInterface::class);
3525
3526
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3527
            ->method('checkAccess')
3528
            ->with($this->equalTo('batchDelete'))
3529
            ->will($this->returnValue(true));
3530
3531
        $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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getModelManager')
3533
            ->will($this->returnValue($modelManager));
3534
3535
        $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\AdminInterface>.

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

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

Loading history...
3536
            ->method('getClass')
3537
            ->will($this->returnValue('Foo'));
3538
3539
        $modelManager->expects($this->once())
3540
            ->method('addIdentifiersToQuery')
3541
            ->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456']))
3542
            ->will($this->returnValue(true));
3543
3544
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
3545
3546
        $this->request->setMethod('POST');
3547
        $this->request->request->set('action', 'delete');
3548
        $this->request->request->set('idx', ['123', '456']);
3549
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3550
3551
        $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...
3552
3553
        $this->assertInstanceOf(RedirectResponse::class, $result);
3554
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3555
        $this->assertSame('list', $result->getTargetUrl());
3556
    }
3557
3558
    public function testBatchActionWithConfirmation(): void
3559
    {
3560
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'translation_domain' => 'FooBarBaz', 'ask_confirmation' => true]];
3561
3562
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3563
            ->method('getBatchActions')
3564
            ->will($this->returnValue($batchActions));
3565
3566
        $data = ['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false];
3567
3568
        $this->request->setMethod('POST');
3569
        $this->request->request->set('data', json_encode($data));
3570
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3571
3572
        $datagrid = $this->createMock(DatagridInterface::class);
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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getDatagrid')
3576
            ->will($this->returnValue($datagrid));
3577
3578
        $form = $this->getMockBuilder(Form::class)
3579
            ->disableOriginalConstructor()
3580
            ->getMock();
3581
3582
        $form->expects($this->once())
3583
            ->method('createView')
3584
            ->will($this->returnValue($this->createMock(FormView::class)));
3585
3586
        $datagrid->expects($this->once())
3587
            ->method('getForm')
3588
            ->will($this->returnValue($form));
3589
3590
        $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...
3591
3592
        $this->assertSame($this->admin, $this->parameters['admin']);
3593
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
3594
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3595
3596
        $this->assertSame('list', $this->parameters['action']);
3597
        $this->assertSame($datagrid, $this->parameters['datagrid']);
3598
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
3599
        $this->assertSame($data, $this->parameters['data']);
3600
        $this->assertSame('csrf-token-123_sonata.batch', $this->parameters['csrf_token']);
3601
        $this->assertSame('Foo Bar', $this->parameters['action_label']);
3602
3603
        $this->assertSame([], $this->session->getFlashBag()->all());
3604
        $this->assertSame('@SonataAdmin/CRUD/batch_confirmation.html.twig', $this->template);
3605
    }
3606
3607
    public function testBatchActionNonRelevantAction(): void
3608
    {
3609
        $controller = new BatchAdminController();
3610
        $controller->setContainer($this->container);
3611
3612
        $batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3613
3614
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3615
            ->method('getBatchActions')
3616
            ->will($this->returnValue($batchActions));
3617
3618
        $datagrid = $this->createMock(DatagridInterface::class);
3619
3620
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3621
            ->method('getDatagrid')
3622
            ->will($this->returnValue($datagrid));
3623
3624
        $this->expectTranslate('flash_batch_empty', [], 'SonataAdminBundle');
3625
3626
        $this->request->setMethod('POST');
3627
        $this->request->request->set('action', 'foo');
3628
        $this->request->request->set('idx', ['789']);
3629
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3630
3631
        $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...
3632
3633
        $this->assertInstanceOf(RedirectResponse::class, $result);
3634
        $this->assertSame(['flash_batch_empty'], $this->session->getFlashBag()->get('sonata_flash_info'));
3635
        $this->assertSame('list', $result->getTargetUrl());
3636
    }
3637
3638
    public function testBatchActionWithCustomConfirmationTemplate(): void
3639
    {
3640
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => true, 'template' => 'custom_template.html.twig']];
3641
3642
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3643
            ->method('getBatchActions')
3644
            ->will($this->returnValue($batchActions));
3645
3646
        $data = ['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false];
3647
3648
        $this->request->setMethod('POST');
3649
        $this->request->request->set('data', json_encode($data));
3650
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3651
3652
        $datagrid = $this->createMock(DatagridInterface::class);
3653
3654
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3655
            ->method('getDatagrid')
3656
            ->will($this->returnValue($datagrid));
3657
3658
        $form = $this->createMock(Form::class);
3659
3660
        $form->expects($this->once())
3661
            ->method('createView')
3662
            ->will($this->returnValue($this->createMock(FormView::class)));
3663
3664
        $datagrid->expects($this->once())
3665
            ->method('getForm')
3666
            ->will($this->returnValue($form));
3667
3668
        $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...
3669
3670
        $this->assertSame('custom_template.html.twig', $this->template);
3671
    }
3672
3673
    public function testBatchActionNonRelevantAction2(): void
3674
    {
3675
        $controller = new BatchAdminController();
3676
        $controller->setContainer($this->container);
3677
3678
        $batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3679
3680
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3681
            ->method('getBatchActions')
3682
            ->will($this->returnValue($batchActions));
3683
3684
        $datagrid = $this->createMock(DatagridInterface::class);
3685
3686
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3687
            ->method('getDatagrid')
3688
            ->will($this->returnValue($datagrid));
3689
3690
        $this->expectTranslate('flash_foo_error', [], 'SonataAdminBundle');
3691
3692
        $this->request->setMethod('POST');
3693
        $this->request->request->set('action', 'foo');
3694
        $this->request->request->set('idx', ['999']);
3695
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3696
3697
        $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...
3698
3699
        $this->assertInstanceOf(RedirectResponse::class, $result);
3700
        $this->assertSame(['flash_foo_error'], $this->session->getFlashBag()->get('sonata_flash_info'));
3701
        $this->assertSame('list', $result->getTargetUrl());
3702
    }
3703
3704
    public function testBatchActionNoItems(): void
3705
    {
3706
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => true]];
3707
3708
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3709
            ->method('getBatchActions')
3710
            ->will($this->returnValue($batchActions));
3711
3712
        $datagrid = $this->createMock(DatagridInterface::class);
3713
3714
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getDatagrid')
3716
            ->will($this->returnValue($datagrid));
3717
3718
        $this->expectTranslate('flash_batch_empty', [], 'SonataAdminBundle');
3719
3720
        $this->request->setMethod('POST');
3721
        $this->request->request->set('action', 'delete');
3722
        $this->request->request->set('idx', []);
3723
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3724
3725
        $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...
3726
3727
        $this->assertInstanceOf(RedirectResponse::class, $result);
3728
        $this->assertSame(['flash_batch_empty'], $this->session->getFlashBag()->get('sonata_flash_info'));
3729
        $this->assertSame('list', $result->getTargetUrl());
3730
    }
3731
3732
    public function testBatchActionNoItemsEmptyQuery(): void
3733
    {
3734
        $controller = new BatchAdminController();
3735
        $controller->setContainer($this->container);
3736
3737
        $batchActions = ['bar' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3738
3739
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3740
            ->method('getBatchActions')
3741
            ->will($this->returnValue($batchActions));
3742
3743
        $datagrid = $this->createMock(DatagridInterface::class);
3744
3745
        $query = $this->createMock(ProxyQueryInterface::class);
3746
        $datagrid->expects($this->once())
3747
            ->method('getQuery')
3748
            ->will($this->returnValue($query));
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\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getDatagrid')
3752
            ->will($this->returnValue($datagrid));
3753
3754
        $modelManager = $this->createMock(ModelManagerInterface::class);
3755
3756
        $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\AdminInterface>.

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

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

Loading history...
3757
            ->method('getModelManager')
3758
            ->will($this->returnValue($modelManager));
3759
3760
        $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\AdminInterface>.

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

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

Loading history...
3761
            ->method('getClass')
3762
            ->will($this->returnValue('Foo'));
3763
3764
        $this->request->setMethod('POST');
3765
        $this->request->request->set('action', 'bar');
3766
        $this->request->request->set('idx', []);
3767
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3768
3769
        $this->expectTranslate('flash_batch_no_elements_processed', [], 'SonataAdminBundle');
3770
        $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...
3771
3772
        $this->assertInstanceOf(Response::class, $result);
3773
        $this->assertRegExp('/Redirecting to list/', $result->getContent());
3774
    }
3775
3776
    public function testBatchActionWithRequesData(): void
3777
    {
3778
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3779
3780
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3781
            ->method('getBatchActions')
3782
            ->will($this->returnValue($batchActions));
3783
3784
        $datagrid = $this->createMock(DatagridInterface::class);
3785
3786
        $query = $this->createMock(ProxyQueryInterface::class);
3787
        $datagrid->expects($this->once())
3788
            ->method('getQuery')
3789
            ->will($this->returnValue($query));
3790
3791
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3792
            ->method('getDatagrid')
3793
            ->will($this->returnValue($datagrid));
3794
3795
        $modelManager = $this->createMock(ModelManagerInterface::class);
3796
3797
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3798
            ->method('checkAccess')
3799
            ->with($this->equalTo('batchDelete'))
3800
            ->will($this->returnValue(true));
3801
3802
        $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\AdminInterface>.

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

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

Loading history...
3803
            ->method('getModelManager')
3804
            ->will($this->returnValue($modelManager));
3805
3806
        $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\AdminInterface>.

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

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

Loading history...
3807
            ->method('getClass')
3808
            ->will($this->returnValue('Foo'));
3809
3810
        $modelManager->expects($this->once())
3811
            ->method('addIdentifiersToQuery')
3812
            ->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456']))
3813
            ->will($this->returnValue(true));
3814
3815
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
3816
3817
        $this->request->setMethod('POST');
3818
        $this->request->request->set('data', json_encode(['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false]));
3819
        $this->request->request->set('foo', 'bar');
3820
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3821
3822
        $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...
3823
3824
        $this->assertInstanceOf(RedirectResponse::class, $result);
3825
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3826
        $this->assertSame('list', $result->getTargetUrl());
3827
        $this->assertSame('bar', $this->request->request->get('foo'));
3828
    }
3829
3830
    public function testItThrowsWhenCallingAnUndefinedMethod(): void
3831
    {
3832
        $this->expectException(
3833
            \LogicException::class
3834
        );
3835
        $this->expectExceptionMessage(
3836
            'Call to undefined method Sonata\AdminBundle\Controller\CRUDController::doesNotExist'
3837
        );
3838
        $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...
3839
    }
3840
3841
    /**
3842
     * @expectedDeprecation Method Sonata\AdminBundle\Controller\CRUDController::render has been renamed to Sonata\AdminBundle\Controller\CRUDController::renderWithExtraParams.
3843
     */
3844
    public function testRenderIsDeprecated(): void
3845
    {
3846
        $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...
3847
    }
3848
3849
    public function getCsrfProvider()
3850
    {
3851
        return $this->csrfProvider;
3852
    }
3853
3854
    public function getToStringValues()
3855
    {
3856
        return [
3857
            ['', ''],
3858
            ['Foo', 'Foo'],
3859
            ['&lt;a href=&quot;http://foo&quot;&gt;Bar&lt;/a&gt;', '<a href="http://foo">Bar</a>'],
3860
            ['&lt;&gt;&amp;&quot;&#039;abcdefghijklmnopqrstuvwxyz*-+.,?_()[]\/', '<>&"\'abcdefghijklmnopqrstuvwxyz*-+.,?_()[]\/'],
3861
        ];
3862
    }
3863
3864
    private function assertLoggerLogsModelManagerException($subject, $method): void
3865
    {
3866
        $exception = new ModelManagerException(
3867
            $message = 'message',
3868
            1234,
3869
            new \Exception($previousExceptionMessage = 'very useful message')
3870
        );
3871
3872
        $subject->expects($this->once())
3873
            ->method($method)
3874
            ->will($this->returnCallback(function () use ($exception): void {
3875
                throw $exception;
3876
            }));
3877
3878
        $this->logger->expects($this->once())
3879
            ->method('error')
3880
            ->with($message, [
3881
                'exception' => $exception,
3882
                'previous_exception_message' => $previousExceptionMessage,
3883
            ]);
3884
    }
3885
3886
    private function expectTranslate($id, array $parameters = [], $domain = null, $locale = null): void
3887
    {
3888
        $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...
3889
            ->method('trans')
3890
            ->with($this->equalTo($id), $this->equalTo($parameters), $this->equalTo($domain), $this->equalTo($locale))
3891
            ->will($this->returnValue($id));
3892
    }
3893
}
3894