Completed
Push — master ( 6a1428...1fabec )
by Grégoire
14s queued 10s
created

testDeleteActionWithDisabledCsrfProtection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 9.408
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\AdminBundle\Tests\Controller;
15
16
use PHPUnit\Framework\TestCase;
17
use Psr\Log\LoggerInterface;
18
use Sonata\AdminBundle\Admin\AdminInterface;
19
use Sonata\AdminBundle\Admin\FieldDescriptionCollection;
20
use Sonata\AdminBundle\Admin\Pool;
21
use Sonata\AdminBundle\Controller\CRUDController;
22
use Sonata\AdminBundle\Datagrid\DatagridInterface;
23
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
24
use Sonata\AdminBundle\Exception\LockException;
25
use Sonata\AdminBundle\Exception\ModelManagerException;
26
use Sonata\AdminBundle\Export\Exporter as SonataExporter;
27
use Sonata\AdminBundle\Model\AuditManager;
28
use Sonata\AdminBundle\Model\AuditReaderInterface;
29
use Sonata\AdminBundle\Model\ModelManagerInterface;
30
use Sonata\AdminBundle\Security\Acl\Permission\AdminPermissionMap;
31
use Sonata\AdminBundle\Security\Handler\AclSecurityHandler;
32
use Sonata\AdminBundle\Templating\TemplateRegistryInterface;
33
use Sonata\AdminBundle\Tests\Fixtures\Controller\BatchAdminController;
34
use Sonata\AdminBundle\Tests\Fixtures\Controller\PreCRUDController;
35
use Sonata\AdminBundle\Util\AdminObjectAclData;
36
use Sonata\AdminBundle\Util\AdminObjectAclManipulator;
37
use Sonata\Exporter\Exporter;
38
use Sonata\Exporter\Source\SourceIteratorInterface;
39
use Sonata\Exporter\Writer\JsonWriter;
40
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
41
use Symfony\Bundle\FrameworkBundle\Templating\DelegatingEngine;
42
use Symfony\Component\DependencyInjection\ContainerInterface;
43
use Symfony\Component\Form\Form;
44
use Symfony\Component\Form\FormBuilderInterface;
45
use Symfony\Component\Form\FormError;
46
use Symfony\Component\Form\FormInterface;
47
use Symfony\Component\Form\FormRenderer;
48
use Symfony\Component\Form\FormView;
49
use Symfony\Component\HttpFoundation\JsonResponse;
50
use Symfony\Component\HttpFoundation\RedirectResponse;
51
use Symfony\Component\HttpFoundation\Request;
52
use Symfony\Component\HttpFoundation\RequestStack;
53
use Symfony\Component\HttpFoundation\Response;
54
use Symfony\Component\HttpFoundation\Session\Session;
55
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
56
use Symfony\Component\HttpFoundation\StreamedResponse;
57
use Symfony\Component\HttpKernel\Exception\HttpException;
58
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
59
use Symfony\Component\HttpKernel\KernelInterface;
60
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
61
use Symfony\Component\Security\Csrf\CsrfToken;
62
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
63
use Symfony\Component\Translation\TranslatorInterface;
64
use Twig\Environment;
65
66
/**
67
 * Test for CRUDController.
68
 *
69
 * @author Andrej Hudec <[email protected]>
70
 *
71
 * @group legacy
72
 */
73
class CRUDControllerTest extends TestCase
74
{
75
    /**
76
     * @var CRUDController
77
     */
78
    private $controller;
79
80
    /**
81
     * @var Request
82
     */
83
    private $request;
84
85
    /**
86
     * @var AdminInterface
87
     */
88
    private $admin;
89
90
    /**
91
     * @var TemplateRegistryInterface
92
     */
93
    private $templateRegistry;
94
95
    /**
96
     * @var Pool
97
     */
98
    private $pool;
99
100
    /**
101
     * @var array
102
     */
103
    private $parameters;
104
105
    /**
106
     * @var Session
107
     */
108
    private $session;
109
110
    /**
111
     * @var AuditManager
112
     */
113
    private $auditManager;
114
115
    /**
116
     * @var ContainerInterface
117
     */
118
    private $container;
119
120
    /**
121
     * @var AdminObjectAclManipulator
122
     */
123
    private $adminObjectAclManipulator;
124
125
    /**
126
     * @var string
127
     */
128
    private $template;
129
130
    /**
131
     * @var array
132
     */
133
    private $protectedTestedMethods;
134
135
    /**
136
     * @var CsrfTokenManagerInterface
137
     */
138
    private $csrfProvider;
139
140
    /**
141
     * @var KernelInterface
142
     */
143
    private $kernel;
144
145
    /**
146
     * @var TranslatorInterface
147
     */
148
    private $translator;
149
150
    /**
151
     * @var FormBuilderInterface
152
     */
153
    private $formBuilder;
154
155
    /**
156
     * {@inheritdoc}
157
     */
158
    protected function setUp(): void
159
    {
160
        $this->container = $this->createMock(ContainerInterface::class);
161
162
        $this->request = new Request();
163
        $this->pool = new Pool($this->container, 'title', 'logo.png');
164
        $this->pool->setAdminServiceIds(['foo.admin']);
165
        $this->request->attributes->set('_sonata_admin', 'foo.admin');
166
        $this->admin = $this->getMockBuilder(AdminInterface::class)
167
            ->disableOriginalConstructor()
168
            ->getMock();
169
        $this->translator = $this->createMock(TranslatorInterface::class);
170
        $this->parameters = [];
171
        $this->template = '';
172
173
        $this->formBuilder = $this->createMock(FormBuilderInterface::class);
174
        $this->admin->expects($this->any())
175
            ->method('getFormBuilder')
176
            ->willReturn($this->formBuilder);
177
178
        $this->templateRegistry = $this->prophesize(TemplateRegistryInterface::class);
179
180
        $templating = $this->getMockBuilder(DelegatingEngine::class)
181
            ->setConstructorArgs([$this->container, []])
182
            ->getMock();
183
184
        $templatingRenderReturnCallback = $this->returnCallback(function (
185
            $view,
186
            array $parameters = [],
187
            Response $response = null
188
        ) {
189
            $this->template = $view;
190
191
            if (null === $response) {
192
                $response = new Response();
193
            }
194
195
            $this->parameters = $parameters;
196
197
            return $response;
198
        });
199
200
        $templating->expects($this->any())
201
            ->method('render')
202
            ->will($templatingRenderReturnCallback);
203
204
        $this->session = new Session(new MockArraySessionStorage());
205
206
        $twig = $this->getMockBuilder(Environment::class)
207
            ->disableOriginalConstructor()
208
            ->getMock();
209
210
        $twig->expects($this->any())
211
            ->method('getRuntime')
212
            ->willReturn($this->createMock(FormRenderer::class));
213
214
        // NEXT_MAJOR : require sonata/exporter ^1.7 and remove conditional
215
        if (class_exists(Exporter::class)) {
216
            $exporter = new Exporter([new JsonWriter('/tmp/sonataadmin/export.json')]);
217
        } else {
218
            $exporter = $this->createMock(SonataExporter::class);
219
220
            $exporter->expects($this->any())
221
                ->method('getResponse')
222
                ->willReturn(new StreamedResponse());
223
        }
224
225
        $this->auditManager = $this->getMockBuilder(AuditManager::class)
226
            ->disableOriginalConstructor()
227
            ->getMock();
228
229
        $this->adminObjectAclManipulator = $this->getMockBuilder(AdminObjectAclManipulator::class)
230
            ->disableOriginalConstructor()
231
            ->getMock();
232
233
        $this->csrfProvider = $this->getMockBuilder(CsrfTokenManagerInterface::class)
234
            ->getMock();
235
236
        $this->csrfProvider->expects($this->any())
237
            ->method('getToken')
238
            ->willReturnCallback(static function ($intention) {
239
                return new CsrfToken($intention, 'csrf-token-123_'.$intention);
240
            });
241
242
        $this->csrfProvider->expects($this->any())
243
            ->method('isTokenValid')
244
            ->willReturnCallback(static function (CsrfToken $token) {
245
                if ($token->getValue() === 'csrf-token-123_'.$token->getId()) {
246
                    return true;
247
                }
248
249
                return false;
250
            });
251
252
        $this->logger = $this->createMock(LoggerInterface::class);
253
254
        $requestStack = new RequestStack();
255
        $requestStack->push($this->request);
256
257
        $this->kernel = $this->createMock(KernelInterface::class);
258
259
        $this->container->expects($this->any())
260
            ->method('get')
261
            ->willReturnCallback(function ($id) use (
262
                $templating,
263
                $twig,
264
                $exporter,
265
                $requestStack
266
            ) {
267
                switch ($id) {
268
                    case 'sonata.admin.pool':
269
                        return $this->pool;
270
                    case 'request_stack':
271
                        return $requestStack;
272
                    case 'foo.admin':
273
                        return $this->admin;
274
                    case 'foo.admin.template_registry':
275
                        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...
276
                    case 'templating':
277
                        return $templating;
278
                    case 'twig':
279
                        return $twig;
280
                    case 'session':
281
                        return $this->session;
282
                    case 'sonata.admin.exporter':
283
                        return $exporter;
284
                    case 'sonata.admin.audit.manager':
285
                        return $this->auditManager;
286
                    case 'sonata.admin.object.manipulator.acl.admin':
287
                        return $this->adminObjectAclManipulator;
288
                    case 'security.csrf.token_manager':
289
                        return $this->csrfProvider;
290
                    case 'logger':
291
                        return $this->logger;
292
                    case 'kernel':
293
                        return $this->kernel;
294
                    case 'translator':
295
                        return $this->translator;
296
                }
297
            });
298
299
        $this->container->expects($this->any())
300
            ->method('has')
301
            ->willReturnCallback(function ($id) {
302
                if ('security.csrf.token_manager' === $id && null !== $this->getCsrfProvider()) {
303
                    return true;
304
                }
305
306
                if ('logger' === $id) {
307
                    return true;
308
                }
309
310
                if ('session' === $id) {
311
                    return true;
312
                }
313
314
                if ('templating' === $id) {
315
                    return true;
316
                }
317
318
                if ('translator' === $id) {
319
                    return true;
320
                }
321
322
                return false;
323
            });
324
325
        $this->container->expects($this->any())
326
            ->method('getParameter')
327
            ->willReturnCallback(static function ($name) {
328
                switch ($name) {
329
                    case 'security.role_hierarchy.roles':
330
                       return ['ROLE_SUPER_ADMIN' => ['ROLE_USER', 'ROLE_SONATA_ADMIN', 'ROLE_ADMIN']];
331
                }
332
            });
333
334
        $this->templateRegistry->getTemplate('ajax')->willReturn('@SonataAdmin/ajax_layout.html.twig');
335
        $this->templateRegistry->getTemplate('layout')->willReturn('@SonataAdmin/standard_layout.html.twig');
336
        $this->templateRegistry->getTemplate('show')->willReturn('@SonataAdmin/CRUD/show.html.twig');
337
        $this->templateRegistry->getTemplate('show_compare')->willReturn('@SonataAdmin/CRUD/show_compare.html.twig');
338
        $this->templateRegistry->getTemplate('edit')->willReturn('@SonataAdmin/CRUD/edit.html.twig');
339
        $this->templateRegistry->getTemplate('dashboard')->willReturn('@SonataAdmin/Core/dashboard.html.twig');
340
        $this->templateRegistry->getTemplate('search')->willReturn('@SonataAdmin/Core/search.html.twig');
341
        $this->templateRegistry->getTemplate('list')->willReturn('@SonataAdmin/CRUD/list.html.twig');
342
        $this->templateRegistry->getTemplate('preview')->willReturn('@SonataAdmin/CRUD/preview.html.twig');
343
        $this->templateRegistry->getTemplate('history')->willReturn('@SonataAdmin/CRUD/history.html.twig');
344
        $this->templateRegistry->getTemplate('acl')->willReturn('@SonataAdmin/CRUD/acl.html.twig');
345
        $this->templateRegistry->getTemplate('delete')->willReturn('@SonataAdmin/CRUD/delete.html.twig');
346
        $this->templateRegistry->getTemplate('batch')->willReturn('@SonataAdmin/CRUD/list__batch.html.twig');
347
        $this->templateRegistry->getTemplate('batch_confirmation')->willReturn('@SonataAdmin/CRUD/batch_confirmation.html.twig');
348
349
        // NEXT_MAJOR: Remove this call
350
        $this->admin->method('getTemplate')->willReturnMap([
351
            ['ajax', '@SonataAdmin/ajax_layout.html.twig'],
352
            ['layout', '@SonataAdmin/standard_layout.html.twig'],
353
            ['show', '@SonataAdmin/CRUD/show.html.twig'],
354
            ['show_compare', '@SonataAdmin/CRUD/show_compare.html.twig'],
355
            ['edit', '@SonataAdmin/CRUD/edit.html.twig'],
356
            ['dashboard', '@SonataAdmin/Core/dashboard.html.twig'],
357
            ['search', '@SonataAdmin/Core/search.html.twig'],
358
            ['list', '@SonataAdmin/CRUD/list.html.twig'],
359
            ['preview', '@SonataAdmin/CRUD/preview.html.twig'],
360
            ['history', '@SonataAdmin/CRUD/history.html.twig'],
361
            ['acl', '@SonataAdmin/CRUD/acl.html.twig'],
362
            ['delete', '@SonataAdmin/CRUD/delete.html.twig'],
363
            ['batch', '@SonataAdmin/CRUD/list__batch.html.twig'],
364
            ['batch_confirmation', '@SonataAdmin/CRUD/batch_confirmation.html.twig'],
365
        ]);
366
367
        $this->admin->expects($this->any())
368
            ->method('getIdParameter')
369
            ->willReturn('id');
370
371
        $this->admin->expects($this->any())
372
            ->method('getAccessMapping')
373
            ->willReturn([]);
374
375
        $this->admin->expects($this->any())
376
            ->method('generateUrl')
377
            ->willReturnCallback(
378
379
                    static function ($name, array $parameters = [], $absolute = false) {
0 ignored issues
show
Unused Code introduced by
The parameter $absolute is not used and could be removed.

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

Loading history...
380
                        $result = $name;
381
                        if (!empty($parameters)) {
382
                            $result .= '?'.http_build_query($parameters);
383
                        }
384
385
                        return $result;
386
                    }
387
388
            );
389
390
        $this->admin->expects($this->any())
391
            ->method('generateObjectUrl')
392
            ->willReturnCallback(
393
394
                    static function ($name, $object, array $parameters = [], $absolute = false) {
0 ignored issues
show
Unused Code introduced by
The parameter $absolute is not used and could be removed.

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

Loading history...
395
                        $result = \get_class($object).'_'.$name;
396
                        if (!empty($parameters)) {
397
                            $result .= '?'.http_build_query($parameters);
398
                        }
399
400
                        return $result;
401
                    }
402
403
            );
404
405
        $this->admin->expects($this->any())
406
            ->method('getCode')
407
            ->willReturn('foo.admin');
408
409
        $this->controller = new CRUDController();
410
        $this->controller->setContainer($this->container);
411
412
        // Make some methods public to test them
413
        $testedMethods = [
414
            'renderJson',
415
            'isXmlHttpRequest',
416
            'configure',
417
            'getBaseTemplate',
418
            'redirectTo',
419
            'addFlash',
420
        ];
421
        foreach ($testedMethods as $testedMethod) {
422
            // NEXT_MAJOR: Remove this check and only use CRUDController
423
            if (method_exists(CRUDController::class, $testedMethod)) {
424
                $method = new \ReflectionMethod(CRUDController::class, $testedMethod);
425
            } else {
426
                $method = new \ReflectionMethod(Controller::class, $testedMethod);
427
            }
428
429
            $method->setAccessible(true);
430
            $this->protectedTestedMethods[$testedMethod] = $method;
431
        }
432
    }
433
434
    public function testRenderJson1(): void
435
    {
436
        $data = ['example' => '123', 'foo' => 'bar'];
437
438
        $this->request->headers->set('Content-Type', 'application/x-www-form-urlencoded');
439
        $response = $this->protectedTestedMethods['renderJson']->invoke($this->controller, $data, 200, [], $this->request);
440
441
        $this->assertSame($response->headers->get('Content-Type'), 'application/json');
442
        $this->assertSame(json_encode($data), $response->getContent());
443
    }
444
445
    public function testRenderJson2(): void
446
    {
447
        $data = ['example' => '123', 'foo' => 'bar'];
448
449
        $this->request->headers->set('Content-Type', 'multipart/form-data');
450
        $response = $this->protectedTestedMethods['renderJson']->invoke($this->controller, $data, 200, [], $this->request);
451
452
        $this->assertSame($response->headers->get('Content-Type'), 'application/json');
453
        $this->assertSame(json_encode($data), $response->getContent());
454
    }
455
456
    public function testRenderJsonAjax(): void
457
    {
458
        $data = ['example' => '123', 'foo' => 'bar'];
459
460
        $this->request->attributes->set('_xml_http_request', true);
461
        $this->request->headers->set('Content-Type', 'multipart/form-data');
462
        $response = $this->protectedTestedMethods['renderJson']->invoke($this->controller, $data, 200, [], $this->request);
463
464
        $this->assertSame($response->headers->get('Content-Type'), 'application/json');
465
        $this->assertSame(json_encode($data), $response->getContent());
466
    }
467
468
    public function testIsXmlHttpRequest(): void
469
    {
470
        $this->assertFalse($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
471
472
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
473
474
        $this->assertTrue($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
475
476
        $this->request->headers->remove('X-Requested-With');
477
        $this->assertFalse($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
478
479
        $this->request->attributes->set('_xml_http_request', true);
480
        $this->assertTrue($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
481
    }
482
483
    public function testConfigure(): void
484
    {
485
        $uniqueId = '';
486
487
        $this->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...
488
            ->method('setUniqid')
489
            ->willReturnCallback(static function ($uniqid) use (&$uniqueId): void {
490
                $uniqueId = $uniqid;
491
            });
492
493
        $this->request->query->set('uniqid', 123456);
494
        $this->protectedTestedMethods['configure']->invoke($this->controller);
495
496
        $this->assertSame(123456, $uniqueId);
497
        $this->assertAttributeSame($this->admin, 'admin', $this->controller);
498
    }
499
500
    public function testConfigureChild(): void
501
    {
502
        $uniqueId = '';
503
504
        $this->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...
505
            ->method('setUniqid')
506
            ->willReturnCallback(static function ($uniqid) use (&$uniqueId): void {
507
                $uniqueId = $uniqid;
508
            });
509
510
        $this->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...
511
            ->method('isChild')
512
            ->willReturn(true);
513
514
        $adminParent = $this->getMockBuilder(AdminInterface::class)
515
            ->disableOriginalConstructor()
516
            ->getMock();
517
        $this->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...
518
            ->method('getParent')
519
            ->willReturn($adminParent);
520
521
        $this->request->query->set('uniqid', 123456);
522
        $this->protectedTestedMethods['configure']->invoke($this->controller);
523
524
        $this->assertSame(123456, $uniqueId);
525
        $this->assertAttributeInstanceOf(\get_class($adminParent), 'admin', $this->controller);
526
    }
527
528
    public function testConfigureWithException(): void
529
    {
530
        $this->expectException(
531
            \RuntimeException::class,
532
            'There is no `_sonata_admin` defined for the controller `Sonata\AdminBundle\Controller\CRUDController`'
533
        );
534
535
        $this->request->attributes->remove('_sonata_admin');
536
        $this->protectedTestedMethods['configure']->invoke($this->controller);
537
    }
538
539
    public function testConfigureWithException2(): void
540
    {
541
        $this->expectException(
542
            \InvalidArgumentException::class,
543
            'Found service "nonexistent.admin" is not a valid admin service'
544
        );
545
546
        $this->pool->setAdminServiceIds(['nonexistent.admin']);
547
        $this->request->attributes->set('_sonata_admin', 'nonexistent.admin');
548
        $this->protectedTestedMethods['configure']->invoke($this->controller);
549
    }
550
551
    public function testGetBaseTemplate(): void
552
    {
553
        $this->assertSame(
554
            '@SonataAdmin/standard_layout.html.twig',
555
            $this->protectedTestedMethods['getBaseTemplate']->invoke($this->controller, $this->request)
556
        );
557
558
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
559
        $this->assertSame(
560
            '@SonataAdmin/ajax_layout.html.twig',
561
            $this->protectedTestedMethods['getBaseTemplate']->invoke($this->controller, $this->request)
562
        );
563
564
        $this->request->headers->remove('X-Requested-With');
565
        $this->assertSame(
566
            '@SonataAdmin/standard_layout.html.twig',
567
            $this->protectedTestedMethods['getBaseTemplate']->invoke($this->controller, $this->request)
568
        );
569
570
        $this->request->attributes->set('_xml_http_request', true);
571
        $this->assertSame(
572
            '@SonataAdmin/ajax_layout.html.twig',
573
            $this->protectedTestedMethods['getBaseTemplate']->invoke($this->controller, $this->request)
574
        );
575
    }
576
577
    public function testRender(): void
578
    {
579
        $this->parameters = [];
580
        $this->assertInstanceOf(
581
            Response::class,
582
            $this->controller->renderWithExtraParams('@FooAdmin/foo.html.twig', [], null)
583
        );
584
        $this->assertSame($this->admin, $this->parameters['admin']);
585
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
586
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
587
        $this->assertSame('@FooAdmin/foo.html.twig', $this->template);
588
    }
589
590
    public function testRenderWithResponse(): void
591
    {
592
        $this->parameters = [];
593
        $response = $response = new Response();
594
        $response->headers->set('X-foo', 'bar');
595
        $responseResult = $this->controller->renderWithExtraParams('@FooAdmin/foo.html.twig', [], $response);
596
597
        $this->assertSame($response, $responseResult);
598
        $this->assertSame('bar', $responseResult->headers->get('X-foo'));
599
        $this->assertSame($this->admin, $this->parameters['admin']);
600
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
601
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
602
        $this->assertSame('@FooAdmin/foo.html.twig', $this->template);
603
    }
604
605
    public function testRenderCustomParams(): void
606
    {
607
        $this->parameters = [];
608
        $this->assertInstanceOf(
609
            Response::class,
610
            $this->controller->renderWithExtraParams(
611
                '@FooAdmin/foo.html.twig',
612
                ['foo' => 'bar'],
613
                null
614
            )
615
        );
616
        $this->assertSame($this->admin, $this->parameters['admin']);
617
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
618
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
619
        $this->assertSame('bar', $this->parameters['foo']);
620
        $this->assertSame('@FooAdmin/foo.html.twig', $this->template);
621
    }
622
623
    public function testRenderAjax(): void
624
    {
625
        $this->parameters = [];
626
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
627
        $this->assertInstanceOf(
628
            Response::class,
629
            $this->controller->renderWithExtraParams(
630
                '@FooAdmin/foo.html.twig',
631
                ['foo' => 'bar'],
632
                null
633
            )
634
        );
635
        $this->assertSame($this->admin, $this->parameters['admin']);
636
        $this->assertSame('@SonataAdmin/ajax_layout.html.twig', $this->parameters['base_template']);
637
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
638
        $this->assertSame('bar', $this->parameters['foo']);
639
        $this->assertSame('@FooAdmin/foo.html.twig', $this->template);
640
    }
641
642
    public function testListActionAccessDenied(): void
643
    {
644
        $this->expectException(AccessDeniedException::class);
645
646
        $this->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...
647
            ->method('checkAccess')
648
            ->with($this->equalTo('list'))
649
            ->will($this->throwException(new AccessDeniedException()));
650
651
        $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...
652
    }
653
654
    public function testPreList(): void
655
    {
656
        $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...
657
            ->method('hasRoute')
658
            ->with($this->equalTo('list'))
659
            ->willReturn(true);
660
661
        $this->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...
662
            ->method('checkAccess')
663
            ->with($this->equalTo('list'))
664
            ->willReturn(true);
665
666
        $controller = new PreCRUDController();
667
        $controller->setContainer($this->container);
668
669
        $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...
670
        $this->assertInstanceOf(Response::class, $response);
671
        $this->assertSame('preList called', $response->getContent());
672
    }
673
674
    public function testListAction(): void
675
    {
676
        $datagrid = $this->createMock(DatagridInterface::class);
677
678
        $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...
679
            ->method('hasRoute')
680
            ->with($this->equalTo('list'))
681
            ->willReturn(true);
682
683
        $this->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...
684
            ->method('checkAccess')
685
            ->with($this->equalTo('list'))
686
            ->willReturn(true);
687
688
        $form = $this->getMockBuilder(Form::class)
689
            ->disableOriginalConstructor()
690
            ->getMock();
691
692
        $form->expects($this->once())
693
            ->method('createView')
694
            ->willReturn($this->createMock(FormView::class));
695
696
        $this->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...
697
            ->method('getDatagrid')
698
            ->willReturn($datagrid);
699
700
        $datagrid->expects($this->once())
701
            ->method('getForm')
702
            ->willReturn($form);
703
704
        $this->parameters = [];
705
        $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...
706
707
        $this->assertSame($this->admin, $this->parameters['admin']);
708
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
709
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
710
711
        $this->assertSame('list', $this->parameters['action']);
712
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
713
        $this->assertInstanceOf(DatagridInterface::class, $this->parameters['datagrid']);
714
        $this->assertSame('csrf-token-123_sonata.batch', $this->parameters['csrf_token']);
715
        $this->assertSame([], $this->session->getFlashBag()->all());
716
        $this->assertSame('@SonataAdmin/CRUD/list.html.twig', $this->template);
717
    }
718
719
    public function testBatchActionDeleteAccessDenied(): void
720
    {
721
        $this->expectException(AccessDeniedException::class);
722
723
        $this->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...
724
            ->method('checkAccess')
725
            ->with($this->equalTo('batchDelete'))
726
            ->will($this->throwException(new AccessDeniedException()));
727
728
        $this->controller->batchActionDelete($this->createMock(ProxyQueryInterface::class));
729
    }
730
731
    public function testBatchActionDelete(): void
732
    {
733
        $modelManager = $this->createMock(ModelManagerInterface::class);
734
735
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
736
            ->method('checkAccess')
737
            ->with($this->equalTo('batchDelete'))
738
            ->willReturn(true);
739
740
        $this->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...
741
            ->method('getModelManager')
742
            ->willReturn($modelManager);
743
744
        $this->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...
745
            ->method('getFilterParameters')
746
            ->willReturn(['foo' => 'bar']);
747
748
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
749
750
        $result = $this->controller->batchActionDelete($this->createMock(ProxyQueryInterface::class));
751
752
        $this->assertInstanceOf(RedirectResponse::class, $result);
753
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
754
        $this->assertSame('list?filter%5Bfoo%5D=bar', $result->getTargetUrl());
755
    }
756
757
    public function testBatchActionDeleteWithModelManagerException(): void
758
    {
759
        $modelManager = $this->createMock(ModelManagerInterface::class);
760
        $this->assertLoggerLogsModelManagerException($modelManager, 'batchDelete');
761
762
        $this->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...
763
            ->method('getModelManager')
764
            ->willReturn($modelManager);
765
766
        $this->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...
767
            ->method('getFilterParameters')
768
            ->willReturn(['foo' => 'bar']);
769
770
        $this->expectTranslate('flash_batch_delete_error', [], 'SonataAdminBundle');
771
772
        $result = $this->controller->batchActionDelete($this->createMock(ProxyQueryInterface::class));
773
774
        $this->assertInstanceOf(RedirectResponse::class, $result);
775
        $this->assertSame(['flash_batch_delete_error'], $this->session->getFlashBag()->get('sonata_flash_error'));
776
        $this->assertSame('list?filter%5Bfoo%5D=bar', $result->getTargetUrl());
777
    }
778
779
    public function testBatchActionDeleteWithModelManagerExceptionInDebugMode(): void
780
    {
781
        $modelManager = $this->createMock(ModelManagerInterface::class);
782
        $this->expectException(ModelManagerException::class);
783
784
        $modelManager->expects($this->once())
785
            ->method('batchDelete')
786
            ->willReturnCallback(static function (): void {
787
                throw new ModelManagerException();
788
            });
789
790
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
791
            ->method('getModelManager')
792
            ->willReturn($modelManager);
793
794
        $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...
795
            ->method('isDebug')
796
            ->willReturn(true);
797
798
        $this->controller->batchActionDelete($this->createMock(ProxyQueryInterface::class));
799
    }
800
801
    public function testShowActionNotFoundException(): void
802
    {
803
        $this->expectException(NotFoundHttpException::class);
804
805
        $this->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...
806
            ->method('getObject')
807
            ->willReturn(false);
808
809
        $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...
810
    }
811
812
    public function testShowActionAccessDenied(): void
813
    {
814
        $this->expectException(AccessDeniedException::class);
815
816
        $this->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...
817
            ->method('getObject')
818
            ->willReturn(new \stdClass());
819
820
        $this->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...
821
            ->method('checkAccess')
822
            ->with($this->equalTo('show'))
823
            ->will($this->throwException(new AccessDeniedException()));
824
825
        $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...
826
    }
827
828
    /**
829
     * @group legacy
830
     * @expectedDeprecation Calling this method without implementing "configureShowFields" is not supported since 3.40.0 and will no longer be possible in 4.0
831
     */
832
    public function testShowActionDeprecation(): void
833
    {
834
        $object = new \stdClass();
835
836
        $this->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...
837
            ->method('getObject')
838
            ->willReturn($object);
839
840
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
841
            ->method('checkAccess')
842
            ->with($this->equalTo('show'))
843
            ->willReturn(true);
844
845
        $show = $this->createMock(FieldDescriptionCollection::class);
846
847
        $this->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...
848
            ->method('getShow')
849
            ->willReturn($show);
850
851
        $show->expects($this->once())
852
            ->method('getElements')
853
            ->willReturn([]);
854
855
        $show->expects($this->once())
856
            ->method('count')
857
            ->willReturn(0);
858
859
        $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...
860
    }
861
862
    public function testPreShow(): void
863
    {
864
        $object = new \stdClass();
865
        $object->foo = 123456;
866
867
        $this->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...
868
            ->method('getObject')
869
            ->willReturn($object);
870
871
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
872
            ->method('checkAccess')
873
            ->with($this->equalTo('show'))
874
            ->willReturn(true);
875
876
        $controller = new PreCRUDController();
877
        $controller->setContainer($this->container);
878
879
        $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...
880
        $this->assertInstanceOf(Response::class, $response);
881
        $this->assertSame('preShow called: 123456', $response->getContent());
882
    }
883
884
    public function testShowAction(): void
885
    {
886
        $object = new \stdClass();
887
888
        $this->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...
889
            ->method('getObject')
890
            ->willReturn($object);
891
892
        $this->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...
893
            ->method('checkAccess')
894
            ->with($this->equalTo('show'))
895
            ->willReturn(true);
896
897
        $show = $this->createMock(FieldDescriptionCollection::class);
898
899
        $this->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...
900
            ->method('getShow')
901
            ->willReturn($show);
902
903
        $show->expects($this->once())
904
            ->method('getElements')
905
            ->willReturn(['field' => 'fielddata']);
906
907
        $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...
908
909
        $this->assertSame($this->admin, $this->parameters['admin']);
910
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
911
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
912
913
        $this->assertSame('show', $this->parameters['action']);
914
        $this->assertInstanceOf(FieldDescriptionCollection::class, $this->parameters['elements']);
915
        $this->assertSame($object, $this->parameters['object']);
916
917
        $this->assertSame([], $this->session->getFlashBag()->all());
918
        $this->assertSame('@SonataAdmin/CRUD/show.html.twig', $this->template);
919
    }
920
921
    /**
922
     * @dataProvider getRedirectToTests
923
     */
924
    public function testRedirectTo($expected, $route, $queryParams, $requestParams, $hasActiveSubclass): void
925
    {
926
        $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...
927
            ->method('hasActiveSubclass')
928
            ->willReturn($hasActiveSubclass);
929
930
        $object = new \stdClass();
931
932
        foreach ($queryParams as $key => $value) {
933
            $this->request->query->set($key, $value);
934
        }
935
936
        foreach ($requestParams as $key => $value) {
937
            $this->request->request->set($key, $value);
938
        }
939
940
        $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...
941
            ->method('hasRoute')
942
            ->with($this->equalTo($route))
943
            ->willReturn(true);
944
945
        $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...
946
            ->method('hasAccess')
947
            ->with($this->equalTo($route))
948
            ->willReturn(true);
949
950
        $response = $this->protectedTestedMethods['redirectTo']->invoke($this->controller, $object, $this->request);
951
        $this->assertInstanceOf(RedirectResponse::class, $response);
952
        $this->assertSame($expected, $response->getTargetUrl());
953
    }
954
955
    public function testRedirectToWithObject(): void
956
    {
957
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
958
            ->method('hasActiveSubclass')
959
            ->willReturn(false);
960
961
        $object = new \stdClass();
962
963
        $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...
964
            ->method('hasRoute')
965
            ->with($this->equalTo('edit'))
966
            ->willReturn(true);
967
968
        $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...
969
            ->method('hasAccess')
970
            ->with($this->equalTo('edit'), $object)
971
            ->willReturn(false);
972
973
        $response = $this->protectedTestedMethods['redirectTo']->invoke($this->controller, $object, $this->request);
974
        $this->assertInstanceOf(RedirectResponse::class, $response);
975
        $this->assertSame('list', $response->getTargetUrl());
976
    }
977
978
    public function getRedirectToTests()
979
    {
980
        return [
981
            ['stdClass_edit', 'edit', [], [], false],
982
            ['list', 'list', ['btn_update_and_list' => true], [], false],
983
            ['list', 'list', ['btn_create_and_list' => true], [], false],
984
            ['create', 'create', ['btn_create_and_create' => true], [], false],
985
            ['create?subclass=foo', 'create', ['btn_create_and_create' => true, 'subclass' => 'foo'], [], true],
986
            ['stdClass_edit?_tab=first_tab', 'edit', ['btn_update_and_edit' => true], ['_tab' => 'first_tab'], false],
987
        ];
988
    }
989
990
    public function testDeleteActionNotFoundException(): void
991
    {
992
        $this->expectException(NotFoundHttpException::class);
993
994
        $this->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...
995
            ->method('getObject')
996
            ->willReturn(false);
997
998
        $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...
999
    }
1000
1001
    public function testDeleteActionAccessDenied(): void
1002
    {
1003
        $this->expectException(AccessDeniedException::class);
1004
1005
        $this->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...
1006
            ->method('getObject')
1007
            ->willReturn(new \stdClass());
1008
1009
        $this->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...
1010
            ->method('checkAccess')
1011
            ->with($this->equalTo('delete'))
1012
            ->will($this->throwException(new AccessDeniedException()));
1013
1014
        $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...
1015
    }
1016
1017
    public function testPreDelete(): void
1018
    {
1019
        $object = new \stdClass();
1020
        $object->foo = 123456;
1021
1022
        $this->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...
1023
            ->method('getObject')
1024
            ->willReturn($object);
1025
1026
        $this->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...
1027
            ->method('checkAccess')
1028
            ->with($this->equalTo('delete'))
1029
            ->willReturn(true);
1030
1031
        $controller = new PreCRUDController();
1032
        $controller->setContainer($this->container);
1033
1034
        $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...
1035
        $this->assertInstanceOf(Response::class, $response);
1036
        $this->assertSame('preDelete called: 123456', $response->getContent());
1037
    }
1038
1039
    public function testDeleteAction(): void
1040
    {
1041
        $object = new \stdClass();
1042
1043
        $this->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...
1044
            ->method('getObject')
1045
            ->willReturn($object);
1046
1047
        $this->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...
1048
            ->method('checkAccess')
1049
            ->with($this->equalTo('delete'))
1050
            ->willReturn(true);
1051
1052
        $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...
1053
1054
        $this->assertSame($this->admin, $this->parameters['admin']);
1055
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1056
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1057
1058
        $this->assertSame('delete', $this->parameters['action']);
1059
        $this->assertSame($object, $this->parameters['object']);
1060
        $this->assertSame('csrf-token-123_sonata.delete', $this->parameters['csrf_token']);
1061
1062
        $this->assertSame([], $this->session->getFlashBag()->all());
1063
        $this->assertSame('@SonataAdmin/CRUD/delete.html.twig', $this->template);
1064
    }
1065
1066
    public function testDeleteActionNoCsrfToken(): void
1067
    {
1068
        $this->csrfProvider = null;
1069
1070
        $object = new \stdClass();
1071
1072
        $this->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...
1073
            ->method('getObject')
1074
            ->willReturn($object);
1075
1076
        $this->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...
1077
            ->method('checkAccess')
1078
            ->with($this->equalTo('delete'))
1079
            ->willReturn(true);
1080
1081
        $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...
1082
1083
        $this->assertSame($this->admin, $this->parameters['admin']);
1084
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1085
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1086
1087
        $this->assertSame('delete', $this->parameters['action']);
1088
        $this->assertSame($object, $this->parameters['object']);
1089
        $this->assertFalse($this->parameters['csrf_token']);
1090
1091
        $this->assertSame([], $this->session->getFlashBag()->all());
1092
        $this->assertSame('@SonataAdmin/CRUD/delete.html.twig', $this->template);
1093
    }
1094
1095
    public function testDeleteActionAjaxSuccess1(): void
1096
    {
1097
        $object = new \stdClass();
1098
1099
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1100
            ->method('getObject')
1101
            ->willReturn($object);
1102
1103
        $this->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...
1104
            ->method('checkAccess')
1105
            ->with($this->equalTo('delete'))
1106
            ->willReturn(true);
1107
1108
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
1109
            ->method('getOption')
1110
            ->with('csrf_protection')
1111
            ->willReturn(true);
1112
1113
        $this->request->setMethod('DELETE');
1114
1115
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1116
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1117
1118
        $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...
1119
1120
        $this->assertInstanceOf(Response::class, $response);
1121
        $this->assertSame(json_encode(['result' => 'ok']), $response->getContent());
1122
        $this->assertSame([], $this->session->getFlashBag()->all());
1123
    }
1124
1125
    public function testDeleteActionAjaxSuccess2(): void
1126
    {
1127
        $object = new \stdClass();
1128
1129
        $this->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...
1130
            ->method('getObject')
1131
            ->willReturn($object);
1132
1133
        $this->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...
1134
            ->method('checkAccess')
1135
            ->with($this->equalTo('delete'))
1136
            ->willReturn(true);
1137
1138
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
1139
            ->method('getOption')
1140
            ->with('csrf_protection')
1141
            ->willReturn(true);
1142
1143
        $this->request->setMethod('POST');
1144
        $this->request->request->set('_method', 'DELETE');
1145
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1146
1147
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1148
1149
        $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...
1150
1151
        $this->assertInstanceOf(Response::class, $response);
1152
        $this->assertSame(json_encode(['result' => 'ok']), $response->getContent());
1153
        $this->assertSame([], $this->session->getFlashBag()->all());
1154
    }
1155
1156
    public function testDeleteActionAjaxError(): void
1157
    {
1158
        $object = new \stdClass();
1159
1160
        $this->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...
1161
            ->method('getObject')
1162
            ->willReturn($object);
1163
1164
        $this->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...
1165
            ->method('checkAccess')
1166
            ->with($this->equalTo('delete'))
1167
            ->willReturn(true);
1168
1169
        $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...
1170
            ->method('getClass')
1171
            ->willReturn('stdClass');
1172
1173
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
1174
            ->method('getOption')
1175
            ->with('csrf_protection')
1176
            ->willReturn(true);
1177
1178
        $this->assertLoggerLogsModelManagerException($this->admin, 'delete');
1179
1180
        $this->request->setMethod('DELETE');
1181
1182
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1183
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1184
1185
        $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...
1186
1187
        $this->assertInstanceOf(Response::class, $response);
1188
        $this->assertSame(json_encode(['result' => 'error']), $response->getContent());
1189
        $this->assertSame([], $this->session->getFlashBag()->all());
1190
    }
1191
1192
    public function testDeleteActionWithModelManagerExceptionInDebugMode(): void
1193
    {
1194
        $this->expectException(ModelManagerException::class);
1195
1196
        $object = new \stdClass();
1197
1198
        $this->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...
1199
            ->method('getObject')
1200
            ->willReturn($object);
1201
1202
        $this->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...
1203
            ->method('checkAccess')
1204
            ->with($this->equalTo('delete'))
1205
            ->willReturn(true);
1206
1207
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
1208
            ->method('getOption')
1209
            ->with('csrf_protection')
1210
            ->willReturn(true);
1211
1212
        $this->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...
1213
            ->method('delete')
1214
            ->willReturnCallback(static function (): void {
1215
                throw new ModelManagerException();
1216
            });
1217
1218
        $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...
1219
            ->method('isDebug')
1220
            ->willReturn(true);
1221
1222
        $this->request->setMethod('DELETE');
1223
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1224
1225
        $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...
1226
    }
1227
1228
    /**
1229
     * @dataProvider getToStringValues
1230
     */
1231
    public function testDeleteActionSuccess1($expectedToStringValue, $toStringValue): void
1232
    {
1233
        $object = new \stdClass();
1234
1235
        $this->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...
1236
            ->method('getObject')
1237
            ->willReturn($object);
1238
1239
        $this->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...
1240
            ->method('toString')
1241
            ->with($this->equalTo($object))
1242
            ->willReturn($toStringValue);
1243
1244
        $this->expectTranslate('flash_delete_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1245
1246
        $this->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...
1247
            ->method('checkAccess')
1248
            ->with($this->equalTo('delete'))
1249
            ->willReturn(true);
1250
1251
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
1252
            ->method('getOption')
1253
            ->with('csrf_protection')
1254
            ->willReturn(true);
1255
1256
        $this->request->setMethod('DELETE');
1257
1258
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1259
1260
        $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...
1261
1262
        $this->assertInstanceOf(RedirectResponse::class, $response);
1263
        $this->assertSame(['flash_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1264
        $this->assertSame('list', $response->getTargetUrl());
1265
    }
1266
1267
    /**
1268
     * @dataProvider getToStringValues
1269
     */
1270
    public function testDeleteActionSuccess2($expectedToStringValue, $toStringValue): void
1271
    {
1272
        $object = new \stdClass();
1273
1274
        $this->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...
1275
            ->method('getObject')
1276
            ->willReturn($object);
1277
1278
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1279
            ->method('checkAccess')
1280
            ->with($this->equalTo('delete'))
1281
            ->willReturn(true);
1282
1283
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1284
            ->method('toString')
1285
            ->with($this->equalTo($object))
1286
            ->willReturn($toStringValue);
1287
1288
        $this->expectTranslate('flash_delete_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1289
1290
        $this->request->setMethod('POST');
1291
        $this->request->request->set('_method', 'DELETE');
1292
1293
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1294
1295
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
1296
            ->method('getOption')
1297
            ->with('csrf_protection')
1298
            ->willReturn(true);
1299
1300
        $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...
1301
1302
        $this->assertInstanceOf(RedirectResponse::class, $response);
1303
        $this->assertSame(['flash_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1304
        $this->assertSame('list', $response->getTargetUrl());
1305
    }
1306
1307
    /**
1308
     * @dataProvider getToStringValues
1309
     */
1310
    public function testDeleteActionSuccessNoCsrfTokenProvider($expectedToStringValue, $toStringValue): void
1311
    {
1312
        $this->csrfProvider = null;
1313
1314
        $object = new \stdClass();
1315
1316
        $this->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...
1317
            ->method('getObject')
1318
            ->willReturn($object);
1319
1320
        $this->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...
1321
            ->method('checkAccess')
1322
            ->with($this->equalTo('delete'))
1323
            ->willReturn(true);
1324
1325
        $this->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...
1326
            ->method('toString')
1327
            ->with($this->equalTo($object))
1328
            ->willReturn($toStringValue);
1329
1330
        $this->expectTranslate('flash_delete_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1331
1332
        $this->request->setMethod('POST');
1333
        $this->request->request->set('_method', 'DELETE');
1334
1335
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

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

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

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

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

Loading history...
1341
1342
        $this->assertInstanceOf(RedirectResponse::class, $response);
1343
        $this->assertSame(['flash_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1344
        $this->assertSame('list', $response->getTargetUrl());
1345
    }
1346
1347
    public function testDeleteActionWrongRequestMethod(): void
1348
    {
1349
        $object = new \stdClass();
1350
1351
        $this->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...
1352
            ->method('getObject')
1353
            ->willReturn($object);
1354
1355
        $this->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...
1356
            ->method('checkAccess')
1357
            ->with($this->equalTo('delete'))
1358
            ->willReturn(true);
1359
1360
        //without POST request parameter "_method" should not be used as real REST method
1361
        $this->request->query->set('_method', 'DELETE');
1362
1363
        $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...
1364
1365
        $this->assertSame($this->admin, $this->parameters['admin']);
1366
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1367
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1368
1369
        $this->assertSame('delete', $this->parameters['action']);
1370
        $this->assertSame($object, $this->parameters['object']);
1371
        $this->assertSame('csrf-token-123_sonata.delete', $this->parameters['csrf_token']);
1372
1373
        $this->assertSame([], $this->session->getFlashBag()->all());
1374
        $this->assertSame('@SonataAdmin/CRUD/delete.html.twig', $this->template);
1375
    }
1376
1377
    /**
1378
     * @dataProvider getToStringValues
1379
     */
1380
    public function testDeleteActionError($expectedToStringValue, $toStringValue): 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
            ->willReturn($object);
1387
1388
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1389
            ->method('checkAccess')
1390
            ->with($this->equalTo('delete'))
1391
            ->willReturn(true);
1392
1393
        $this->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...
1394
            ->method('toString')
1395
            ->with($this->equalTo($object))
1396
            ->willReturn($toStringValue);
1397
1398
        $this->expectTranslate('flash_delete_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1399
1400
        $this->assertLoggerLogsModelManagerException($this->admin, 'delete');
1401
1402
        $this->request->setMethod('DELETE');
1403
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1404
1405
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
1406
            ->method('getOption')
1407
            ->with('csrf_protection')
1408
            ->willReturn(true);
1409
1410
        $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...
1411
1412
        $this->assertInstanceOf(RedirectResponse::class, $response);
1413
        $this->assertSame(['flash_delete_error'], $this->session->getFlashBag()->get('sonata_flash_error'));
1414
        $this->assertSame('list', $response->getTargetUrl());
1415
    }
1416
1417
    public function testDeleteActionInvalidCsrfToken(): void
1418
    {
1419
        $object = new \stdClass();
1420
1421
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1422
            ->method('getObject')
1423
            ->willReturn($object);
1424
1425
        $this->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...
1426
            ->method('checkAccess')
1427
            ->with($this->equalTo('delete'))
1428
            ->willReturn(true);
1429
1430
        $this->request->setMethod('POST');
1431
        $this->request->request->set('_method', 'DELETE');
1432
        $this->request->request->set('_sonata_csrf_token', 'CSRF-INVALID');
1433
1434
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
1435
            ->method('getOption')
1436
            ->with('csrf_protection')
1437
            ->willReturn(true);
1438
1439
        try {
1440
            $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...
1441
        } catch (HttpException $e) {
1442
            $this->assertSame('The csrf token is not valid, CSRF attack?', $e->getMessage());
1443
            $this->assertSame(400, $e->getStatusCode());
1444
        }
1445
    }
1446
1447
    public function testDeleteActionWithDisabledCsrfProtection(): void
1448
    {
1449
        $object = new \stdClass();
1450
1451
        $this->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...
1452
            ->method('getObject')
1453
            ->willReturn($object);
1454
1455
        $this->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...
1456
            ->method('checkAccess')
1457
            ->with($this->equalTo('delete'))
1458
            ->willReturn(true);
1459
1460
        $this->request->setMethod('POST');
1461
        $this->request->request->set('_method', 'DELETE');
1462
1463
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

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

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

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

Loading history...
1469
            ->method('toString')
1470
            ->with($object)
1471
            ->willReturn(\stdClass::class);
1472
1473
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1474
            ->method('delete')
1475
            ->with($object);
1476
1477
        $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...
1478
    }
1479
1480
    public function testEditActionNotFoundException(): void
1481
    {
1482
        $this->expectException(NotFoundHttpException::class);
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
            ->willReturn(false);
1487
1488
        $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...
1489
    }
1490
1491
    public function testEditActionRuntimeException(): void
1492
    {
1493
        $this->expectException(\RuntimeException::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('getObject')
1497
            ->willReturn(new \stdClass());
1498
1499
        $this->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...
1500
            ->method('checkAccess')
1501
            ->with($this->equalTo('edit'))
1502
            ->willReturn(true);
1503
1504
        $form = $this->createMock(Form::class);
1505
1506
        $this->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...
1507
            ->method('getForm')
1508
            ->willReturn($form);
1509
1510
        $form->expects($this->once())
1511
            ->method('all')
1512
            ->willReturn([]);
1513
1514
        $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...
1515
    }
1516
1517
    public function testEditActionAccessDenied(): void
1518
    {
1519
        $this->expectException(AccessDeniedException::class);
1520
1521
        $this->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...
1522
            ->method('getObject')
1523
            ->willReturn(new \stdClass());
1524
1525
        $this->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...
1526
            ->method('checkAccess')
1527
            ->with($this->equalTo('edit'))
1528
            ->will($this->throwException(new AccessDeniedException()));
1529
1530
        $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...
1531
    }
1532
1533
    public function testPreEdit(): void
1534
    {
1535
        $object = new \stdClass();
1536
        $object->foo = 123456;
1537
1538
        $this->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...
1539
            ->method('getObject')
1540
            ->willReturn($object);
1541
1542
        $this->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...
1543
            ->method('checkAccess')
1544
            ->with($this->equalTo('edit'))
1545
            ->willReturn(true);
1546
1547
        $controller = new PreCRUDController();
1548
        $controller->setContainer($this->container);
1549
1550
        $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...
1551
        $this->assertInstanceOf(Response::class, $response);
1552
        $this->assertSame('preEdit called: 123456', $response->getContent());
1553
    }
1554
1555
    public function testEditAction(): void
1556
    {
1557
        $object = new \stdClass();
1558
1559
        $this->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...
1560
            ->method('getObject')
1561
            ->willReturn($object);
1562
1563
        $this->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...
1564
            ->method('checkAccess')
1565
            ->with($this->equalTo('edit'))
1566
            ->willReturn(true);
1567
1568
        $form = $this->createMock(Form::class);
1569
1570
        $this->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...
1571
            ->method('getForm')
1572
            ->willReturn($form);
1573
1574
        $formView = $this->createMock(FormView::class);
1575
1576
        $form->expects($this->any())
1577
            ->method('createView')
1578
            ->willReturn($formView);
1579
1580
        $form->expects($this->once())
1581
            ->method('all')
1582
            ->willReturn(['field' => 'fielddata']);
1583
1584
        $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...
1585
1586
        $this->assertSame($this->admin, $this->parameters['admin']);
1587
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1588
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1589
1590
        $this->assertSame('edit', $this->parameters['action']);
1591
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1592
        $this->assertSame($object, $this->parameters['object']);
1593
        $this->assertSame([], $this->session->getFlashBag()->all());
1594
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1595
    }
1596
1597
    /**
1598
     * @dataProvider getToStringValues
1599
     */
1600
    public function testEditActionSuccess($expectedToStringValue, $toStringValue): void
1601
    {
1602
        $object = new \stdClass();
1603
1604
        $this->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...
1605
            ->method('getObject')
1606
            ->willReturn($object);
1607
1608
        $this->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...
1609
            ->method('update')
1610
            ->willReturnArgument(0);
1611
1612
        $this->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...
1613
            ->method('checkAccess')
1614
            ->with($this->equalTo('edit'));
1615
1616
        $this->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...
1617
            ->method('hasRoute')
1618
            ->with($this->equalTo('edit'))
1619
            ->willReturn(true);
1620
1621
        $this->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...
1622
            ->method('hasAccess')
1623
            ->with($this->equalTo('edit'))
1624
            ->willReturn(true);
1625
1626
        $form = $this->createMock(Form::class);
1627
1628
        $form->expects($this->once())
1629
            ->method('getData')
1630
            ->willReturn($object);
1631
1632
        $this->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...
1633
            ->method('getForm')
1634
            ->willReturn($form);
1635
1636
        $form->expects($this->once())
1637
            ->method('isSubmitted')
1638
            ->willReturn(true);
1639
1640
        $form->expects($this->once())
1641
            ->method('isValid')
1642
            ->willReturn(true);
1643
1644
        $form->expects($this->once())
1645
            ->method('all')
1646
            ->willReturn(['field' => 'fielddata']);
1647
1648
        $this->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...
1649
            ->method('toString')
1650
            ->with($this->equalTo($object))
1651
            ->willReturn($toStringValue);
1652
1653
        $this->expectTranslate('flash_edit_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1654
1655
        $this->request->setMethod('POST');
1656
1657
        $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...
1658
1659
        $this->assertInstanceOf(RedirectResponse::class, $response);
1660
        $this->assertSame(['flash_edit_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1661
        $this->assertSame('stdClass_edit', $response->getTargetUrl());
1662
    }
1663
1664
    /**
1665
     * @dataProvider getToStringValues
1666
     */
1667
    public function testEditActionError($expectedToStringValue, $toStringValue): void
1668
    {
1669
        $object = new \stdClass();
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('getObject')
1673
            ->willReturn($object);
1674
1675
        $this->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...
1676
            ->method('checkAccess')
1677
            ->with($this->equalTo('edit'))
1678
            ->willReturn(true);
1679
1680
        $form = $this->createMock(Form::class);
1681
1682
        $this->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...
1683
            ->method('getForm')
1684
            ->willReturn($form);
1685
1686
        $form->expects($this->once())
1687
            ->method('isSubmitted')
1688
            ->willReturn(true);
1689
1690
        $form->expects($this->once())
1691
            ->method('isValid')
1692
            ->willReturn(false);
1693
1694
        $form->expects($this->once())
1695
            ->method('all')
1696
            ->willReturn(['field' => 'fielddata']);
1697
1698
        $this->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...
1699
            ->method('toString')
1700
            ->with($this->equalTo($object))
1701
            ->willReturn($toStringValue);
1702
1703
        $this->expectTranslate('flash_edit_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1704
1705
        $this->request->setMethod('POST');
1706
1707
        $formView = $this->createMock(FormView::class);
1708
1709
        $form->expects($this->any())
1710
            ->method('createView')
1711
            ->willReturn($formView);
1712
1713
        $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...
1714
1715
        $this->assertSame($this->admin, $this->parameters['admin']);
1716
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1717
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1718
1719
        $this->assertSame('edit', $this->parameters['action']);
1720
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1721
        $this->assertSame($object, $this->parameters['object']);
1722
1723
        $this->assertSame(['sonata_flash_error' => ['flash_edit_error']], $this->session->getFlashBag()->all());
1724
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1725
    }
1726
1727
    public function testEditActionAjaxSuccess(): void
1728
    {
1729
        $object = new \stdClass();
1730
1731
        $this->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...
1732
            ->method('getObject')
1733
            ->willReturn($object);
1734
1735
        $this->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...
1736
            ->method('update')
1737
            ->willReturnArgument(0);
1738
1739
        $this->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...
1740
            ->method('checkAccess')
1741
            ->with($this->equalTo('edit'))
1742
            ->willReturn(true);
1743
1744
        $form = $this->createMock(Form::class);
1745
1746
        $this->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...
1747
            ->method('getForm')
1748
            ->willReturn($form);
1749
1750
        $form->expects($this->once())
1751
            ->method('isSubmitted')
1752
            ->willReturn(true);
1753
1754
        $form->expects($this->once())
1755
            ->method('isValid')
1756
            ->willReturn(true);
1757
1758
        $form->expects($this->once())
1759
            ->method('getData')
1760
            ->willReturn($object);
1761
1762
        $form->expects($this->once())
1763
            ->method('all')
1764
            ->willReturn(['field' => 'fielddata']);
1765
1766
        $this->admin
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1767
            ->method('getNormalizedIdentifier')
1768
            ->with($this->equalTo($object))
1769
            ->willReturn('foo_normalized');
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('toString')
1773
            ->willReturn('foo');
1774
1775
        $this->request->setMethod('POST');
1776
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1777
1778
        $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...
1779
1780
        $this->assertInstanceOf(Response::class, $response);
1781
        $this->assertSame(json_encode(['result' => 'ok', 'objectId' => 'foo_normalized', 'objectName' => 'foo']), $response->getContent());
1782
        $this->assertSame([], $this->session->getFlashBag()->all());
1783
    }
1784
1785
    public function testEditActionAjaxError(): void
1786
    {
1787
        $object = new \stdClass();
1788
1789
        $this->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...
1790
            ->method('getObject')
1791
            ->willReturn($object);
1792
1793
        $this->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...
1794
            ->method('checkAccess')
1795
            ->with($this->equalTo('edit'))
1796
            ->willReturn(true);
1797
1798
        $form = $this->createMock(Form::class);
1799
1800
        $this->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...
1801
            ->method('getForm')
1802
            ->willReturn($form);
1803
1804
        $form->expects($this->once())
1805
            ->method('isSubmitted')
1806
            ->willReturn(true);
1807
1808
        $form->expects($this->once())
1809
            ->method('isValid')
1810
            ->willReturn(false);
1811
1812
        $form->expects($this->once())
1813
            ->method('all')
1814
            ->willReturn(['field' => 'fielddata']);
1815
1816
        $formError = $this->createMock(FormError::class);
1817
        $formError->expects($this->atLeastOnce())
1818
            ->method('getMessage')
1819
            ->willReturn('Form error message');
1820
1821
        $form->expects($this->once())
1822
            ->method('getErrors')
1823
            ->with(true)
1824
            ->willReturn([$formError]);
1825
1826
        $this->request->setMethod('POST');
1827
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1828
        $this->request->headers->set('Accept', 'application/json');
1829
1830
        $this->assertInstanceOf(JsonResponse::class, $response = $this->controller->editAction(null, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::editAction() has too many arguments starting with $this->request.

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

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

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

Loading history...
1831
        $this->assertJsonStringEqualsJsonString('{"result":"error","errors":["Form error message"]}', $response->getContent());
1832
    }
1833
1834
    /**
1835
     * @legacy
1836
     * @expectedDeprecation In next major version response will return 406 NOT ACCEPTABLE without `Accept: application/json`
1837
     */
1838
    public function testEditActionAjaxErrorWithoutAcceptApplicationJson(): void
1839
    {
1840
        $object = new \stdClass();
1841
1842
        $this->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...
1843
            ->method('getObject')
1844
            ->willReturn($object);
1845
1846
        $this->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...
1847
            ->method('checkAccess')
1848
            ->with($this->equalTo('edit'))
1849
            ->willReturn(true);
1850
1851
        $form = $this->createMock(Form::class);
1852
1853
        $this->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...
1854
            ->method('getForm')
1855
            ->willReturn($form);
1856
1857
        $form->expects($this->once())
1858
            ->method('isSubmitted')
1859
            ->willReturn(true);
1860
1861
        $form->expects($this->once())
1862
            ->method('isValid')
1863
            ->willReturn(false);
1864
1865
        $form->expects($this->once())
1866
            ->method('all')
1867
            ->willReturn(['field' => 'fielddata']);
1868
1869
        $this->request->setMethod('POST');
1870
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1871
1872
        $formView = $this->createMock(FormView::class);
1873
        $form
1874
            ->method('createView')
1875
            ->willReturn($formView);
1876
1877
        $this->assertInstanceOf(Response::class, $response = $this->controller->editAction(null, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::editAction() has too many arguments starting with $this->request.

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

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

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

Loading history...
1878
        $this->assertSame($this->admin, $this->parameters['admin']);
1879
        $this->assertSame('@SonataAdmin/ajax_layout.html.twig', $this->parameters['base_template']);
1880
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1881
        $this->assertSame('edit', $this->parameters['action']);
1882
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1883
        $this->assertSame($object, $this->parameters['object']);
1884
        $this->assertSame(['sonata_flash_error' => [0 => null]], $this->session->getFlashBag()->all());
1885
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1886
    }
1887
1888
    /**
1889
     * @dataProvider getToStringValues
1890
     */
1891
    public function testEditActionWithModelManagerException($expectedToStringValue, $toStringValue): void
1892
    {
1893
        $object = new \stdClass();
1894
1895
        $this->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...
1896
            ->method('getObject')
1897
            ->willReturn($object);
1898
1899
        $this->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...
1900
            ->method('checkAccess')
1901
            ->with($this->equalTo('edit'))
1902
            ->willReturn(true);
1903
1904
        $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...
1905
            ->method('getClass')
1906
            ->willReturn('stdClass');
1907
1908
        $form = $this->createMock(Form::class);
1909
1910
        $this->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...
1911
            ->method('getForm')
1912
            ->willReturn($form);
1913
1914
        $form->expects($this->once())
1915
            ->method('isValid')
1916
            ->willReturn(true);
1917
1918
        $form->expects($this->once())
1919
            ->method('getData')
1920
            ->willReturn($object);
1921
1922
        $form->expects($this->once())
1923
            ->method('all')
1924
            ->willReturn(['field' => 'fielddata']);
1925
1926
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1927
            ->method('toString')
1928
            ->with($this->equalTo($object))
1929
            ->willReturn($toStringValue);
1930
1931
        $this->expectTranslate('flash_edit_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1932
1933
        $form->expects($this->once())
1934
            ->method('isSubmitted')
1935
            ->willReturn(true);
1936
        $this->request->setMethod('POST');
1937
1938
        $formView = $this->createMock(FormView::class);
1939
1940
        $form->expects($this->any())
1941
            ->method('createView')
1942
            ->willReturn($formView);
1943
1944
        $this->assertLoggerLogsModelManagerException($this->admin, 'update');
1945
        $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...
1946
1947
        $this->assertSame($this->admin, $this->parameters['admin']);
1948
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1949
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1950
1951
        $this->assertSame('edit', $this->parameters['action']);
1952
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1953
        $this->assertSame($object, $this->parameters['object']);
1954
1955
        $this->assertSame(['sonata_flash_error' => ['flash_edit_error']], $this->session->getFlashBag()->all());
1956
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1957
    }
1958
1959
    public function testEditActionWithPreview(): void
1960
    {
1961
        $object = new \stdClass();
1962
1963
        $this->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...
1964
            ->method('getObject')
1965
            ->willReturn($object);
1966
1967
        $this->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...
1968
            ->method('checkAccess')
1969
            ->with($this->equalTo('edit'))
1970
            ->willReturn(true);
1971
1972
        $form = $this->createMock(Form::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('getForm')
1976
            ->willReturn($form);
1977
1978
        $this->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...
1979
            ->method('supportsPreviewMode')
1980
            ->willReturn(true);
1981
1982
        $formView = $this->createMock(FormView::class);
1983
1984
        $form->expects($this->any())
1985
            ->method('createView')
1986
            ->willReturn($formView);
1987
1988
        $form->expects($this->once())
1989
            ->method('isSubmitted')
1990
            ->willReturn(true);
1991
1992
        $form->expects($this->once())
1993
            ->method('isValid')
1994
            ->willReturn(true);
1995
1996
        $form->expects($this->once())
1997
            ->method('all')
1998
            ->willReturn(['field' => 'fielddata']);
1999
2000
        $this->request->setMethod('POST');
2001
        $this->request->request->set('btn_preview', 'Preview');
2002
2003
        $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...
2004
2005
        $this->assertSame($this->admin, $this->parameters['admin']);
2006
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2007
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2008
2009
        $this->assertSame('edit', $this->parameters['action']);
2010
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2011
        $this->assertSame($object, $this->parameters['object']);
2012
2013
        $this->assertSame([], $this->session->getFlashBag()->all());
2014
        $this->assertSame('@SonataAdmin/CRUD/preview.html.twig', $this->template);
2015
    }
2016
2017
    public function testEditActionWithLockException(): void
2018
    {
2019
        $object = new \stdClass();
2020
        $class = \get_class($object);
2021
2022
        $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...
2023
            ->method('getObject')
2024
            ->willReturn($object);
2025
2026
        $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...
2027
            ->method('checkAccess')
2028
            ->with($this->equalTo('edit'))
2029
            ->willReturn(true);
2030
2031
        $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...
2032
            ->method('getClass')
2033
            ->willReturn($class);
2034
2035
        $form = $this->createMock(Form::class);
2036
2037
        $form->expects($this->any())
2038
            ->method('isValid')
2039
            ->willReturn(true);
2040
2041
        $form->expects($this->once())
2042
            ->method('getData')
2043
            ->willReturn($object);
2044
2045
        $form->expects($this->once())
2046
            ->method('all')
2047
            ->willReturn(['field' => 'fielddata']);
2048
2049
        $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...
2050
            ->method('getForm')
2051
            ->willReturn($form);
2052
2053
        $form->expects($this->any())
2054
            ->method('isSubmitted')
2055
            ->willReturn(true);
2056
        $this->request->setMethod('POST');
2057
2058
        $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...
2059
            ->method('update')
2060
            ->will($this->throwException(new LockException()));
2061
2062
        $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...
2063
            ->method('toString')
2064
            ->with($this->equalTo($object))
2065
            ->willReturn($class);
2066
2067
        $formView = $this->createMock(FormView::class);
2068
2069
        $form->expects($this->any())
2070
            ->method('createView')
2071
            ->willReturn($formView);
2072
2073
        $this->expectTranslate('flash_lock_error', [
2074
            '%name%' => $class,
2075
            '%link_start%' => '<a href="stdClass_edit">',
2076
            '%link_end%' => '</a>',
2077
        ], 'SonataAdminBundle');
2078
2079
        $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...
2080
    }
2081
2082
    public function testCreateActionAccessDenied(): void
2083
    {
2084
        $this->expectException(AccessDeniedException::class);
2085
2086
        $this->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...
2087
            ->method('checkAccess')
2088
            ->with($this->equalTo('create'))
2089
            ->will($this->throwException(new AccessDeniedException()));
2090
2091
        $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...
2092
    }
2093
2094
    public function testCreateActionRuntimeException(): void
2095
    {
2096
        $this->expectException(\RuntimeException::class);
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('checkAccess')
2100
            ->with($this->equalTo('create'))
2101
            ->willReturn(true);
2102
2103
        $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...
2104
            ->method('getClass')
2105
            ->willReturn('stdClass');
2106
2107
        $this->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...
2108
            ->method('getNewInstance')
2109
            ->willReturn(new \stdClass());
2110
2111
        $form = $this->createMock(Form::class);
2112
2113
        $this->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...
2114
            ->method('getForm')
2115
            ->willReturn($form);
2116
2117
        $form->expects($this->once())
2118
            ->method('all')
2119
            ->willReturn([]);
2120
2121
        $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...
2122
    }
2123
2124
    public function testPreCreate(): void
2125
    {
2126
        $object = new \stdClass();
2127
        $object->foo = 123456;
2128
2129
        $this->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...
2130
            ->method('checkAccess')
2131
            ->with($this->equalTo('create'))
2132
            ->willReturn(true);
2133
2134
        $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...
2135
            ->method('getClass')
2136
            ->willReturn('stdClass');
2137
2138
        $this->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...
2139
            ->method('getNewInstance')
2140
            ->willReturn($object);
2141
2142
        $controller = new PreCRUDController();
2143
        $controller->setContainer($this->container);
2144
2145
        $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...
2146
        $this->assertInstanceOf(Response::class, $response);
2147
        $this->assertSame('preCreate called: 123456', $response->getContent());
2148
    }
2149
2150
    public function testCreateAction(): void
2151
    {
2152
        $this->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...
2153
            ->method('checkAccess')
2154
            ->with($this->equalTo('create'))
2155
            ->willReturn(true);
2156
2157
        $object = new \stdClass();
2158
2159
        $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...
2160
            ->method('getClass')
2161
            ->willReturn('stdClass');
2162
2163
        $this->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...
2164
            ->method('getNewInstance')
2165
            ->willReturn($object);
2166
2167
        $form = $this->createMock(Form::class);
2168
2169
        $this->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...
2170
            ->method('getForm')
2171
            ->willReturn($form);
2172
2173
        $form->expects($this->once())
2174
            ->method('all')
2175
            ->willReturn(['field' => 'fielddata']);
2176
2177
        $formView = $this->createMock(FormView::class);
2178
2179
        $form->expects($this->any())
2180
            ->method('createView')
2181
            ->willReturn($formView);
2182
2183
        $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...
2184
2185
        $this->assertSame($this->admin, $this->parameters['admin']);
2186
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2187
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2188
2189
        $this->assertSame('create', $this->parameters['action']);
2190
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2191
        $this->assertSame($object, $this->parameters['object']);
2192
2193
        $this->assertSame([], $this->session->getFlashBag()->all());
2194
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
2195
    }
2196
2197
    /**
2198
     * @dataProvider getToStringValues
2199
     */
2200
    public function testCreateActionSuccess($expectedToStringValue, $toStringValue): void
2201
    {
2202
        $object = new \stdClass();
2203
2204
        $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...
2205
            ->method('checkAccess')
2206
            ->willReturnCallback(static function ($name, $objectIn = null) use ($object) {
2207
                if ('edit' === $name) {
2208
                    return true;
2209
                }
2210
2211
                if ('create' !== $name) {
2212
                    return false;
2213
                }
2214
2215
                if (null === $objectIn) {
2216
                    return true;
2217
                }
2218
2219
                return $objectIn === $object;
2220
            });
2221
2222
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2223
            ->method('hasRoute')
2224
            ->with($this->equalTo('edit'))
2225
            ->willReturn(true);
2226
2227
        $this->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...
2228
            ->method('hasAccess')
2229
            ->with($this->equalTo('edit'))
2230
            ->willReturn(true);
2231
2232
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2233
            ->method('getNewInstance')
2234
            ->willReturn($object);
2235
2236
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2237
            ->method('create')
2238
            ->willReturnArgument(0);
2239
2240
        $form = $this->createMock(Form::class);
2241
2242
        $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...
2243
            ->method('getClass')
2244
            ->willReturn('stdClass');
2245
2246
        $this->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...
2247
            ->method('getForm')
2248
            ->willReturn($form);
2249
2250
        $form->expects($this->once())
2251
            ->method('all')
2252
            ->willReturn(['field' => 'fielddata']);
2253
2254
        $form->expects($this->once())
2255
            ->method('isSubmitted')
2256
            ->willReturn(true);
2257
2258
        $form->expects($this->once())
2259
            ->method('isValid')
2260
            ->willReturn(true);
2261
2262
        $form->expects($this->once())
2263
            ->method('getData')
2264
            ->willReturn($object);
2265
2266
        $this->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...
2267
            ->method('toString')
2268
            ->with($this->equalTo($object))
2269
            ->willReturn($toStringValue);
2270
2271
        $this->expectTranslate('flash_create_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
2272
2273
        $this->request->setMethod('POST');
2274
2275
        $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...
2276
2277
        $this->assertInstanceOf(RedirectResponse::class, $response);
2278
        $this->assertSame(['flash_create_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
2279
        $this->assertSame('stdClass_edit', $response->getTargetUrl());
2280
    }
2281
2282
    public function testCreateActionAccessDenied2(): void
2283
    {
2284
        $this->expectException(AccessDeniedException::class);
2285
2286
        $object = new \stdClass();
2287
2288
        $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...
2289
            ->method('checkAccess')
2290
            ->willReturnCallback(static function ($name, $object = null) {
2291
                if ('create' !== $name) {
2292
                    throw new AccessDeniedException();
2293
                }
2294
                if (null === $object) {
2295
                    return true;
2296
                }
2297
2298
                throw new AccessDeniedException();
2299
            });
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('getNewInstance')
2303
            ->willReturn($object);
2304
2305
        $form = $this->createMock(Form::class);
2306
2307
        $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...
2308
            ->method('getClass')
2309
            ->willReturn('stdClass');
2310
2311
        $this->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...
2312
            ->method('getForm')
2313
            ->willReturn($form);
2314
2315
        $form->expects($this->once())
2316
            ->method('all')
2317
            ->willReturn(['field' => 'fielddata']);
2318
2319
        $form->expects($this->once())
2320
            ->method('isSubmitted')
2321
            ->willReturn(true);
2322
2323
        $form->expects($this->once())
2324
            ->method('getData')
2325
            ->willReturn($object);
2326
2327
        $form->expects($this->once())
2328
            ->method('isValid')
2329
            ->willReturn(true);
2330
2331
        $this->request->setMethod('POST');
2332
2333
        $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...
2334
    }
2335
2336
    /**
2337
     * @dataProvider getToStringValues
2338
     */
2339
    public function testCreateActionError($expectedToStringValue, $toStringValue): void
2340
    {
2341
        $this->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...
2342
            ->method('checkAccess')
2343
            ->with($this->equalTo('create'))
2344
            ->willReturn(true);
2345
2346
        $object = new \stdClass();
2347
2348
        $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...
2349
            ->method('getClass')
2350
            ->willReturn('stdClass');
2351
2352
        $this->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...
2353
            ->method('getNewInstance')
2354
            ->willReturn($object);
2355
2356
        $form = $this->createMock(Form::class);
2357
2358
        $this->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...
2359
            ->method('getForm')
2360
            ->willReturn($form);
2361
2362
        $form->expects($this->once())
2363
            ->method('all')
2364
            ->willReturn(['field' => 'fielddata']);
2365
2366
        $form->expects($this->once())
2367
            ->method('isSubmitted')
2368
            ->willReturn(true);
2369
2370
        $form->expects($this->once())
2371
            ->method('isValid')
2372
            ->willReturn(false);
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('toString')
2376
            ->with($this->equalTo($object))
2377
            ->willReturn($toStringValue);
2378
2379
        $this->expectTranslate('flash_create_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
2380
2381
        $this->request->setMethod('POST');
2382
2383
        $formView = $this->createMock(FormView::class);
2384
2385
        $form->expects($this->any())
2386
            ->method('createView')
2387
            ->willReturn($formView);
2388
2389
        $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...
2390
2391
        $this->assertSame($this->admin, $this->parameters['admin']);
2392
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2393
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2394
2395
        $this->assertSame('create', $this->parameters['action']);
2396
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2397
        $this->assertSame($object, $this->parameters['object']);
2398
2399
        $this->assertSame(['sonata_flash_error' => ['flash_create_error']], $this->session->getFlashBag()->all());
2400
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
2401
    }
2402
2403
    /**
2404
     * @dataProvider getToStringValues
2405
     */
2406
    public function testCreateActionWithModelManagerException($expectedToStringValue, $toStringValue): void
2407
    {
2408
        $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...
2409
            ->method('checkAccess')
2410
            ->with($this->equalTo('create'))
2411
            ->willReturn(true);
2412
2413
        $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...
2414
            ->method('getClass')
2415
            ->willReturn('stdClass');
2416
2417
        $object = new \stdClass();
2418
2419
        $this->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...
2420
            ->method('getNewInstance')
2421
            ->willReturn($object);
2422
2423
        $form = $this->createMock(Form::class);
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('getForm')
2427
            ->willReturn($form);
2428
2429
        $form->expects($this->once())
2430
            ->method('all')
2431
            ->willReturn(['field' => 'fielddata']);
2432
2433
        $form->expects($this->once())
2434
            ->method('isValid')
2435
            ->willReturn(true);
2436
2437
        $this->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...
2438
            ->method('toString')
2439
            ->with($this->equalTo($object))
2440
            ->willReturn($toStringValue);
2441
2442
        $this->expectTranslate('flash_create_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
2443
2444
        $form->expects($this->once())
2445
            ->method('isSubmitted')
2446
            ->willReturn(true);
2447
2448
        $form->expects($this->once())
2449
            ->method('getData')
2450
            ->willReturn($object);
2451
2452
        $this->request->setMethod('POST');
2453
2454
        $formView = $this->createMock(FormView::class);
2455
2456
        $form->expects($this->any())
2457
            ->method('createView')
2458
            ->willReturn($formView);
2459
2460
        $this->assertLoggerLogsModelManagerException($this->admin, 'create');
2461
2462
        $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...
2463
2464
        $this->assertSame($this->admin, $this->parameters['admin']);
2465
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2466
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2467
2468
        $this->assertSame('create', $this->parameters['action']);
2469
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2470
        $this->assertSame($object, $this->parameters['object']);
2471
2472
        $this->assertSame(['sonata_flash_error' => ['flash_create_error']], $this->session->getFlashBag()->all());
2473
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
2474
    }
2475
2476
    public function testCreateActionAjaxSuccess(): void
2477
    {
2478
        $object = new \stdClass();
2479
2480
        $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...
2481
            ->method('checkAccess')
2482
            ->willReturnCallback(static function ($name, $objectIn = null) use ($object) {
2483
                if ('create' !== $name) {
2484
                    return false;
2485
                }
2486
2487
                if (null === $objectIn) {
2488
                    return true;
2489
                }
2490
2491
                return $objectIn === $object;
2492
            });
2493
2494
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2495
            ->method('getNewInstance')
2496
            ->willReturn($object);
2497
2498
        $this->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...
2499
            ->method('create')
2500
            ->willReturnArgument(0);
2501
2502
        $form = $this->createMock(Form::class);
2503
2504
        $this->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...
2505
            ->method('getForm')
2506
            ->willReturn($form);
2507
2508
        $form->expects($this->once())
2509
            ->method('all')
2510
            ->willReturn(['field' => 'fielddata']);
2511
2512
        $form->expects($this->once())
2513
            ->method('isSubmitted')
2514
            ->willReturn(true);
2515
2516
        $form->expects($this->once())
2517
            ->method('isValid')
2518
            ->willReturn(true);
2519
2520
        $form->expects($this->once())
2521
            ->method('getData')
2522
            ->willReturn($object);
2523
2524
        $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...
2525
            ->method('getClass')
2526
            ->willReturn('stdClass');
2527
2528
        $this->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...
2529
            ->method('getNormalizedIdentifier')
2530
            ->with($this->equalTo($object))
2531
            ->willReturn('foo_normalized');
2532
2533
        $this->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...
2534
            ->method('toString')
2535
            ->willReturn('foo');
2536
2537
        $this->request->setMethod('POST');
2538
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
2539
2540
        $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...
2541
2542
        $this->assertInstanceOf(Response::class, $response);
2543
        $this->assertSame(json_encode(['result' => 'ok', 'objectId' => 'foo_normalized', 'objectName' => 'foo']), $response->getContent());
2544
        $this->assertSame([], $this->session->getFlashBag()->all());
2545
    }
2546
2547
    public function testCreateActionAjaxError(): void
2548
    {
2549
        $this->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...
2550
            ->method('checkAccess')
2551
            ->with($this->equalTo('create'))
2552
            ->willReturn(true);
2553
2554
        $object = new \stdClass();
2555
2556
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2557
            ->method('getNewInstance')
2558
            ->willReturn($object);
2559
2560
        $form = $this->createMock(Form::class);
2561
2562
        $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...
2563
            ->method('getClass')
2564
            ->willReturn('stdClass');
2565
2566
        $this->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...
2567
            ->method('getForm')
2568
            ->willReturn($form);
2569
2570
        $form->expects($this->once())
2571
            ->method('all')
2572
            ->willReturn(['field' => 'fielddata']);
2573
2574
        $form->expects($this->once())
2575
            ->method('isSubmitted')
2576
            ->willReturn(true);
2577
2578
        $form->expects($this->once())
2579
            ->method('isValid')
2580
            ->willReturn(false);
2581
2582
        $formError = $this->createMock(FormError::class);
2583
        $formError->expects($this->atLeastOnce())
2584
            ->method('getMessage')
2585
            ->willReturn('Form error message');
2586
2587
        $form->expects($this->once())
2588
            ->method('getErrors')
2589
            ->with(true)
2590
            ->willReturn([$formError]);
2591
2592
        $this->request->setMethod('POST');
2593
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
2594
        $this->request->headers->set('Accept', 'application/json');
2595
2596
        $this->assertInstanceOf(JsonResponse::class, $response = $this->controller->createAction($this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::createAction() has too many arguments starting with $this->request.

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

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

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

Loading history...
2597
        $this->assertJsonStringEqualsJsonString('{"result":"error","errors":["Form error message"]}', $response->getContent());
2598
    }
2599
2600
    /**
2601
     * @legacy
2602
     * @expectedDeprecation In next major version response will return 406 NOT ACCEPTABLE without `Accept: application/json`
2603
     */
2604
    public function testCreateActionAjaxErrorWithoutAcceptApplicationJson(): void
2605
    {
2606
        $this->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...
2607
            ->method('checkAccess')
2608
            ->with($this->equalTo('create'))
2609
            ->willReturn(true);
2610
2611
        $object = new \stdClass();
2612
2613
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2614
            ->method('getNewInstance')
2615
            ->willReturn($object);
2616
2617
        $form = $this->createMock(Form::class);
2618
2619
        $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...
2620
            ->method('getClass')
2621
            ->willReturn('stdClass');
2622
2623
        $this->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...
2624
            ->method('getForm')
2625
            ->willReturn($form);
2626
2627
        $form->expects($this->once())
2628
            ->method('all')
2629
            ->willReturn(['field' => 'fielddata']);
2630
2631
        $form->expects($this->once())
2632
            ->method('isSubmitted')
2633
            ->willReturn(true);
2634
2635
        $form->expects($this->once())
2636
            ->method('isValid')
2637
            ->willReturn(false);
2638
2639
        $this->request->setMethod('POST');
2640
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
2641
2642
        $formView = $this->createMock(FormView::class);
2643
        $form
2644
            ->method('createView')
2645
            ->willReturn($formView);
2646
2647
        $this->assertInstanceOf(Response::class, $response = $this->controller->createAction($this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::createAction() has too many arguments starting with $this->request.

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

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

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

Loading history...
2648
        $this->assertSame($this->admin, $this->parameters['admin']);
2649
        $this->assertSame('@SonataAdmin/ajax_layout.html.twig', $this->parameters['base_template']);
2650
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2651
        $this->assertSame('create', $this->parameters['action']);
2652
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2653
        $this->assertSame($object, $this->parameters['object']);
2654
        $this->assertSame(['sonata_flash_error' => [0 => null]], $this->session->getFlashBag()->all());
2655
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
2656
    }
2657
2658
    public function testCreateActionWithPreview(): void
2659
    {
2660
        $this->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...
2661
            ->method('checkAccess')
2662
            ->with($this->equalTo('create'))
2663
            ->willReturn(true);
2664
2665
        $object = new \stdClass();
2666
2667
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2668
            ->method('getNewInstance')
2669
            ->willReturn($object);
2670
2671
        $form = $this->createMock(Form::class);
2672
2673
        $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...
2674
            ->method('getClass')
2675
            ->willReturn('stdClass');
2676
2677
        $this->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...
2678
            ->method('getForm')
2679
            ->willReturn($form);
2680
2681
        $form->expects($this->once())
2682
            ->method('all')
2683
            ->willReturn(['field' => 'fielddata']);
2684
2685
        $this->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...
2686
            ->method('supportsPreviewMode')
2687
            ->willReturn(true);
2688
2689
        $formView = $this->createMock(FormView::class);
2690
2691
        $form->expects($this->any())
2692
            ->method('createView')
2693
            ->willReturn($formView);
2694
2695
        $form->expects($this->once())
2696
            ->method('isSubmitted')
2697
            ->willReturn(true);
2698
2699
        $form->expects($this->once())
2700
            ->method('isValid')
2701
            ->willReturn(true);
2702
2703
        $this->request->setMethod('POST');
2704
        $this->request->request->set('btn_preview', 'Preview');
2705
2706
        $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...
2707
2708
        $this->assertSame($this->admin, $this->parameters['admin']);
2709
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2710
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2711
2712
        $this->assertSame('create', $this->parameters['action']);
2713
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2714
        $this->assertSame($object, $this->parameters['object']);
2715
2716
        $this->assertSame([], $this->session->getFlashBag()->all());
2717
        $this->assertSame('@SonataAdmin/CRUD/preview.html.twig', $this->template);
2718
    }
2719
2720
    public function testExportActionAccessDenied(): void
2721
    {
2722
        $this->expectException(AccessDeniedException::class);
2723
2724
        $this->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...
2725
            ->method('checkAccess')
2726
            ->with($this->equalTo('export'))
2727
            ->will($this->throwException(new AccessDeniedException()));
2728
2729
        $this->controller->exportAction($this->request);
2730
    }
2731
2732
    public function testExportActionWrongFormat(): void
2733
    {
2734
        $this->expectException(\RuntimeException::class, 'Export in format `csv` is not allowed for class: `Foo`. Allowed formats are: `json`');
2735
2736
        $this->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...
2737
            ->method('checkAccess')
2738
            ->with($this->equalTo('export'))
2739
            ->willReturn(true);
2740
2741
        $this->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...
2742
            ->method('getExportFormats')
2743
            ->willReturn(['json']);
2744
2745
        $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...
2746
            ->method('getClass')
2747
            ->willReturn('Foo');
2748
2749
        $this->request->query->set('format', 'csv');
2750
2751
        $this->controller->exportAction($this->request);
2752
    }
2753
2754
    public function testExportAction(): void
2755
    {
2756
        $this->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...
2757
            ->method('checkAccess')
2758
            ->with($this->equalTo('export'))
2759
            ->willReturn(true);
2760
2761
        $this->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...
2762
            ->method('getExportFormats')
2763
            ->willReturn(['json']);
2764
2765
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2766
            ->method('getClass')
2767
            ->willReturn(\stdClass::class);
2768
2769
        $dataSourceIterator = $this->createMock(SourceIteratorInterface::class);
2770
2771
        $this->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...
2772
            ->method('getDataSourceIterator')
2773
            ->willReturn($dataSourceIterator);
2774
2775
        $this->request->query->set('format', 'json');
2776
2777
        $response = $this->controller->exportAction($this->request);
2778
        $this->assertInstanceOf(StreamedResponse::class, $response);
2779
        $this->assertSame(200, $response->getStatusCode());
2780
        $this->assertSame([], $this->session->getFlashBag()->all());
2781
    }
2782
2783
    public function testHistoryActionAccessDenied(): void
2784
    {
2785
        $this->expectException(AccessDeniedException::class);
2786
2787
        $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...
2788
            ->method('getObject')
2789
            ->willReturn(new \StdClass());
2790
2791
        $this->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...
2792
            ->method('checkAccess')
2793
            ->with($this->equalTo('history'))
2794
            ->will($this->throwException(new AccessDeniedException()));
2795
2796
        $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...
2797
    }
2798
2799
    public function testHistoryActionNotFoundException(): void
2800
    {
2801
        $this->expectException(NotFoundHttpException::class);
2802
2803
        $this->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...
2804
            ->method('getObject')
2805
            ->willReturn(false);
2806
2807
        $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...
2808
    }
2809
2810
    public function testHistoryActionNoReader(): void
2811
    {
2812
        $this->expectException(NotFoundHttpException::class, 'unable to find the audit reader for class : Foo');
2813
2814
        $this->request->query->set('id', 123);
2815
2816
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2817
            ->method('checkAccess')
2818
            ->with($this->equalTo('history'))
2819
            ->willReturn(true);
2820
2821
        $object = new \stdClass();
2822
2823
        $this->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...
2824
            ->method('getObject')
2825
            ->willReturn($object);
2826
2827
        $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...
2828
            ->method('getClass')
2829
            ->willReturn('Foo');
2830
2831
        $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...
2832
            ->method('hasReader')
2833
            ->with($this->equalTo('Foo'))
2834
            ->willReturn(false);
2835
2836
        $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...
2837
    }
2838
2839
    public function testHistoryAction(): void
2840
    {
2841
        $this->request->query->set('id', 123);
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('checkAccess')
2845
            ->with($this->equalTo('history'))
2846
            ->willReturn(true);
2847
2848
        $object = new \stdClass();
2849
2850
        $this->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...
2851
            ->method('getObject')
2852
            ->willReturn($object);
2853
2854
        $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...
2855
            ->method('getClass')
2856
            ->willReturn('Foo');
2857
2858
        $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...
2859
            ->method('hasReader')
2860
            ->with($this->equalTo('Foo'))
2861
            ->willReturn(true);
2862
2863
        $reader = $this->createMock(AuditReaderInterface::class);
2864
2865
        $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...
2866
            ->method('getReader')
2867
            ->with($this->equalTo('Foo'))
2868
            ->willReturn($reader);
2869
2870
        $reader->expects($this->once())
2871
            ->method('findRevisions')
2872
            ->with($this->equalTo('Foo'), $this->equalTo(123))
2873
            ->willReturn([]);
2874
2875
        $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...
2876
2877
        $this->assertSame($this->admin, $this->parameters['admin']);
2878
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2879
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2880
2881
        $this->assertSame('history', $this->parameters['action']);
2882
        $this->assertSame([], $this->parameters['revisions']);
2883
        $this->assertSame($object, $this->parameters['object']);
2884
2885
        $this->assertSame([], $this->session->getFlashBag()->all());
2886
        $this->assertSame('@SonataAdmin/CRUD/history.html.twig', $this->template);
2887
    }
2888
2889
    public function testAclActionAclNotEnabled(): void
2890
    {
2891
        $this->expectException(NotFoundHttpException::class, 'ACL are not enabled for this admin');
2892
2893
        $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...
2894
    }
2895
2896
    public function testAclActionNotFoundException(): void
2897
    {
2898
        $this->expectException(NotFoundHttpException::class);
2899
2900
        $this->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...
2901
            ->method('isAclEnabled')
2902
            ->willReturn(true);
2903
2904
        $this->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...
2905
            ->method('getObject')
2906
            ->willReturn(false);
2907
2908
        $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...
2909
    }
2910
2911
    public function testAclActionAccessDenied(): void
2912
    {
2913
        $this->expectException(AccessDeniedException::class);
2914
2915
        $this->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...
2916
            ->method('isAclEnabled')
2917
            ->willReturn(true);
2918
2919
        $object = new \stdClass();
2920
2921
        $this->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...
2922
            ->method('getObject')
2923
            ->willReturn($object);
2924
2925
        $this->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...
2926
            ->method('checkAccess')
2927
            ->with($this->equalTo('acl'), $this->equalTo($object))
2928
            ->will($this->throwException(new AccessDeniedException()));
2929
2930
        $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...
2931
    }
2932
2933
    public function testAclAction(): void
2934
    {
2935
        $this->request->query->set('id', 123);
2936
2937
        $this->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...
2938
            ->method('isAclEnabled')
2939
            ->willReturn(true);
2940
2941
        $object = new \stdClass();
2942
2943
        $this->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...
2944
            ->method('getObject')
2945
            ->willReturn($object);
2946
2947
        $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...
2948
            ->method('checkAccess')
2949
            ->willReturn(true);
2950
2951
        $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...
2952
            ->method('getSecurityInformation')
2953
            ->willReturn([]);
2954
2955
        $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...
2956
            ->method('getMaskBuilderClass')
2957
            ->willReturn(AdminPermissionMap::class);
2958
2959
        $aclUsersForm = $this->getMockBuilder(Form::class)
2960
            ->disableOriginalConstructor()
2961
            ->getMock();
2962
2963
        $aclUsersForm->expects($this->once())
2964
            ->method('createView')
2965
            ->willReturn($this->createMock(FormView::class));
2966
2967
        $aclRolesForm = $this->getMockBuilder(Form::class)
2968
            ->disableOriginalConstructor()
2969
            ->getMock();
2970
2971
        $aclRolesForm->expects($this->once())
2972
            ->method('createView')
2973
            ->willReturn($this->createMock(FormView::class));
2974
2975
        $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...
2976
            ->method('createAclUsersForm')
2977
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2978
            ->willReturn($aclUsersForm);
2979
2980
        $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...
2981
            ->method('createAclRolesForm')
2982
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2983
            ->willReturn($aclRolesForm);
2984
2985
        $aclSecurityHandler = $this->getMockBuilder(AclSecurityHandler::class)
2986
            ->disableOriginalConstructor()
2987
            ->getMock();
2988
2989
        $aclSecurityHandler->expects($this->any())
2990
            ->method('getObjectPermissions')
2991
            ->willReturn([]);
2992
2993
        $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...
2994
            ->method('getSecurityHandler')
2995
            ->willReturn($aclSecurityHandler);
2996
2997
        $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...
2998
2999
        $this->assertSame($this->admin, $this->parameters['admin']);
3000
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
3001
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3002
3003
        $this->assertSame('acl', $this->parameters['action']);
3004
        $this->assertSame([], $this->parameters['permissions']);
3005
        $this->assertSame($object, $this->parameters['object']);
3006
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['users']);
3007
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['roles']);
3008
        $this->assertInstanceOf(FormView::class, $this->parameters['aclUsersForm']);
3009
        $this->assertInstanceOf(FormView::class, $this->parameters['aclRolesForm']);
3010
3011
        $this->assertSame([], $this->session->getFlashBag()->all());
3012
        $this->assertSame('@SonataAdmin/CRUD/acl.html.twig', $this->template);
3013
    }
3014
3015
    public function testAclActionInvalidUpdate(): void
3016
    {
3017
        $this->request->query->set('id', 123);
3018
        $this->request->request->set(AdminObjectAclManipulator::ACL_USERS_FORM_NAME, []);
3019
3020
        $this->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...
3021
            ->method('isAclEnabled')
3022
            ->willReturn(true);
3023
3024
        $object = new \stdClass();
3025
3026
        $this->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...
3027
            ->method('getObject')
3028
            ->willReturn($object);
3029
3030
        $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...
3031
            ->method('checkAccess')
3032
            ->willReturn(true);
3033
3034
        $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...
3035
            ->method('getSecurityInformation')
3036
            ->willReturn([]);
3037
3038
        $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...
3039
            ->method('getMaskBuilderClass')
3040
            ->willReturn(AdminPermissionMap::class);
3041
3042
        $aclUsersForm = $this->getMockBuilder(Form::class)
3043
            ->disableOriginalConstructor()
3044
            ->getMock();
3045
3046
        $aclUsersForm->expects($this->once())
3047
            ->method('isValid')
3048
            ->willReturn(false);
3049
3050
        $aclUsersForm->expects($this->once())
3051
            ->method('createView')
3052
            ->willReturn($this->createMock(FormView::class));
3053
3054
        $aclRolesForm = $this->getMockBuilder(Form::class)
3055
            ->disableOriginalConstructor()
3056
            ->getMock();
3057
3058
        $aclRolesForm->expects($this->once())
3059
            ->method('createView')
3060
            ->willReturn($this->createMock(FormView::class));
3061
3062
        $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...
3063
            ->method('createAclUsersForm')
3064
            ->with($this->isInstanceOf(AdminObjectAclData::class))
3065
            ->willReturn($aclUsersForm);
3066
3067
        $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...
3068
            ->method('createAclRolesForm')
3069
            ->with($this->isInstanceOf(AdminObjectAclData::class))
3070
            ->willReturn($aclRolesForm);
3071
3072
        $aclSecurityHandler = $this->getMockBuilder(AclSecurityHandler::class)
3073
            ->disableOriginalConstructor()
3074
            ->getMock();
3075
3076
        $aclSecurityHandler->expects($this->any())
3077
            ->method('getObjectPermissions')
3078
            ->willReturn([]);
3079
3080
        $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...
3081
            ->method('getSecurityHandler')
3082
            ->willReturn($aclSecurityHandler);
3083
3084
        $this->request->setMethod('POST');
3085
3086
        $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...
3087
3088
        $this->assertSame($this->admin, $this->parameters['admin']);
3089
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
3090
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3091
3092
        $this->assertSame('acl', $this->parameters['action']);
3093
        $this->assertSame([], $this->parameters['permissions']);
3094
        $this->assertSame($object, $this->parameters['object']);
3095
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['users']);
3096
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['roles']);
3097
        $this->assertInstanceOf(FormView::class, $this->parameters['aclUsersForm']);
3098
        $this->assertInstanceOf(FormView::class, $this->parameters['aclRolesForm']);
3099
3100
        $this->assertSame([], $this->session->getFlashBag()->all());
3101
        $this->assertSame('@SonataAdmin/CRUD/acl.html.twig', $this->template);
3102
    }
3103
3104
    public function testAclActionSuccessfulUpdate(): void
3105
    {
3106
        $this->request->query->set('id', 123);
3107
        $this->request->request->set(AdminObjectAclManipulator::ACL_ROLES_FORM_NAME, []);
3108
3109
        $this->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...
3110
            ->method('isAclEnabled')
3111
            ->willReturn(true);
3112
3113
        $object = new \stdClass();
3114
3115
        $this->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...
3116
            ->method('getObject')
3117
            ->willReturn($object);
3118
3119
        $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...
3120
            ->method('checkAccess')
3121
            ->willReturn(true);
3122
3123
        $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...
3124
            ->method('getSecurityInformation')
3125
            ->willReturn([]);
3126
3127
        $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...
3128
            ->method('getMaskBuilderClass')
3129
            ->willReturn(AdminPermissionMap::class);
3130
3131
        $aclUsersForm = $this->getMockBuilder(Form::class)
3132
            ->disableOriginalConstructor()
3133
            ->getMock();
3134
3135
        $aclUsersForm->expects($this->any())
3136
            ->method('createView')
3137
            ->willReturn($this->createMock(FormView::class));
3138
3139
        $aclRolesForm = $this->getMockBuilder(Form::class)
3140
            ->disableOriginalConstructor()
3141
            ->getMock();
3142
3143
        $aclRolesForm->expects($this->any())
3144
            ->method('createView')
3145
            ->willReturn($this->createMock(FormView::class));
3146
3147
        $aclRolesForm->expects($this->once())
3148
            ->method('isValid')
3149
            ->willReturn(true);
3150
3151
        $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...
3152
            ->method('createAclUsersForm')
3153
            ->with($this->isInstanceOf(AdminObjectAclData::class))
3154
            ->willReturn($aclUsersForm);
3155
3156
        $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...
3157
            ->method('createAclRolesForm')
3158
            ->with($this->isInstanceOf(AdminObjectAclData::class))
3159
            ->willReturn($aclRolesForm);
3160
3161
        $aclSecurityHandler = $this->getMockBuilder(AclSecurityHandler::class)
3162
            ->disableOriginalConstructor()
3163
            ->getMock();
3164
3165
        $aclSecurityHandler->expects($this->any())
3166
            ->method('getObjectPermissions')
3167
            ->willReturn([]);
3168
3169
        $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...
3170
            ->method('getSecurityHandler')
3171
            ->willReturn($aclSecurityHandler);
3172
3173
        $this->expectTranslate('flash_acl_edit_success', [], 'SonataAdminBundle');
3174
3175
        $this->request->setMethod('POST');
3176
3177
        $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...
3178
3179
        $this->assertInstanceOf(RedirectResponse::class, $response);
3180
3181
        $this->assertSame(['flash_acl_edit_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3182
        $this->assertSame('stdClass_acl', $response->getTargetUrl());
3183
    }
3184
3185
    public function testHistoryViewRevisionActionAccessDenied(): void
3186
    {
3187
        $this->expectException(AccessDeniedException::class);
3188
3189
        $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...
3190
            ->method('getObject')
3191
            ->willReturn(new \StdClass());
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('checkAccess')
3195
            ->with($this->equalTo('historyViewRevision'))
3196
            ->will($this->throwException(new AccessDeniedException()));
3197
3198
        $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...
3199
    }
3200
3201
    public function testHistoryViewRevisionActionNotFoundException(): void
3202
    {
3203
        $this->expectException(NotFoundHttpException::class, 'unable to find the object with id: 123');
3204
3205
        $this->request->query->set('id', 123);
3206
3207
        $this->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...
3208
            ->method('getObject')
3209
            ->willReturn(false);
3210
3211
        $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...
3212
    }
3213
3214
    public function testHistoryViewRevisionActionNoReader(): void
3215
    {
3216
        $this->expectException(NotFoundHttpException::class, 'unable to find the audit reader for class : Foo');
3217
3218
        $this->request->query->set('id', 123);
3219
3220
        $this->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...
3221
            ->method('checkAccess')
3222
            ->with($this->equalTo('historyViewRevision'))
3223
            ->willReturn(true);
3224
3225
        $object = new \stdClass();
3226
3227
        $this->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...
3228
            ->method('getObject')
3229
            ->willReturn($object);
3230
3231
        $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...
3232
            ->method('getClass')
3233
            ->willReturn('Foo');
3234
3235
        $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...
3236
            ->method('hasReader')
3237
            ->with($this->equalTo('Foo'))
3238
            ->willReturn(false);
3239
3240
        $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...
3241
    }
3242
3243
    public function testHistoryViewRevisionActionNotFoundRevision(): void
3244
    {
3245
        $this->expectException(NotFoundHttpException::class, 'unable to find the targeted object `123` from the revision `456` with classname : `Foo`');
3246
3247
        $this->request->query->set('id', 123);
3248
3249
        $this->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...
3250
            ->method('checkAccess')
3251
            ->with($this->equalTo('historyViewRevision'))
3252
            ->willReturn(true);
3253
3254
        $object = new \stdClass();
3255
3256
        $this->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...
3257
            ->method('getObject')
3258
            ->willReturn($object);
3259
3260
        $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...
3261
            ->method('getClass')
3262
            ->willReturn('Foo');
3263
3264
        $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...
3265
            ->method('hasReader')
3266
            ->with($this->equalTo('Foo'))
3267
            ->willReturn(true);
3268
3269
        $reader = $this->createMock(AuditReaderInterface::class);
3270
3271
        $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...
3272
            ->method('getReader')
3273
            ->with($this->equalTo('Foo'))
3274
            ->willReturn($reader);
3275
3276
        $reader->expects($this->once())
3277
            ->method('find')
3278
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3279
            ->willReturn(null);
3280
3281
        $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...
3282
    }
3283
3284
    public function testHistoryViewRevisionAction(): void
3285
    {
3286
        $this->request->query->set('id', 123);
3287
3288
        $this->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...
3289
            ->method('checkAccess')
3290
            ->with($this->equalTo('historyViewRevision'))
3291
            ->willReturn(true);
3292
3293
        $object = new \stdClass();
3294
3295
        $this->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...
3296
            ->method('getObject')
3297
            ->willReturn($object);
3298
3299
        $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...
3300
            ->method('getClass')
3301
            ->willReturn('Foo');
3302
3303
        $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...
3304
            ->method('hasReader')
3305
            ->with($this->equalTo('Foo'))
3306
            ->willReturn(true);
3307
3308
        $reader = $this->createMock(AuditReaderInterface::class);
3309
3310
        $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...
3311
            ->method('getReader')
3312
            ->with($this->equalTo('Foo'))
3313
            ->willReturn($reader);
3314
3315
        $objectRevision = new \stdClass();
3316
        $objectRevision->revision = 456;
3317
3318
        $reader->expects($this->once())
3319
            ->method('find')
3320
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3321
            ->willReturn($objectRevision);
3322
3323
        $this->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...
3324
            ->method('setSubject')
3325
            ->with($this->equalTo($objectRevision))
3326
            ->willReturn(null);
3327
3328
        $fieldDescriptionCollection = new FieldDescriptionCollection();
3329
        $this->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...
3330
            ->method('getShow')
3331
            ->willReturn($fieldDescriptionCollection);
3332
3333
        $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...
3334
3335
        $this->assertSame($this->admin, $this->parameters['admin']);
3336
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
3337
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3338
3339
        $this->assertSame('show', $this->parameters['action']);
3340
        $this->assertSame($objectRevision, $this->parameters['object']);
3341
        $this->assertSame($fieldDescriptionCollection, $this->parameters['elements']);
3342
3343
        $this->assertSame([], $this->session->getFlashBag()->all());
3344
        $this->assertSame('@SonataAdmin/CRUD/show.html.twig', $this->template);
3345
    }
3346
3347
    public function testHistoryCompareRevisionsActionAccessDenied(): void
3348
    {
3349
        $this->expectException(AccessDeniedException::class);
3350
3351
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3352
            ->method('checkAccess')
3353
            ->with($this->equalTo('historyCompareRevisions'))
3354
            ->will($this->throwException(new AccessDeniedException()));
3355
3356
        $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...
3357
    }
3358
3359
    public function testHistoryCompareRevisionsActionNotFoundException(): void
3360
    {
3361
        $this->expectException(NotFoundHttpException::class, 'unable to find the object with id: 123');
3362
3363
        $this->request->query->set('id', 123);
3364
3365
        $this->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...
3366
            ->method('checkAccess')
3367
            ->with($this->equalTo('historyCompareRevisions'))
3368
            ->willReturn(true);
3369
3370
        $this->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...
3371
            ->method('getObject')
3372
            ->willReturn(false);
3373
3374
        $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...
3375
    }
3376
3377
    public function testHistoryCompareRevisionsActionNoReader(): void
3378
    {
3379
        $this->expectException(NotFoundHttpException::class, 'unable to find the audit reader for class : Foo');
3380
3381
        $this->request->query->set('id', 123);
3382
3383
        $this->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...
3384
            ->method('checkAccess')
3385
            ->with($this->equalTo('historyCompareRevisions'))
3386
            ->willReturn(true);
3387
3388
        $object = new \stdClass();
3389
3390
        $this->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...
3391
            ->method('getObject')
3392
            ->willReturn($object);
3393
3394
        $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...
3395
            ->method('getClass')
3396
            ->willReturn('Foo');
3397
3398
        $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...
3399
            ->method('hasReader')
3400
            ->with($this->equalTo('Foo'))
3401
            ->willReturn(false);
3402
3403
        $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...
3404
    }
3405
3406
    public function testHistoryCompareRevisionsActionNotFoundBaseRevision(): void
3407
    {
3408
        $this->expectException(NotFoundHttpException::class, 'unable to find the targeted object `123` from the revision `456` with classname : `Foo`');
3409
3410
        $this->request->query->set('id', 123);
3411
3412
        $this->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...
3413
            ->method('checkAccess')
3414
            ->with($this->equalTo('historyCompareRevisions'))
3415
            ->willReturn(true);
3416
3417
        $object = new \stdClass();
3418
3419
        $this->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...
3420
            ->method('getObject')
3421
            ->willReturn($object);
3422
3423
        $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...
3424
            ->method('getClass')
3425
            ->willReturn('Foo');
3426
3427
        $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...
3428
            ->method('hasReader')
3429
            ->with($this->equalTo('Foo'))
3430
            ->willReturn(true);
3431
3432
        $reader = $this->createMock(AuditReaderInterface::class);
3433
3434
        $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...
3435
            ->method('getReader')
3436
            ->with($this->equalTo('Foo'))
3437
            ->willReturn($reader);
3438
3439
        // once because it will not be found and therefore the second call won't be executed
3440
        $reader->expects($this->once())
3441
            ->method('find')
3442
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3443
            ->willReturn(null);
3444
3445
        $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...
3446
    }
3447
3448
    public function testHistoryCompareRevisionsActionNotFoundCompareRevision(): void
3449
    {
3450
        $this->expectException(NotFoundHttpException::class, 'unable to find the targeted object `123` from the revision `789` with classname : `Foo`');
3451
3452
        $this->request->query->set('id', 123);
3453
3454
        $this->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...
3455
            ->method('checkAccess')
3456
            ->with($this->equalTo('historyCompareRevisions'))
3457
            ->willReturn(true);
3458
3459
        $object = new \stdClass();
3460
3461
        $this->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...
3462
            ->method('getObject')
3463
            ->willReturn($object);
3464
3465
        $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...
3466
            ->method('getClass')
3467
            ->willReturn('Foo');
3468
3469
        $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...
3470
            ->method('hasReader')
3471
            ->with($this->equalTo('Foo'))
3472
            ->willReturn(true);
3473
3474
        $reader = $this->createMock(AuditReaderInterface::class);
3475
3476
        $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...
3477
            ->method('getReader')
3478
            ->with($this->equalTo('Foo'))
3479
            ->willReturn($reader);
3480
3481
        $objectRevision = new \stdClass();
3482
        $objectRevision->revision = 456;
3483
3484
        // first call should return, so the second call will throw an exception
3485
        $reader->expects($this->at(0))
3486
            ->method('find')
3487
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3488
            ->willReturn($objectRevision);
3489
3490
        $reader->expects($this->at(1))
3491
            ->method('find')
3492
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(789))
3493
            ->willReturn(null);
3494
3495
        $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...
3496
    }
3497
3498
    public function testHistoryCompareRevisionsActionAction(): void
3499
    {
3500
        $this->request->query->set('id', 123);
3501
3502
        $this->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...
3503
            ->method('checkAccess')
3504
            ->with($this->equalTo('historyCompareRevisions'))
3505
            ->willReturn(true);
3506
3507
        $object = new \stdClass();
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('getObject')
3511
            ->willReturn($object);
3512
3513
        $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...
3514
            ->method('getClass')
3515
            ->willReturn('Foo');
3516
3517
        $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...
3518
            ->method('hasReader')
3519
            ->with($this->equalTo('Foo'))
3520
            ->willReturn(true);
3521
3522
        $reader = $this->createMock(AuditReaderInterface::class);
3523
3524
        $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...
3525
            ->method('getReader')
3526
            ->with($this->equalTo('Foo'))
3527
            ->willReturn($reader);
3528
3529
        $objectRevision = new \stdClass();
3530
        $objectRevision->revision = 456;
3531
3532
        $compareObjectRevision = new \stdClass();
3533
        $compareObjectRevision->revision = 789;
3534
3535
        $reader->expects($this->at(0))
3536
            ->method('find')
3537
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3538
            ->willReturn($objectRevision);
3539
3540
        $reader->expects($this->at(1))
3541
            ->method('find')
3542
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(789))
3543
            ->willReturn($compareObjectRevision);
3544
3545
        $this->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...
3546
            ->method('setSubject')
3547
            ->with($this->equalTo($objectRevision))
3548
            ->willReturn(null);
3549
3550
        $fieldDescriptionCollection = new FieldDescriptionCollection();
3551
        $this->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...
3552
            ->method('getShow')
3553
            ->willReturn($fieldDescriptionCollection);
3554
3555
        $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...
3556
3557
        $this->assertSame($this->admin, $this->parameters['admin']);
3558
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
3559
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3560
3561
        $this->assertSame('show', $this->parameters['action']);
3562
        $this->assertSame($objectRevision, $this->parameters['object']);
3563
        $this->assertSame($compareObjectRevision, $this->parameters['object_compare']);
3564
        $this->assertSame($fieldDescriptionCollection, $this->parameters['elements']);
3565
3566
        $this->assertSame([], $this->session->getFlashBag()->all());
3567
        $this->assertSame('@SonataAdmin/CRUD/show_compare.html.twig', $this->template);
3568
    }
3569
3570
    public function testBatchActionWrongMethod(): void
3571
    {
3572
        $this->expectException(NotFoundHttpException::class, 'Invalid request type "GET", POST expected');
3573
3574
        $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...
3575
    }
3576
3577
    public function testBatchActionActionNotDefined(): void
3578
    {
3579
        $this->expectException(\RuntimeException::class, 'The `foo` batch action is not defined');
3580
3581
        $batchActions = [];
3582
3583
        $this->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...
3584
            ->method('getBatchActions')
3585
            ->willReturn($batchActions);
3586
3587
        $this->request->setMethod('POST');
3588
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3589
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3590
3591
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
3592
            ->method('getOption')
3593
            ->with('csrf_protection')
3594
            ->willReturn(true);
3595
3596
        $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...
3597
    }
3598
3599
    public function testBatchActionActionInvalidCsrfToken(): void
3600
    {
3601
        $this->request->setMethod('POST');
3602
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3603
        $this->request->request->set('_sonata_csrf_token', 'CSRF-INVALID');
3604
3605
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
3606
            ->method('getOption')
3607
            ->with('csrf_protection')
3608
            ->willReturn(true);
3609
3610
        try {
3611
            $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...
3612
        } catch (HttpException $e) {
3613
            $this->assertSame('The csrf token is not valid, CSRF attack?', $e->getMessage());
3614
            $this->assertSame(400, $e->getStatusCode());
3615
        }
3616
    }
3617
3618
    public function testBatchActionActionWithDisabledCsrfProtection(): void
3619
    {
3620
        $this->request->setMethod('POST');
3621
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3622
3623
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
3624
            ->method('getOption')
3625
            ->with('csrf_protection')
3626
            ->willReturn(false);
3627
3628
        $this->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...
3629
            ->method('getBatchActions')
3630
            ->willReturn(['foo' => ['label' => 'foo']]);
3631
3632
        $datagrid = $this->createMock(DatagridInterface::class);
3633
3634
        $this->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...
3635
            ->method('getDatagrid')
3636
            ->willReturn($datagrid);
3637
3638
        $datagrid->expects($this->once())
3639
            ->method('buildPager');
3640
3641
        $form = $this->createMock(FormInterface::class);
3642
3643
        $datagrid->expects($this->once())
3644
            ->method('getForm')
3645
            ->willReturn($form);
3646
3647
        $formView = $this->createMock(FormView::class);
3648
3649
        $form->expects($this->once())
3650
            ->method('createView')
3651
            ->willReturn($formView);
3652
3653
        $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...
3654
    }
3655
3656
    public function testBatchActionMethodNotExist(): void
3657
    {
3658
        $this->expectException(\RuntimeException::class, 'A `Sonata\AdminBundle\Controller\CRUDController::batchActionFoo` method must be callable');
3659
3660
        $batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3661
3662
        $this->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...
3663
            ->method('getBatchActions')
3664
            ->willReturn($batchActions);
3665
3666
        $datagrid = $this->createMock(DatagridInterface::class);
3667
        $this->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...
3668
            ->method('getDatagrid')
3669
            ->willReturn($datagrid);
3670
3671
        $this->request->setMethod('POST');
3672
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3673
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3674
3675
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
3676
            ->method('getOption')
3677
            ->with('csrf_protection')
3678
            ->willReturn(true);
3679
3680
        $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...
3681
    }
3682
3683
    public function testBatchActionWithoutConfirmation(): void
3684
    {
3685
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3686
3687
        $this->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...
3688
            ->method('getBatchActions')
3689
            ->willReturn($batchActions);
3690
3691
        $datagrid = $this->createMock(DatagridInterface::class);
3692
3693
        $query = $this->createMock(ProxyQueryInterface::class);
3694
        $datagrid->expects($this->once())
3695
            ->method('getQuery')
3696
            ->willReturn($query);
3697
3698
        $this->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...
3699
            ->method('getDatagrid')
3700
            ->willReturn($datagrid);
3701
3702
        $modelManager = $this->createMock(ModelManagerInterface::class);
3703
3704
        $this->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...
3705
            ->method('checkAccess')
3706
            ->with($this->equalTo('batchDelete'))
3707
            ->willReturn(true);
3708
3709
        $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...
3710
            ->method('getModelManager')
3711
            ->willReturn($modelManager);
3712
3713
        $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...
3714
            ->method('getClass')
3715
            ->willReturn('Foo');
3716
3717
        $modelManager->expects($this->once())
3718
            ->method('addIdentifiersToQuery')
3719
            ->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456']))
3720
            ->willReturn(true);
3721
3722
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
3723
3724
        $this->request->setMethod('POST');
3725
        $this->request->request->set('data', json_encode(['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false]));
3726
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3727
3728
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
3729
            ->method('getOption')
3730
            ->with('csrf_protection')
3731
            ->willReturn(true);
3732
3733
        $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...
3734
3735
        $this->assertInstanceOf(RedirectResponse::class, $result);
3736
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3737
        $this->assertSame('list', $result->getTargetUrl());
3738
    }
3739
3740
    public function testBatchActionWithoutConfirmation2(): void
3741
    {
3742
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3743
3744
        $this->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...
3745
            ->method('getBatchActions')
3746
            ->willReturn($batchActions);
3747
3748
        $datagrid = $this->createMock(DatagridInterface::class);
3749
3750
        $query = $this->createMock(ProxyQueryInterface::class);
3751
        $datagrid->expects($this->once())
3752
            ->method('getQuery')
3753
            ->willReturn($query);
3754
3755
        $this->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...
3756
            ->method('getDatagrid')
3757
            ->willReturn($datagrid);
3758
3759
        $modelManager = $this->createMock(ModelManagerInterface::class);
3760
3761
        $this->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...
3762
            ->method('checkAccess')
3763
            ->with($this->equalTo('batchDelete'))
3764
            ->willReturn(true);
3765
3766
        $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...
3767
            ->method('getModelManager')
3768
            ->willReturn($modelManager);
3769
3770
        $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...
3771
            ->method('getClass')
3772
            ->willReturn('Foo');
3773
3774
        $modelManager->expects($this->once())
3775
            ->method('addIdentifiersToQuery')
3776
            ->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456']))
3777
            ->willReturn(true);
3778
3779
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
3780
3781
        $this->request->setMethod('POST');
3782
        $this->request->request->set('action', 'delete');
3783
        $this->request->request->set('idx', ['123', '456']);
3784
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3785
3786
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
3787
            ->method('getOption')
3788
            ->with('csrf_protection')
3789
            ->willReturn(true);
3790
3791
        $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...
3792
3793
        $this->assertInstanceOf(RedirectResponse::class, $result);
3794
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3795
        $this->assertSame('list', $result->getTargetUrl());
3796
    }
3797
3798
    public function testBatchActionWithConfirmation(): void
3799
    {
3800
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'translation_domain' => 'FooBarBaz', 'ask_confirmation' => true]];
3801
3802
        $this->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...
3803
            ->method('getBatchActions')
3804
            ->willReturn($batchActions);
3805
3806
        $data = ['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false];
3807
3808
        $this->request->setMethod('POST');
3809
        $this->request->request->set('data', json_encode($data));
3810
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3811
3812
        $datagrid = $this->createMock(DatagridInterface::class);
3813
3814
        $this->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...
3815
            ->method('getDatagrid')
3816
            ->willReturn($datagrid);
3817
3818
        $form = $this->getMockBuilder(Form::class)
3819
            ->disableOriginalConstructor()
3820
            ->getMock();
3821
3822
        $form->expects($this->once())
3823
            ->method('createView')
3824
            ->willReturn($this->createMock(FormView::class));
3825
3826
        $datagrid->expects($this->once())
3827
            ->method('getForm')
3828
            ->willReturn($form);
3829
3830
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
3831
            ->method('getOption')
3832
            ->with('csrf_protection')
3833
            ->willReturn(true);
3834
3835
        $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...
3836
3837
        $this->assertSame($this->admin, $this->parameters['admin']);
3838
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
3839
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3840
3841
        $this->assertSame('list', $this->parameters['action']);
3842
        $this->assertSame($datagrid, $this->parameters['datagrid']);
3843
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
3844
        $this->assertSame($data, $this->parameters['data']);
3845
        $this->assertSame('csrf-token-123_sonata.batch', $this->parameters['csrf_token']);
3846
        $this->assertSame('Foo Bar', $this->parameters['action_label']);
3847
3848
        $this->assertSame([], $this->session->getFlashBag()->all());
3849
        $this->assertSame('@SonataAdmin/CRUD/batch_confirmation.html.twig', $this->template);
3850
    }
3851
3852
    public function testBatchActionNonRelevantAction(): void
3853
    {
3854
        $controller = new BatchAdminController();
3855
        $controller->setContainer($this->container);
3856
3857
        $batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3858
3859
        $this->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...
3860
            ->method('getBatchActions')
3861
            ->willReturn($batchActions);
3862
3863
        $datagrid = $this->createMock(DatagridInterface::class);
3864
3865
        $this->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...
3866
            ->method('getDatagrid')
3867
            ->willReturn($datagrid);
3868
3869
        $this->expectTranslate('flash_batch_empty', [], 'SonataAdminBundle');
3870
3871
        $this->request->setMethod('POST');
3872
        $this->request->request->set('action', 'foo');
3873
        $this->request->request->set('idx', ['789']);
3874
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3875
3876
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
3877
            ->method('getOption')
3878
            ->with('csrf_protection')
3879
            ->willReturn(true);
3880
3881
        $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...
3882
3883
        $this->assertInstanceOf(RedirectResponse::class, $result);
3884
        $this->assertSame(['flash_batch_empty'], $this->session->getFlashBag()->get('sonata_flash_info'));
3885
        $this->assertSame('list', $result->getTargetUrl());
3886
    }
3887
3888
    public function testBatchActionWithCustomConfirmationTemplate(): void
3889
    {
3890
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => true, 'template' => 'custom_template.html.twig']];
3891
3892
        $this->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...
3893
            ->method('getBatchActions')
3894
            ->willReturn($batchActions);
3895
3896
        $data = ['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false];
3897
3898
        $this->request->setMethod('POST');
3899
        $this->request->request->set('data', json_encode($data));
3900
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3901
3902
        $datagrid = $this->createMock(DatagridInterface::class);
3903
3904
        $this->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...
3905
            ->method('getDatagrid')
3906
            ->willReturn($datagrid);
3907
3908
        $form = $this->createMock(Form::class);
3909
3910
        $form->expects($this->once())
3911
            ->method('createView')
3912
            ->willReturn($this->createMock(FormView::class));
3913
3914
        $datagrid->expects($this->once())
3915
            ->method('getForm')
3916
            ->willReturn($form);
3917
3918
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
3919
            ->method('getOption')
3920
            ->with('csrf_protection')
3921
            ->willReturn(true);
3922
3923
        $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...
3924
3925
        $this->assertSame('custom_template.html.twig', $this->template);
3926
    }
3927
3928
    public function testBatchActionNonRelevantAction2(): void
3929
    {
3930
        $controller = new BatchAdminController();
3931
        $controller->setContainer($this->container);
3932
3933
        $batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3934
3935
        $this->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...
3936
            ->method('getBatchActions')
3937
            ->willReturn($batchActions);
3938
3939
        $datagrid = $this->createMock(DatagridInterface::class);
3940
3941
        $this->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...
3942
            ->method('getDatagrid')
3943
            ->willReturn($datagrid);
3944
3945
        $this->expectTranslate('flash_foo_error', [], 'SonataAdminBundle');
3946
3947
        $this->request->setMethod('POST');
3948
        $this->request->request->set('action', 'foo');
3949
        $this->request->request->set('idx', ['999']);
3950
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3951
3952
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
3953
            ->method('getOption')
3954
            ->with('csrf_protection')
3955
            ->willReturn(true);
3956
3957
        $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...
3958
3959
        $this->assertInstanceOf(RedirectResponse::class, $result);
3960
        $this->assertSame(['flash_foo_error'], $this->session->getFlashBag()->get('sonata_flash_info'));
3961
        $this->assertSame('list', $result->getTargetUrl());
3962
    }
3963
3964
    public function testBatchActionNoItems(): void
3965
    {
3966
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => true]];
3967
3968
        $this->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...
3969
            ->method('getBatchActions')
3970
            ->willReturn($batchActions);
3971
3972
        $datagrid = $this->createMock(DatagridInterface::class);
3973
3974
        $this->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...
3975
            ->method('getDatagrid')
3976
            ->willReturn($datagrid);
3977
3978
        $this->expectTranslate('flash_batch_empty', [], 'SonataAdminBundle');
3979
3980
        $this->request->setMethod('POST');
3981
        $this->request->request->set('action', 'delete');
3982
        $this->request->request->set('idx', []);
3983
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3984
3985
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
3986
            ->method('getOption')
3987
            ->with('csrf_protection')
3988
            ->willReturn(true);
3989
3990
        $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...
3991
3992
        $this->assertInstanceOf(RedirectResponse::class, $result);
3993
        $this->assertSame(['flash_batch_empty'], $this->session->getFlashBag()->get('sonata_flash_info'));
3994
        $this->assertSame('list', $result->getTargetUrl());
3995
    }
3996
3997
    public function testBatchActionNoItemsEmptyQuery(): void
3998
    {
3999
        $controller = new BatchAdminController();
4000
        $controller->setContainer($this->container);
4001
4002
        $batchActions = ['bar' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
4003
4004
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
4005
            ->method('getBatchActions')
4006
            ->willReturn($batchActions);
4007
4008
        $datagrid = $this->createMock(DatagridInterface::class);
4009
4010
        $query = $this->createMock(ProxyQueryInterface::class);
4011
        $datagrid->expects($this->once())
4012
            ->method('getQuery')
4013
            ->willReturn($query);
4014
4015
        $this->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...
4016
            ->method('getDatagrid')
4017
            ->willReturn($datagrid);
4018
4019
        $modelManager = $this->createMock(ModelManagerInterface::class);
4020
4021
        $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...
4022
            ->method('getModelManager')
4023
            ->willReturn($modelManager);
4024
4025
        $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...
4026
            ->method('getClass')
4027
            ->willReturn('Foo');
4028
4029
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
4030
            ->method('getOption')
4031
            ->with('csrf_protection')
4032
            ->willReturn(true);
4033
4034
        $this->request->setMethod('POST');
4035
        $this->request->request->set('action', 'bar');
4036
        $this->request->request->set('idx', []);
4037
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
4038
4039
        $this->expectTranslate('flash_batch_no_elements_processed', [], 'SonataAdminBundle');
4040
        $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...
4041
4042
        $this->assertInstanceOf(Response::class, $result);
4043
        $this->assertRegExp('/Redirecting to list/', $result->getContent());
4044
    }
4045
4046
    public function testBatchActionWithRequesData(): void
4047
    {
4048
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
4049
4050
        $this->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...
4051
            ->method('getBatchActions')
4052
            ->willReturn($batchActions);
4053
4054
        $datagrid = $this->createMock(DatagridInterface::class);
4055
4056
        $query = $this->createMock(ProxyQueryInterface::class);
4057
        $datagrid->expects($this->once())
4058
            ->method('getQuery')
4059
            ->willReturn($query);
4060
4061
        $this->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...
4062
            ->method('getDatagrid')
4063
            ->willReturn($datagrid);
4064
4065
        $modelManager = $this->createMock(ModelManagerInterface::class);
4066
4067
        $this->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...
4068
            ->method('checkAccess')
4069
            ->with($this->equalTo('batchDelete'))
4070
            ->willReturn(true);
4071
4072
        $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...
4073
            ->method('getModelManager')
4074
            ->willReturn($modelManager);
4075
4076
        $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...
4077
            ->method('getClass')
4078
            ->willReturn('Foo');
4079
4080
        $modelManager->expects($this->once())
4081
            ->method('addIdentifiersToQuery')
4082
            ->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456']))
4083
            ->willReturn(true);
4084
4085
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
4086
4087
        $this->request->setMethod('POST');
4088
        $this->request->request->set('data', json_encode(['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false]));
4089
        $this->request->request->set('foo', 'bar');
4090
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
4091
4092
        $this->formBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...m\FormBuilderInterface>.

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

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

Loading history...
4093
            ->method('getOption')
4094
            ->with('csrf_protection')
4095
            ->willReturn(true);
4096
4097
        $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...
4098
4099
        $this->assertInstanceOf(RedirectResponse::class, $result);
4100
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
4101
        $this->assertSame('list', $result->getTargetUrl());
4102
        $this->assertSame('bar', $this->request->request->get('foo'));
4103
    }
4104
4105
    public function testItThrowsWhenCallingAnUndefinedMethod(): void
4106
    {
4107
        $this->expectException(
4108
            \LogicException::class
4109
        );
4110
        $this->expectExceptionMessage(
4111
            'Call to undefined method Sonata\AdminBundle\Controller\CRUDController::doesNotExist'
4112
        );
4113
        $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...
4114
    }
4115
4116
    /**
4117
     * @expectedDeprecation Method Sonata\AdminBundle\Controller\CRUDController::render has been renamed to Sonata\AdminBundle\Controller\CRUDController::renderWithExtraParams.
4118
     */
4119
    public function testRenderIsDeprecated(): void
4120
    {
4121
        $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...
4122
    }
4123
4124
    public function getCsrfProvider()
4125
    {
4126
        return $this->csrfProvider;
4127
    }
4128
4129
    public function getToStringValues()
4130
    {
4131
        return [
4132
            ['', ''],
4133
            ['Foo', 'Foo'],
4134
            ['&lt;a href=&quot;http://foo&quot;&gt;Bar&lt;/a&gt;', '<a href="http://foo">Bar</a>'],
4135
            ['&lt;&gt;&amp;&quot;&#039;abcdefghijklmnopqrstuvwxyz*-+.,?_()[]\/', '<>&"\'abcdefghijklmnopqrstuvwxyz*-+.,?_()[]\/'],
4136
        ];
4137
    }
4138
4139
    private function assertLoggerLogsModelManagerException($subject, string $method): void
4140
    {
4141
        $exception = new ModelManagerException(
4142
            $message = 'message',
4143
            1234,
4144
            new \Exception($previousExceptionMessage = 'very useful message')
4145
        );
4146
4147
        $subject->expects($this->once())
4148
            ->method($method)
4149
            ->willReturnCallback(static function () use ($exception): void {
4150
                throw $exception;
4151
            });
4152
4153
        $this->logger->expects($this->once())
4154
            ->method('error')
4155
            ->with($message, [
4156
                'exception' => $exception,
4157
                'previous_exception_message' => $previousExceptionMessage,
4158
            ]);
4159
    }
4160
4161
    private function expectTranslate(
4162
        string $id,
4163
        array $parameters = [],
4164
        ?string $domain = null,
4165
        ?string $locale = null
4166
    ): void {
4167
        $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...
4168
            ->method('trans')
4169
            ->with($this->equalTo($id), $this->equalTo($parameters), $this->equalTo($domain), $this->equalTo($locale))
4170
            ->willReturn($id);
4171
    }
4172
}
4173