Completed
Push — master ( de08bc...2cdfe0 )
by Marko
13s
created

testEditActionRuntimeException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 9.52
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\AdminBundle\Tests\Controller;
15
16
use Exporter\Exporter;
17
use Exporter\Source\SourceIteratorInterface;
18
use Exporter\Writer\JsonWriter;
19
use PHPUnit\Framework\TestCase;
20
use Psr\Log\LoggerInterface;
21
use Sonata\AdminBundle\Admin\AdminInterface;
22
use Sonata\AdminBundle\Admin\FieldDescriptionCollection;
23
use Sonata\AdminBundle\Admin\Pool;
24
use Sonata\AdminBundle\Controller\CRUDController;
25
use Sonata\AdminBundle\Datagrid\DatagridInterface;
26
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
27
use Sonata\AdminBundle\Exception\LockException;
28
use Sonata\AdminBundle\Exception\ModelManagerException;
29
use Sonata\AdminBundle\Export\Exporter as SonataExporter;
30
use Sonata\AdminBundle\Model\AuditManager;
31
use Sonata\AdminBundle\Model\AuditReaderInterface;
32
use Sonata\AdminBundle\Model\ModelManagerInterface;
33
use Sonata\AdminBundle\Security\Acl\Permission\AdminPermissionMap;
34
use Sonata\AdminBundle\Security\Handler\AclSecurityHandler;
35
use Sonata\AdminBundle\Templating\TemplateRegistryInterface;
36
use Sonata\AdminBundle\Tests\Fixtures\Controller\BatchAdminController;
37
use Sonata\AdminBundle\Tests\Fixtures\Controller\PreCRUDController;
38
use Sonata\AdminBundle\Util\AdminObjectAclData;
39
use Sonata\AdminBundle\Util\AdminObjectAclManipulator;
40
use Symfony\Bridge\Twig\Extension\FormExtension;
41
use Symfony\Bridge\Twig\Form\TwigRenderer;
42
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
43
use Symfony\Bundle\FrameworkBundle\Templating\DelegatingEngine;
44
use Symfony\Component\DependencyInjection\ContainerInterface;
45
use Symfony\Component\Form\Form;
46
use Symfony\Component\Form\FormRenderer;
47
use Symfony\Component\Form\FormView;
48
use Symfony\Component\HttpFoundation\RedirectResponse;
49
use Symfony\Component\HttpFoundation\Request;
50
use Symfony\Component\HttpFoundation\RequestStack;
51
use Symfony\Component\HttpFoundation\Response;
52
use Symfony\Component\HttpFoundation\Session\Session;
53
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
54
use Symfony\Component\HttpFoundation\StreamedResponse;
55
use Symfony\Component\HttpKernel\Exception\HttpException;
56
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
57
use Symfony\Component\HttpKernel\KernelInterface;
58
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
59
use Symfony\Component\Security\Csrf\CsrfToken;
60
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
61
use Symfony\Component\Translation\TranslatorInterface;
62
63
/**
64
 * Test for CRUDController.
65
 *
66
 * @author Andrej Hudec <[email protected]>
67
 *
68
 * @group legacy
69
 */
70
class CRUDControllerTest extends TestCase
71
{
72
    /**
73
     * @var CRUDController
74
     */
75
    private $controller;
76
77
    /**
78
     * @var Request
79
     */
80
    private $request;
81
82
    /**
83
     * @var AdminInterface
84
     */
85
    private $admin;
86
87
    /**
88
     * @var TemplateRegistryInterface
89
     */
90
    private $templateRegistry;
91
92
    /**
93
     * @var Pool
94
     */
95
    private $pool;
96
97
    /**
98
     * @var array
99
     */
100
    private $parameters;
101
102
    /**
103
     * @var Session
104
     */
105
    private $session;
106
107
    /**
108
     * @var AuditManager
109
     */
110
    private $auditManager;
111
112
    /**
113
     * @var ContainerInterface
114
     */
115
    private $container;
116
117
    /**
118
     * @var AdminObjectAclManipulator
119
     */
120
    private $adminObjectAclManipulator;
121
122
    /**
123
     * @var string
124
     */
125
    private $template;
126
127
    /**
128
     * @var array
129
     */
130
    private $protectedTestedMethods;
131
132
    /**
133
     * @var CsrfTokenManagerInterface
134
     */
135
    private $csrfProvider;
136
137
    /**
138
     * @var KernelInterface
139
     */
140
    private $kernel;
141
142
    /**
143
     * @var TranslatorInterface
144
     */
145
    private $translator;
146
147
    /**
148
     * {@inheritdoc}
149
     */
150
    protected function setUp(): void
151
    {
152
        $this->container = $this->createMock(ContainerInterface::class);
153
154
        $this->request = new Request();
155
        $this->pool = new Pool($this->container, 'title', 'logo.png');
156
        $this->pool->setAdminServiceIds(['foo.admin']);
157
        $this->request->attributes->set('_sonata_admin', 'foo.admin');
158
        $this->admin = $this->getMockBuilder(AdminInterface::class)
159
            ->disableOriginalConstructor()
160
            ->getMock();
161
        $this->translator = $this->createMock(TranslatorInterface::class);
162
        $this->parameters = [];
163
        $this->template = '';
164
165
        $this->templateRegistry = $this->prophesize(TemplateRegistryInterface::class);
166
167
        $templating = $this->getMockBuilder(DelegatingEngine::class)
168
            ->setConstructorArgs([$this->container, []])
169
            ->getMock();
170
171
        $templatingRenderReturnCallback = $this->returnCallback(function (
172
            $view,
173
            array $parameters = [],
174
            Response $response = null
175
        ) {
176
            $this->template = $view;
177
178
            if (null === $response) {
179
                $response = new Response();
180
            }
181
182
            $this->parameters = $parameters;
183
184
            return $response;
185
        });
186
187
        // SF < 3.3.10 BC
188
        $templating->expects($this->any())
189
            ->method('renderResponse')
190
            ->will($templatingRenderReturnCallback);
191
192
        $templating->expects($this->any())
193
            ->method('render')
194
            ->will($templatingRenderReturnCallback);
195
196
        $this->session = new Session(new MockArraySessionStorage());
197
198
        $twig = $this->getMockBuilder(\Twig_Environment::class)
199
            ->disableOriginalConstructor()
200
            ->getMock();
201
202
        $twig->expects($this->any())
203
            ->method('getExtension')
204
            ->will($this->returnCallback(function ($name) {
205
                switch ($name) {
206
                    case FormExtension::class:
207
                        return new FormExtension($this->createMock(TwigRenderer::class));
0 ignored issues
show
Unused Code introduced by
The call to FormExtension::__construct() has too many arguments starting with $this->createMock(\Symfo...rm\TwigRenderer::class).

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

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

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

Loading history...
208
                }
209
            }));
210
211
        $twig->expects($this->any())
212
            ->method('getRuntime')
213
            ->will($this->returnCallback(function ($name) {
214
                switch ($name) {
215
                    case TwigRenderer::class:
216
                        return $this->createMock(TwigRenderer::class);
217
                    case FormRenderer::class:
218
                        return $this->createMock(FormRenderer::class);
219
                }
220
            }));
221
222
        // NEXT_MAJOR : require sonata/exporter ^1.7 and remove conditional
223
        if (class_exists(Exporter::class)) {
224
            $exporter = new Exporter([new JsonWriter('/tmp/sonataadmin/export.json')]);
225
        } else {
226
            $exporter = $this->createMock(SonataExporter::class);
227
228
            $exporter->expects($this->any())
229
                ->method('getResponse')
230
                ->will($this->returnValue(new StreamedResponse()));
231
        }
232
233
        $this->auditManager = $this->getMockBuilder(AuditManager::class)
234
            ->disableOriginalConstructor()
235
            ->getMock();
236
237
        $this->adminObjectAclManipulator = $this->getMockBuilder(AdminObjectAclManipulator::class)
238
            ->disableOriginalConstructor()
239
            ->getMock();
240
241
        $this->csrfProvider = $this->getMockBuilder(CsrfTokenManagerInterface::class)
242
            ->getMock();
243
244
        $this->csrfProvider->expects($this->any())
245
            ->method('getToken')
246
            ->will($this->returnCallback(function ($intention) {
247
                return new CsrfToken($intention, 'csrf-token-123_'.$intention);
248
            }));
249
250
        $this->csrfProvider->expects($this->any())
251
            ->method('isTokenValid')
252
            ->will($this->returnCallback(function (CsrfToken $token) {
253
                if ($token->getValue() == 'csrf-token-123_'.$token->getId()) {
254
                    return true;
255
                }
256
257
                return false;
258
            }));
259
260
        $this->logger = $this->createMock(LoggerInterface::class);
261
262
        $requestStack = new RequestStack();
263
        $requestStack->push($this->request);
264
265
        $this->kernel = $this->createMock(KernelInterface::class);
266
267
        $this->container->expects($this->any())
268
            ->method('get')
269
            ->will($this->returnCallback(function ($id) use (
270
                $templating,
271
                $twig,
272
                $exporter,
273
                $requestStack
274
            ) {
275
                switch ($id) {
276
                    case 'sonata.admin.pool':
277
                        return $this->pool;
278
                    case 'request_stack':
279
                        return $requestStack;
280
                    case 'foo.admin':
281
                        return $this->admin;
282
                    case 'foo.admin.template_registry':
283
                        return $this->templateRegistry->reveal();
0 ignored issues
show
Bug introduced by
The method reveal() does not seem to exist on object<Sonata\AdminBundl...plateRegistryInterface>.

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

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

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

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

Loading history...
388
                        $result = $name;
389
                        if (!empty($parameters)) {
390
                            $result .= '?'.http_build_query($parameters);
391
                        }
392
393
                        return $result;
394
                    }
395
                )
396
            );
397
398
        $this->admin->expects($this->any())
399
            ->method('generateObjectUrl')
400
            ->will(
401
                $this->returnCallback(
402
                    function ($name, $object, array $parameters = [], $absolute = false) {
0 ignored issues
show
Unused Code introduced by
The parameter $absolute is not used and could be removed.

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

Loading history...
403
                        $result = get_class($object).'_'.$name;
404
                        if (!empty($parameters)) {
405
                            $result .= '?'.http_build_query($parameters);
406
                        }
407
408
                        return $result;
409
                    }
410
                )
411
            );
412
413
        $this->admin->expects($this->any())
414
            ->method('getCode')
415
            ->willReturn('foo.admin');
416
417
        $this->controller = new CRUDController();
418
        $this->controller->setContainer($this->container);
419
420
        // Make some methods public to test them
421
        $testedMethods = [
422
            'renderJson',
423
            'isXmlHttpRequest',
424
            'configure',
425
            'getBaseTemplate',
426
            'redirectTo',
427
            'addFlash',
428
        ];
429
        foreach ($testedMethods as $testedMethod) {
430
            // NEXT_MAJOR: Remove this check and only use CRUDController
431
            if (method_exists(CRUDController::class, $testedMethod)) {
432
                $method = new \ReflectionMethod(CRUDController::class, $testedMethod);
433
            } else {
434
                $method = new \ReflectionMethod(Controller::class, $testedMethod);
435
            }
436
437
            $method->setAccessible(true);
438
            $this->protectedTestedMethods[$testedMethod] = $method;
439
        }
440
    }
441
442
    public function testRenderJson1(): void
443
    {
444
        $data = ['example' => '123', 'foo' => 'bar'];
445
446
        $this->request->headers->set('Content-Type', 'application/x-www-form-urlencoded');
447
        $response = $this->protectedTestedMethods['renderJson']->invoke($this->controller, $data, 200, [], $this->request);
448
449
        $this->assertSame($response->headers->get('Content-Type'), 'application/json');
450
        $this->assertSame(json_encode($data), $response->getContent());
451
    }
452
453
    public function testRenderJson2(): void
454
    {
455
        $data = ['example' => '123', 'foo' => 'bar'];
456
457
        $this->request->headers->set('Content-Type', 'multipart/form-data');
458
        $response = $this->protectedTestedMethods['renderJson']->invoke($this->controller, $data, 200, [], $this->request);
459
460
        $this->assertSame($response->headers->get('Content-Type'), 'application/json');
461
        $this->assertSame(json_encode($data), $response->getContent());
462
    }
463
464
    public function testRenderJsonAjax(): void
465
    {
466
        $data = ['example' => '123', 'foo' => 'bar'];
467
468
        $this->request->attributes->set('_xml_http_request', true);
469
        $this->request->headers->set('Content-Type', 'multipart/form-data');
470
        $response = $this->protectedTestedMethods['renderJson']->invoke($this->controller, $data, 200, [], $this->request);
471
472
        $this->assertSame($response->headers->get('Content-Type'), 'application/json');
473
        $this->assertSame(json_encode($data), $response->getContent());
474
    }
475
476
    public function testIsXmlHttpRequest(): void
477
    {
478
        $this->assertFalse($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
479
480
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
481
482
        $this->assertTrue($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
483
484
        $this->request->headers->remove('X-Requested-With');
485
        $this->assertFalse($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
486
487
        $this->request->attributes->set('_xml_http_request', true);
488
        $this->assertTrue($this->protectedTestedMethods['isXmlHttpRequest']->invoke($this->controller, $this->request));
489
    }
490
491
    public function testConfigure(): void
492
    {
493
        $uniqueId = '';
494
495
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
656
            ->method('checkAccess')
657
            ->with($this->equalTo('list'))
658
            ->will($this->throwException(new AccessDeniedException()));
659
660
        $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...
661
    }
662
663
    public function testPreList(): void
664
    {
665
        $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...
666
            ->method('hasRoute')
667
            ->with($this->equalTo('list'))
668
            ->will($this->returnValue(true));
669
670
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
671
            ->method('checkAccess')
672
            ->with($this->equalTo('list'))
673
            ->will($this->returnValue(true));
674
675
        $controller = new PreCRUDController();
676
        $controller->setContainer($this->container);
677
678
        $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...
679
        $this->assertInstanceOf(Response::class, $response);
680
        $this->assertSame('preList called', $response->getContent());
681
    }
682
683
    public function testListAction(): void
684
    {
685
        $datagrid = $this->createMock(DatagridInterface::class);
686
687
        $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...
688
            ->method('hasRoute')
689
            ->with($this->equalTo('list'))
690
            ->will($this->returnValue(true));
691
692
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

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

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

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

Loading history...
750
            ->method('getModelManager')
751
            ->will($this->returnValue($modelManager));
752
753
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
772
            ->method('getModelManager')
773
            ->will($this->returnValue($modelManager));
774
775
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
830
            ->method('checkAccess')
831
            ->with($this->equalTo('show'))
832
            ->will($this->throwException(new AccessDeniedException()));
833
834
        $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...
835
    }
836
837
    public function testPreShow(): void
838
    {
839
        $object = new \stdClass();
840
        $object->foo = 123456;
841
842
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
847
            ->method('checkAccess')
848
            ->with($this->equalTo('show'))
849
            ->will($this->returnValue(true));
850
851
        $controller = new PreCRUDController();
852
        $controller->setContainer($this->container);
853
854
        $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...
855
        $this->assertInstanceOf(Response::class, $response);
856
        $this->assertSame('preShow called: 123456', $response->getContent());
857
    }
858
859
    public function testShowAction(): void
860
    {
861
        $object = new \stdClass();
862
863
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
864
            ->method('getObject')
865
            ->will($this->returnValue($object));
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('checkAccess')
869
            ->with($this->equalTo('show'))
870
            ->will($this->returnValue(true));
871
872
        $show = $this->createMock(FieldDescriptionCollection::class);
873
874
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
961
            ->method('getObject')
962
            ->will($this->returnValue(false));
963
964
        $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...
965
    }
966
967
    public function testDeleteActionAccessDenied(): void
968
    {
969
        $this->expectException(AccessDeniedException::class);
970
971
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
976
            ->method('checkAccess')
977
            ->with($this->equalTo('delete'))
978
            ->will($this->throwException(new AccessDeniedException()));
979
980
        $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...
981
    }
982
983
    public function testPreDelete(): void
984
    {
985
        $object = new \stdClass();
986
        $object->foo = 123456;
987
988
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
993
            ->method('checkAccess')
994
            ->with($this->equalTo('delete'))
995
            ->will($this->returnValue(true));
996
997
        $controller = new PreCRUDController();
998
        $controller->setContainer($this->container);
999
1000
        $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...
1001
        $this->assertInstanceOf(Response::class, $response);
1002
        $this->assertSame('preDelete called: 123456', $response->getContent());
1003
    }
1004
1005
    public function testDeleteAction(): void
1006
    {
1007
        $object = 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('getObject')
1011
            ->will($this->returnValue($object));
1012
1013
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1014
            ->method('checkAccess')
1015
            ->with($this->equalTo('delete'))
1016
            ->will($this->returnValue(true));
1017
1018
        $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...
1019
1020
        $this->assertSame($this->admin, $this->parameters['admin']);
1021
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1022
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1023
1024
        $this->assertSame('delete', $this->parameters['action']);
1025
        $this->assertSame($object, $this->parameters['object']);
1026
        $this->assertSame('csrf-token-123_sonata.delete', $this->parameters['csrf_token']);
1027
1028
        $this->assertSame([], $this->session->getFlashBag()->all());
1029
        $this->assertSame('@SonataAdmin/CRUD/delete.html.twig', $this->template);
1030
    }
1031
1032
    public function testDeleteActionNoCsrfToken(): void
1033
    {
1034
        $this->csrfProvider = null;
1035
1036
        $object = new \stdClass();
1037
1038
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
1043
            ->method('checkAccess')
1044
            ->with($this->equalTo('delete'))
1045
            ->will($this->returnValue(true));
1046
1047
        $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...
1048
1049
        $this->assertSame($this->admin, $this->parameters['admin']);
1050
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1051
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1052
1053
        $this->assertSame('delete', $this->parameters['action']);
1054
        $this->assertSame($object, $this->parameters['object']);
1055
        $this->assertFalse($this->parameters['csrf_token']);
1056
1057
        $this->assertSame([], $this->session->getFlashBag()->all());
1058
        $this->assertSame('@SonataAdmin/CRUD/delete.html.twig', $this->template);
1059
    }
1060
1061
    public function testDeleteActionAjaxSuccess1(): void
1062
    {
1063
        $object = new \stdClass();
1064
1065
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
1070
            ->method('checkAccess')
1071
            ->with($this->equalTo('delete'))
1072
            ->will($this->returnValue(true));
1073
1074
        $this->request->setMethod('DELETE');
1075
1076
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1077
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1078
1079
        $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...
1080
1081
        $this->assertInstanceOf(Response::class, $response);
1082
        $this->assertSame(json_encode(['result' => 'ok']), $response->getContent());
1083
        $this->assertSame([], $this->session->getFlashBag()->all());
1084
    }
1085
1086
    public function testDeleteActionAjaxSuccess2(): void
1087
    {
1088
        $object = new \stdClass();
1089
1090
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
1095
            ->method('checkAccess')
1096
            ->with($this->equalTo('delete'))
1097
            ->will($this->returnValue(true));
1098
1099
        $this->request->setMethod('POST');
1100
        $this->request->request->set('_method', 'DELETE');
1101
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1102
1103
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1104
1105
        $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...
1106
1107
        $this->assertInstanceOf(Response::class, $response);
1108
        $this->assertSame(json_encode(['result' => 'ok']), $response->getContent());
1109
        $this->assertSame([], $this->session->getFlashBag()->all());
1110
    }
1111
1112
    public function testDeleteActionAjaxError(): void
1113
    {
1114
        $object = new \stdClass();
1115
1116
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
1159
            ->method('delete')
1160
            ->will($this->returnCallback(function (): void {
1161
                throw new ModelManagerException();
1162
            }));
1163
1164
        $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...
1165
            ->method('isDebug')
1166
            ->will($this->returnValue(true));
1167
1168
        $this->request->setMethod('DELETE');
1169
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1170
1171
        $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...
1172
    }
1173
1174
    /**
1175
     * @dataProvider getToStringValues
1176
     */
1177
    public function testDeleteActionSuccess1($expectedToStringValue, $toStringValue): void
1178
    {
1179
        $object = new \stdClass();
1180
1181
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
1186
            ->method('toString')
1187
            ->with($this->equalTo($object))
1188
            ->will($this->returnValue($toStringValue));
1189
1190
        $this->expectTranslate('flash_delete_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1191
1192
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1193
            ->method('checkAccess')
1194
            ->with($this->equalTo('delete'))
1195
            ->will($this->returnValue(true));
1196
1197
        $this->request->setMethod('DELETE');
1198
1199
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1200
1201
        $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...
1202
1203
        $this->assertInstanceOf(RedirectResponse::class, $response);
1204
        $this->assertSame(['flash_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1205
        $this->assertSame('list', $response->getTargetUrl());
1206
    }
1207
1208
    /**
1209
     * @dataProvider getToStringValues
1210
     */
1211
    public function testDeleteActionSuccess2($expectedToStringValue, $toStringValue): void
1212
    {
1213
        $object = new \stdClass();
1214
1215
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
1287
            ->method('checkAccess')
1288
            ->with($this->equalTo('delete'))
1289
            ->will($this->returnValue(true));
1290
1291
        //without POST request parameter "_method" should not be used as real REST method
1292
        $this->request->query->set('_method', 'DELETE');
1293
1294
        $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...
1295
1296
        $this->assertSame($this->admin, $this->parameters['admin']);
1297
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1298
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1299
1300
        $this->assertSame('delete', $this->parameters['action']);
1301
        $this->assertSame($object, $this->parameters['object']);
1302
        $this->assertSame('csrf-token-123_sonata.delete', $this->parameters['csrf_token']);
1303
1304
        $this->assertSame([], $this->session->getFlashBag()->all());
1305
        $this->assertSame('@SonataAdmin/CRUD/delete.html.twig', $this->template);
1306
    }
1307
1308
    /**
1309
     * @dataProvider getToStringValues
1310
     */
1311
    public function testDeleteActionError($expectedToStringValue, $toStringValue): void
1312
    {
1313
        $object = new \stdClass();
1314
1315
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

Loading history...
1325
            ->method('toString')
1326
            ->with($this->equalTo($object))
1327
            ->will($this->returnValue($toStringValue));
1328
1329
        $this->expectTranslate('flash_delete_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1330
1331
        $this->assertLoggerLogsModelManagerException($this->admin, 'delete');
1332
1333
        $this->request->setMethod('DELETE');
1334
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1335
1336
        $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...
1337
1338
        $this->assertInstanceOf(RedirectResponse::class, $response);
1339
        $this->assertSame(['flash_delete_error'], $this->session->getFlashBag()->get('sonata_flash_error'));
1340
        $this->assertSame('list', $response->getTargetUrl());
1341
    }
1342
1343
    public function testDeleteActionInvalidCsrfToken(): void
1344
    {
1345
        $object = new \stdClass();
1346
1347
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1348
            ->method('getObject')
1349
            ->will($this->returnValue($object));
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('checkAccess')
1353
            ->with($this->equalTo('delete'))
1354
            ->will($this->returnValue(true));
1355
1356
        $this->request->setMethod('POST');
1357
        $this->request->request->set('_method', 'DELETE');
1358
        $this->request->request->set('_sonata_csrf_token', 'CSRF-INVALID');
1359
1360
        try {
1361
            $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...
1362
        } catch (HttpException $e) {
1363
            $this->assertSame('The csrf token is not valid, CSRF attack?', $e->getMessage());
1364
            $this->assertSame(400, $e->getStatusCode());
1365
        }
1366
    }
1367
1368
    public function testEditActionNotFoundException(): void
1369
    {
1370
        $this->expectException(NotFoundHttpException::class);
1371
1372
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1373
            ->method('getObject')
1374
            ->will($this->returnValue(false));
1375
1376
        $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...
1377
    }
1378
1379
    public function testEditActionRuntimeException(): void
1380
    {
1381
        $this->expectException(\RuntimeException::class);
1382
1383
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
1388
            ->method('checkAccess')
1389
            ->with($this->equalTo('edit'))
1390
            ->will($this->returnValue(true));
1391
1392
        $form = $this->createMock(Form::class);
1393
1394
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1395
            ->method('getForm')
1396
            ->will($this->returnValue($form));
1397
1398
        $form->expects($this->once())
1399
            ->method('all')
1400
            ->willReturn([]);
1401
1402
        $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...
1403
    }
1404
1405
    public function testEditActionAccessDenied(): void
1406
    {
1407
        $this->expectException(AccessDeniedException::class);
1408
1409
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
1414
            ->method('checkAccess')
1415
            ->with($this->equalTo('edit'))
1416
            ->will($this->throwException(new AccessDeniedException()));
1417
1418
        $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...
1419
    }
1420
1421
    public function testPreEdit(): void
1422
    {
1423
        $object = new \stdClass();
1424
        $object->foo = 123456;
1425
1426
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
1431
            ->method('checkAccess')
1432
            ->with($this->equalTo('edit'))
1433
            ->will($this->returnValue(true));
1434
1435
        $controller = new PreCRUDController();
1436
        $controller->setContainer($this->container);
1437
1438
        $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...
1439
        $this->assertInstanceOf(Response::class, $response);
1440
        $this->assertSame('preEdit called: 123456', $response->getContent());
1441
    }
1442
1443
    public function testEditAction(): void
1444
    {
1445
        $object = new \stdClass();
1446
1447
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1448
            ->method('getObject')
1449
            ->will($this->returnValue($object));
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('checkAccess')
1453
            ->with($this->equalTo('edit'))
1454
            ->will($this->returnValue(true));
1455
1456
        $form = $this->createMock(Form::class);
1457
1458
        $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...
1459
            ->method('getForm')
1460
            ->will($this->returnValue($form));
1461
1462
        $formView = $this->createMock(FormView::class);
1463
1464
        $form->expects($this->any())
1465
            ->method('createView')
1466
            ->will($this->returnValue($formView));
1467
1468
        $form->expects($this->once())
1469
            ->method('all')
1470
            ->willReturn(['field' => 'fielddata']);
1471
1472
        $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...
1473
1474
        $this->assertSame($this->admin, $this->parameters['admin']);
1475
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1476
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1477
1478
        $this->assertSame('edit', $this->parameters['action']);
1479
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1480
        $this->assertSame($object, $this->parameters['object']);
1481
        $this->assertSame([], $this->session->getFlashBag()->all());
1482
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1483
    }
1484
1485
    /**
1486
     * @dataProvider getToStringValues
1487
     */
1488
    public function testEditActionSuccess($expectedToStringValue, $toStringValue): void
1489
    {
1490
        $object = new \stdClass();
1491
1492
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
1510
            ->method('hasAccess')
1511
            ->with($this->equalTo('edit'))
1512
            ->will($this->returnValue(true));
1513
1514
        $form = $this->createMock(Form::class);
1515
1516
        $form->expects($this->once())
1517
            ->method('getData')
1518
            ->will($this->returnValue($object));
1519
1520
        $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...
1521
            ->method('getForm')
1522
            ->will($this->returnValue($form));
1523
1524
        $form->expects($this->once())
1525
            ->method('isSubmitted')
1526
            ->will($this->returnValue(true));
1527
1528
        $form->expects($this->once())
1529
            ->method('isValid')
1530
            ->will($this->returnValue(true));
1531
1532
        $form->expects($this->once())
1533
            ->method('all')
1534
            ->willReturn(['field' => 'fielddata']);
1535
1536
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1537
            ->method('toString')
1538
            ->with($this->equalTo($object))
1539
            ->will($this->returnValue($toStringValue));
1540
1541
        $this->expectTranslate('flash_edit_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1542
1543
        $this->request->setMethod('POST');
1544
1545
        $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...
1546
1547
        $this->assertInstanceOf(RedirectResponse::class, $response);
1548
        $this->assertSame(['flash_edit_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1549
        $this->assertSame('stdClass_edit', $response->getTargetUrl());
1550
    }
1551
1552
    /**
1553
     * @dataProvider getToStringValues
1554
     */
1555
    public function testEditActionError($expectedToStringValue, $toStringValue): 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
            ->will($this->returnValue($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
            ->will($this->returnValue(true));
1567
1568
        $form = $this->createMock(Form::class);
1569
1570
        $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...
1571
            ->method('getForm')
1572
            ->will($this->returnValue($form));
1573
1574
        $form->expects($this->once())
1575
            ->method('isSubmitted')
1576
            ->will($this->returnValue(true));
1577
1578
        $form->expects($this->once())
1579
            ->method('isValid')
1580
            ->will($this->returnValue(false));
1581
1582
        $form->expects($this->once())
1583
            ->method('all')
1584
            ->willReturn(['field' => 'fielddata']);
1585
1586
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1587
            ->method('toString')
1588
            ->with($this->equalTo($object))
1589
            ->will($this->returnValue($toStringValue));
1590
1591
        $this->expectTranslate('flash_edit_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1592
1593
        $this->request->setMethod('POST');
1594
1595
        $formView = $this->createMock(FormView::class);
1596
1597
        $form->expects($this->any())
1598
            ->method('createView')
1599
            ->will($this->returnValue($formView));
1600
1601
        $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...
1602
1603
        $this->assertSame($this->admin, $this->parameters['admin']);
1604
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1605
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1606
1607
        $this->assertSame('edit', $this->parameters['action']);
1608
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1609
        $this->assertSame($object, $this->parameters['object']);
1610
1611
        $this->assertSame(['sonata_flash_error' => ['flash_edit_error']], $this->session->getFlashBag()->all());
1612
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1613
    }
1614
1615
    public function testEditActionAjaxSuccess(): void
1616
    {
1617
        $object = new \stdClass();
1618
1619
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

Loading history...
1628
            ->method('checkAccess')
1629
            ->with($this->equalTo('edit'))
1630
            ->will($this->returnValue(true));
1631
1632
        $form = $this->createMock(Form::class);
1633
1634
        $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...
1635
            ->method('getForm')
1636
            ->will($this->returnValue($form));
1637
1638
        $form->expects($this->once())
1639
            ->method('isSubmitted')
1640
            ->will($this->returnValue(true));
1641
1642
        $form->expects($this->once())
1643
            ->method('isValid')
1644
            ->will($this->returnValue(true));
1645
1646
        $form->expects($this->once())
1647
            ->method('getData')
1648
            ->will($this->returnValue($object));
1649
1650
        $form->expects($this->once())
1651
            ->method('all')
1652
            ->willReturn(['field' => 'fielddata']);
1653
1654
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
1660
            ->method('toString')
1661
            ->will($this->returnValue('foo'));
1662
1663
        $this->request->setMethod('POST');
1664
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1665
1666
        $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...
1667
1668
        $this->assertInstanceOf(Response::class, $response);
1669
        $this->assertSame(json_encode(['result' => 'ok', 'objectId' => 'foo_normalized', 'objectName' => 'foo']), $response->getContent());
1670
        $this->assertSame([], $this->session->getFlashBag()->all());
1671
    }
1672
1673
    public function testEditActionAjaxError(): void
1674
    {
1675
        $object = new \stdClass();
1676
1677
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
1682
            ->method('checkAccess')
1683
            ->with($this->equalTo('edit'))
1684
            ->will($this->returnValue(true));
1685
1686
        $form = $this->createMock(Form::class);
1687
1688
        $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...
1689
            ->method('getForm')
1690
            ->will($this->returnValue($form));
1691
1692
        $form->expects($this->once())
1693
            ->method('isSubmitted')
1694
            ->will($this->returnValue(true));
1695
1696
        $form->expects($this->once())
1697
            ->method('isValid')
1698
            ->will($this->returnValue(false));
1699
1700
        $form->expects($this->once())
1701
            ->method('all')
1702
            ->willReturn(['field' => 'fielddata']);
1703
1704
        $this->request->setMethod('POST');
1705
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1706
1707
        $formView = $this->createMock(FormView::class);
1708
1709
        $form->expects($this->any())
1710
            ->method('createView')
1711
            ->will($this->returnValue($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/ajax_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([], $this->session->getFlashBag()->all());
1724
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1725
    }
1726
1727
    /**
1728
     * @dataProvider getToStringValues
1729
     */
1730
    public function testEditActionWithModelManagerException($expectedToStringValue, $toStringValue): void
1731
    {
1732
        $object = new \stdClass();
1733
1734
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
1739
            ->method('checkAccess')
1740
            ->with($this->equalTo('edit'))
1741
            ->will($this->returnValue(true));
1742
1743
        $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...
1744
            ->method('getClass')
1745
            ->will($this->returnValue('stdClass'));
1746
1747
        $form = $this->createMock(Form::class);
1748
1749
        $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...
1750
            ->method('getForm')
1751
            ->will($this->returnValue($form));
1752
1753
        $form->expects($this->once())
1754
            ->method('isValid')
1755
            ->will($this->returnValue(true));
1756
1757
        $form->expects($this->once())
1758
            ->method('getData')
1759
            ->will($this->returnValue($object));
1760
1761
        $form->expects($this->once())
1762
            ->method('all')
1763
            ->willReturn(['field' => 'fielddata']);
1764
1765
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1766
            ->method('toString')
1767
            ->with($this->equalTo($object))
1768
            ->will($this->returnValue($toStringValue));
1769
1770
        $this->expectTranslate('flash_edit_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1771
1772
        $form->expects($this->once())
1773
            ->method('isSubmitted')
1774
            ->will($this->returnValue(true));
1775
        $this->request->setMethod('POST');
1776
1777
        $formView = $this->createMock(FormView::class);
1778
1779
        $form->expects($this->any())
1780
            ->method('createView')
1781
            ->will($this->returnValue($formView));
1782
1783
        $this->assertLoggerLogsModelManagerException($this->admin, 'update');
1784
        $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...
1785
1786
        $this->assertSame($this->admin, $this->parameters['admin']);
1787
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1788
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1789
1790
        $this->assertSame('edit', $this->parameters['action']);
1791
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1792
        $this->assertSame($object, $this->parameters['object']);
1793
1794
        $this->assertSame(['sonata_flash_error' => ['flash_edit_error']], $this->session->getFlashBag()->all());
1795
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1796
    }
1797
1798
    public function testEditActionWithPreview(): void
1799
    {
1800
        $object = new \stdClass();
1801
1802
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
1807
            ->method('checkAccess')
1808
            ->with($this->equalTo('edit'))
1809
            ->will($this->returnValue(true));
1810
1811
        $form = $this->createMock(Form::class);
1812
1813
        $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...
1814
            ->method('getForm')
1815
            ->will($this->returnValue($form));
1816
1817
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1818
            ->method('supportsPreviewMode')
1819
            ->will($this->returnValue(true));
1820
1821
        $formView = $this->createMock(FormView::class);
1822
1823
        $form->expects($this->any())
1824
            ->method('createView')
1825
            ->will($this->returnValue($formView));
1826
1827
        $form->expects($this->once())
1828
            ->method('isSubmitted')
1829
            ->will($this->returnValue(true));
1830
1831
        $form->expects($this->once())
1832
            ->method('isValid')
1833
            ->will($this->returnValue(true));
1834
1835
        $form->expects($this->once())
1836
            ->method('all')
1837
            ->willReturn(['field' => 'fielddata']);
1838
1839
        $this->request->setMethod('POST');
1840
        $this->request->request->set('btn_preview', 'Preview');
1841
1842
        $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...
1843
1844
        $this->assertSame($this->admin, $this->parameters['admin']);
1845
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1846
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1847
1848
        $this->assertSame('edit', $this->parameters['action']);
1849
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1850
        $this->assertSame($object, $this->parameters['object']);
1851
1852
        $this->assertSame([], $this->session->getFlashBag()->all());
1853
        $this->assertSame('@SonataAdmin/CRUD/preview.html.twig', $this->template);
1854
    }
1855
1856
    public function testEditActionWithLockException(): void
1857
    {
1858
        $object = new \stdClass();
1859
        $class = get_class($object);
1860
1861
        $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...
1862
            ->method('getObject')
1863
            ->will($this->returnValue($object));
1864
1865
        $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...
1866
            ->method('checkAccess')
1867
            ->with($this->equalTo('edit'))
1868
            ->will($this->returnValue(true));
1869
1870
        $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...
1871
            ->method('getClass')
1872
            ->will($this->returnValue($class));
1873
1874
        $form = $this->createMock(Form::class);
1875
1876
        $form->expects($this->any())
1877
            ->method('isValid')
1878
            ->will($this->returnValue(true));
1879
1880
        $form->expects($this->once())
1881
            ->method('getData')
1882
            ->will($this->returnValue($object));
1883
1884
        $form->expects($this->once())
1885
            ->method('all')
1886
            ->willReturn(['field' => 'fielddata']);
1887
1888
        $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...
1889
            ->method('getForm')
1890
            ->will($this->returnValue($form));
1891
1892
        $form->expects($this->any())
1893
            ->method('isSubmitted')
1894
            ->will($this->returnValue(true));
1895
        $this->request->setMethod('POST');
1896
1897
        $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...
1898
            ->method('update')
1899
            ->will($this->throwException(new LockException()));
1900
1901
        $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...
1902
            ->method('toString')
1903
            ->with($this->equalTo($object))
1904
            ->will($this->returnValue($class));
1905
1906
        $formView = $this->createMock(FormView::class);
1907
1908
        $form->expects($this->any())
1909
            ->method('createView')
1910
            ->will($this->returnValue($formView));
1911
1912
        $this->expectTranslate('flash_lock_error', [
1913
            '%name%' => $class,
1914
            '%link_start%' => '<a href="stdClass_edit">',
1915
            '%link_end%' => '</a>',
1916
        ], 'SonataAdminBundle');
1917
1918
        $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...
1919
    }
1920
1921
    public function testCreateActionAccessDenied(): void
1922
    {
1923
        $this->expectException(AccessDeniedException::class);
1924
1925
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1926
            ->method('checkAccess')
1927
            ->with($this->equalTo('create'))
1928
            ->will($this->throwException(new AccessDeniedException()));
1929
1930
        $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...
1931
    }
1932
1933
    public function testPreCreate(): void
1934
    {
1935
        $object = new \stdClass();
1936
        $object->foo = 123456;
1937
1938
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1939
            ->method('checkAccess')
1940
            ->with($this->equalTo('create'))
1941
            ->will($this->returnValue(true));
1942
1943
        $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...
1944
            ->method('getClass')
1945
            ->will($this->returnValue('stdClass'));
1946
1947
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1948
            ->method('getNewInstance')
1949
            ->will($this->returnValue($object));
1950
1951
        $controller = new PreCRUDController();
1952
        $controller->setContainer($this->container);
1953
1954
        $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...
1955
        $this->assertInstanceOf(Response::class, $response);
1956
        $this->assertSame('preCreate called: 123456', $response->getContent());
1957
    }
1958
1959
    public function testCreateAction(): void
1960
    {
1961
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1962
            ->method('checkAccess')
1963
            ->with($this->equalTo('create'))
1964
            ->will($this->returnValue(true));
1965
1966
        $object = new \stdClass();
1967
1968
        $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...
1969
            ->method('getClass')
1970
            ->will($this->returnValue('stdClass'));
1971
1972
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
1973
            ->method('getNewInstance')
1974
            ->will($this->returnValue($object));
1975
1976
        $form = $this->createMock(Form::class);
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('getForm')
1980
            ->will($this->returnValue($form));
1981
1982
        $formView = $this->createMock(FormView::class);
1983
1984
        $form->expects($this->any())
1985
            ->method('createView')
1986
            ->will($this->returnValue($formView));
1987
1988
        $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...
1989
1990
        $this->assertSame($this->admin, $this->parameters['admin']);
1991
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1992
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1993
1994
        $this->assertSame('create', $this->parameters['action']);
1995
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1996
        $this->assertSame($object, $this->parameters['object']);
1997
1998
        $this->assertSame([], $this->session->getFlashBag()->all());
1999
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
2000
    }
2001
2002
    /**
2003
     * @dataProvider getToStringValues
2004
     */
2005
    public function testCreateActionSuccess($expectedToStringValue, $toStringValue): void
2006
    {
2007
        $object = new \stdClass();
2008
2009
        $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...
2010
            ->method('checkAccess')
2011
            ->will($this->returnCallback(function ($name, $objectIn = null) use ($object) {
2012
                if ('edit' == $name) {
2013
                    return true;
2014
                }
2015
2016
                if ('create' != $name) {
2017
                    return false;
2018
                }
2019
2020
                if (null === $objectIn) {
2021
                    return true;
2022
                }
2023
2024
                return $objectIn === $object;
2025
            }));
2026
2027
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
2033
            ->method('hasAccess')
2034
            ->with($this->equalTo('edit'))
2035
            ->will($this->returnValue(true));
2036
2037
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
2042
            ->method('create')
2043
            ->will($this->returnArgument(0));
2044
2045
        $form = $this->createMock(Form::class);
2046
2047
        $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...
2048
            ->method('getClass')
2049
            ->will($this->returnValue('stdClass'));
2050
2051
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2052
            ->method('getForm')
2053
            ->will($this->returnValue($form));
2054
2055
        $form->expects($this->once())
2056
            ->method('isSubmitted')
2057
            ->will($this->returnValue(true));
2058
2059
        $form->expects($this->once())
2060
            ->method('isValid')
2061
            ->will($this->returnValue(true));
2062
2063
        $form->expects($this->once())
2064
            ->method('getData')
2065
            ->will($this->returnValue($object));
2066
2067
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2068
            ->method('toString')
2069
            ->with($this->equalTo($object))
2070
            ->will($this->returnValue($toStringValue));
2071
2072
        $this->expectTranslate('flash_create_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
2073
2074
        $this->request->setMethod('POST');
2075
2076
        $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...
2077
2078
        $this->assertInstanceOf(RedirectResponse::class, $response);
2079
        $this->assertSame(['flash_create_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
2080
        $this->assertSame('stdClass_edit', $response->getTargetUrl());
2081
    }
2082
2083
    public function testCreateActionAccessDenied2(): void
2084
    {
2085
        $this->expectException(AccessDeniedException::class);
2086
2087
        $object = new \stdClass();
2088
2089
        $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...
2090
            ->method('checkAccess')
2091
            ->will($this->returnCallback(function ($name, $object = null) {
2092
                if ('create' != $name) {
2093
                    throw new AccessDeniedException();
2094
                }
2095
                if (null === $object) {
2096
                    return true;
2097
                }
2098
2099
                throw new AccessDeniedException();
2100
            }));
2101
2102
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2103
            ->method('getNewInstance')
2104
            ->will($this->returnValue($object));
2105
2106
        $form = $this->createMock(Form::class);
2107
2108
        $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...
2109
            ->method('getClass')
2110
            ->will($this->returnValue('stdClass'));
2111
2112
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2113
            ->method('getForm')
2114
            ->will($this->returnValue($form));
2115
2116
        $form->expects($this->once())
2117
            ->method('isSubmitted')
2118
            ->will($this->returnValue(true));
2119
2120
        $form->expects($this->once())
2121
            ->method('getData')
2122
            ->will($this->returnValue($object));
2123
2124
        $form->expects($this->once())
2125
            ->method('isValid')
2126
            ->will($this->returnValue(true));
2127
2128
        $this->request->setMethod('POST');
2129
2130
        $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...
2131
    }
2132
2133
    /**
2134
     * @dataProvider getToStringValues
2135
     */
2136
    public function testCreateActionError($expectedToStringValue, $toStringValue): void
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('checkAccess')
2140
            ->with($this->equalTo('create'))
2141
            ->will($this->returnValue(true));
2142
2143
        $object = new \stdClass();
2144
2145
        $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...
2146
            ->method('getClass')
2147
            ->will($this->returnValue('stdClass'));
2148
2149
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2150
            ->method('getNewInstance')
2151
            ->will($this->returnValue($object));
2152
2153
        $form = $this->createMock(Form::class);
2154
2155
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2156
            ->method('getForm')
2157
            ->will($this->returnValue($form));
2158
2159
        $form->expects($this->once())
2160
            ->method('isSubmitted')
2161
            ->will($this->returnValue(true));
2162
2163
        $form->expects($this->once())
2164
            ->method('isValid')
2165
            ->will($this->returnValue(false));
2166
2167
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2168
            ->method('toString')
2169
            ->with($this->equalTo($object))
2170
            ->will($this->returnValue($toStringValue));
2171
2172
        $this->expectTranslate('flash_create_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
2173
2174
        $this->request->setMethod('POST');
2175
2176
        $formView = $this->createMock(FormView::class);
2177
2178
        $form->expects($this->any())
2179
            ->method('createView')
2180
            ->will($this->returnValue($formView));
2181
2182
        $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...
2183
2184
        $this->assertSame($this->admin, $this->parameters['admin']);
2185
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2186
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2187
2188
        $this->assertSame('create', $this->parameters['action']);
2189
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2190
        $this->assertSame($object, $this->parameters['object']);
2191
2192
        $this->assertSame(['sonata_flash_error' => ['flash_create_error']], $this->session->getFlashBag()->all());
2193
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
2194
    }
2195
2196
    /**
2197
     * @dataProvider getToStringValues
2198
     */
2199
    public function testCreateActionWithModelManagerException($expectedToStringValue, $toStringValue): void
2200
    {
2201
        $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...
2202
            ->method('checkAccess')
2203
            ->with($this->equalTo('create'))
2204
            ->will($this->returnValue(true));
2205
2206
        $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...
2207
            ->method('getClass')
2208
            ->will($this->returnValue('stdClass'));
2209
2210
        $object = new \stdClass();
2211
2212
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2213
            ->method('getNewInstance')
2214
            ->will($this->returnValue($object));
2215
2216
        $form = $this->createMock(Form::class);
2217
2218
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2219
            ->method('getForm')
2220
            ->will($this->returnValue($form));
2221
2222
        $form->expects($this->once())
2223
            ->method('isValid')
2224
            ->will($this->returnValue(true));
2225
2226
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2227
            ->method('toString')
2228
            ->with($this->equalTo($object))
2229
            ->will($this->returnValue($toStringValue));
2230
2231
        $this->expectTranslate('flash_create_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
2232
2233
        $form->expects($this->once())
2234
            ->method('isSubmitted')
2235
            ->will($this->returnValue(true));
2236
2237
        $form->expects($this->once())
2238
            ->method('getData')
2239
            ->will($this->returnValue($object));
2240
2241
        $this->request->setMethod('POST');
2242
2243
        $formView = $this->createMock(FormView::class);
2244
2245
        $form->expects($this->any())
2246
            ->method('createView')
2247
            ->will($this->returnValue($formView));
2248
2249
        $this->assertLoggerLogsModelManagerException($this->admin, 'create');
2250
2251
        $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...
2252
2253
        $this->assertSame($this->admin, $this->parameters['admin']);
2254
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2255
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2256
2257
        $this->assertSame('create', $this->parameters['action']);
2258
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2259
        $this->assertSame($object, $this->parameters['object']);
2260
2261
        $this->assertSame(['sonata_flash_error' => ['flash_create_error']], $this->session->getFlashBag()->all());
2262
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
2263
    }
2264
2265
    public function testCreateActionAjaxSuccess(): void
2266
    {
2267
        $object = new \stdClass();
2268
2269
        $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...
2270
            ->method('checkAccess')
2271
            ->will($this->returnCallback(function ($name, $objectIn = null) use ($object) {
2272
                if ('create' != $name) {
2273
                    return false;
2274
                }
2275
2276
                if (null === $objectIn) {
2277
                    return true;
2278
                }
2279
2280
                return $objectIn === $object;
2281
            }));
2282
2283
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
2288
            ->method('create')
2289
            ->will($this->returnArgument(0));
2290
2291
        $form = $this->createMock(Form::class);
2292
2293
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2294
            ->method('getForm')
2295
            ->will($this->returnValue($form));
2296
2297
        $form->expects($this->once())
2298
            ->method('isSubmitted')
2299
            ->will($this->returnValue(true));
2300
2301
        $form->expects($this->once())
2302
            ->method('isValid')
2303
            ->will($this->returnValue(true));
2304
2305
        $form->expects($this->once())
2306
            ->method('getData')
2307
            ->will($this->returnValue($object));
2308
2309
        $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...
2310
            ->method('getClass')
2311
            ->will($this->returnValue('stdClass'));
2312
2313
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2314
            ->method('getNormalizedIdentifier')
2315
            ->with($this->equalTo($object))
2316
            ->will($this->returnValue('foo_normalized'));
2317
2318
        $this->request->setMethod('POST');
2319
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
2320
2321
        $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...
2322
2323
        $this->assertInstanceOf(Response::class, $response);
2324
        $this->assertSame(json_encode(['result' => 'ok', 'objectId' => 'foo_normalized']), $response->getContent());
2325
        $this->assertSame([], $this->session->getFlashBag()->all());
2326
    }
2327
2328
    public function testCreateActionAjaxError(): void
2329
    {
2330
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2331
            ->method('checkAccess')
2332
            ->with($this->equalTo('create'))
2333
            ->will($this->returnValue(true));
2334
2335
        $object = new \stdClass();
2336
2337
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2338
            ->method('getNewInstance')
2339
            ->will($this->returnValue($object));
2340
2341
        $form = $this->createMock(Form::class);
2342
2343
        $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...
2344
            ->method('getClass')
2345
            ->will($this->returnValue('stdClass'));
2346
2347
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2348
            ->method('getForm')
2349
            ->will($this->returnValue($form));
2350
2351
        $form->expects($this->once())
2352
            ->method('isSubmitted')
2353
            ->will($this->returnValue(true));
2354
2355
        $form->expects($this->once())
2356
            ->method('isValid')
2357
            ->will($this->returnValue(false));
2358
2359
        $this->request->setMethod('POST');
2360
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
2361
2362
        $formView = $this->createMock(FormView::class);
2363
2364
        $form->expects($this->any())
2365
            ->method('createView')
2366
            ->will($this->returnValue($formView));
2367
2368
        $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...
2369
2370
        $this->assertSame($this->admin, $this->parameters['admin']);
2371
        $this->assertSame('@SonataAdmin/ajax_layout.html.twig', $this->parameters['base_template']);
2372
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2373
2374
        $this->assertSame('create', $this->parameters['action']);
2375
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2376
        $this->assertSame($object, $this->parameters['object']);
2377
2378
        $this->assertSame([], $this->session->getFlashBag()->all());
2379
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
2380
    }
2381
2382
    public function testCreateActionWithPreview(): void
2383
    {
2384
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2385
            ->method('checkAccess')
2386
            ->with($this->equalTo('create'))
2387
            ->will($this->returnValue(true));
2388
2389
        $object = new \stdClass();
2390
2391
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2392
            ->method('getNewInstance')
2393
            ->will($this->returnValue($object));
2394
2395
        $form = $this->createMock(Form::class);
2396
2397
        $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...
2398
            ->method('getClass')
2399
            ->will($this->returnValue('stdClass'));
2400
2401
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
2406
            ->method('supportsPreviewMode')
2407
            ->will($this->returnValue(true));
2408
2409
        $formView = $this->createMock(FormView::class);
2410
2411
        $form->expects($this->any())
2412
            ->method('createView')
2413
            ->will($this->returnValue($formView));
2414
2415
        $form->expects($this->once())
2416
            ->method('isSubmitted')
2417
            ->will($this->returnValue(true));
2418
2419
        $form->expects($this->once())
2420
            ->method('isValid')
2421
            ->will($this->returnValue(true));
2422
2423
        $this->request->setMethod('POST');
2424
        $this->request->request->set('btn_preview', 'Preview');
2425
2426
        $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...
2427
2428
        $this->assertSame($this->admin, $this->parameters['admin']);
2429
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2430
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2431
2432
        $this->assertSame('create', $this->parameters['action']);
2433
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2434
        $this->assertSame($object, $this->parameters['object']);
2435
2436
        $this->assertSame([], $this->session->getFlashBag()->all());
2437
        $this->assertSame('@SonataAdmin/CRUD/preview.html.twig', $this->template);
2438
    }
2439
2440
    public function testExportActionAccessDenied(): void
2441
    {
2442
        $this->expectException(AccessDeniedException::class);
2443
2444
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2445
            ->method('checkAccess')
2446
            ->with($this->equalTo('export'))
2447
            ->will($this->throwException(new AccessDeniedException()));
2448
2449
        $this->controller->exportAction($this->request);
2450
    }
2451
2452
    public function testExportActionWrongFormat(): void
2453
    {
2454
        $this->expectException(\RuntimeException::class, 'Export in format `csv` is not allowed for class: `Foo`. Allowed formats are: `json`');
2455
2456
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
2462
            ->method('getExportFormats')
2463
            ->will($this->returnValue(['json']));
2464
2465
        $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...
2466
            ->method('getClass')
2467
            ->will($this->returnValue('Foo'));
2468
2469
        $this->request->query->set('format', 'csv');
2470
2471
        $this->controller->exportAction($this->request);
2472
    }
2473
2474
    public function testExportAction(): void
2475
    {
2476
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

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

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

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

Loading history...
2486
            ->method('getClass')
2487
            ->will($this->returnValue(\stdClass::class));
2488
2489
        $dataSourceIterator = $this->createMock(SourceIteratorInterface::class);
2490
2491
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2492
            ->method('getDataSourceIterator')
2493
            ->will($this->returnValue($dataSourceIterator));
2494
2495
        $this->request->query->set('format', 'json');
2496
2497
        $response = $this->controller->exportAction($this->request);
2498
        $this->assertInstanceOf(StreamedResponse::class, $response);
2499
        $this->assertSame(200, $response->getStatusCode());
2500
        $this->assertSame([], $this->session->getFlashBag()->all());
2501
    }
2502
2503
    public function testHistoryActionAccessDenied(): void
2504
    {
2505
        $this->expectException(AccessDeniedException::class);
2506
2507
        $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...
2508
            ->method('getObject')
2509
            ->will($this->returnValue(new \StdClass()));
2510
2511
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2512
            ->method('checkAccess')
2513
            ->with($this->equalTo('history'))
2514
            ->will($this->throwException(new AccessDeniedException()));
2515
2516
        $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...
2517
    }
2518
2519
    public function testHistoryActionNotFoundException(): void
2520
    {
2521
        $this->expectException(NotFoundHttpException::class);
2522
2523
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2524
            ->method('getObject')
2525
            ->will($this->returnValue(false));
2526
2527
        $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...
2528
    }
2529
2530
    public function testHistoryActionNoReader(): void
2531
    {
2532
        $this->expectException(NotFoundHttpException::class, 'unable to find the audit reader for class : Foo');
2533
2534
        $this->request->query->set('id', 123);
2535
2536
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2537
            ->method('checkAccess')
2538
            ->with($this->equalTo('history'))
2539
            ->will($this->returnValue(true));
2540
2541
        $object = new \stdClass();
2542
2543
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2544
            ->method('getObject')
2545
            ->will($this->returnValue($object));
2546
2547
        $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...
2548
            ->method('getClass')
2549
            ->will($this->returnValue('Foo'));
2550
2551
        $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...
2552
            ->method('hasReader')
2553
            ->with($this->equalTo('Foo'))
2554
            ->will($this->returnValue(false));
2555
2556
        $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...
2557
    }
2558
2559
    public function testHistoryAction(): void
2560
    {
2561
        $this->request->query->set('id', 123);
2562
2563
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2564
            ->method('checkAccess')
2565
            ->with($this->equalTo('history'))
2566
            ->will($this->returnValue(true));
2567
2568
        $object = new \stdClass();
2569
2570
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2571
            ->method('getObject')
2572
            ->will($this->returnValue($object));
2573
2574
        $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...
2575
            ->method('getClass')
2576
            ->will($this->returnValue('Foo'));
2577
2578
        $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...
2579
            ->method('hasReader')
2580
            ->with($this->equalTo('Foo'))
2581
            ->will($this->returnValue(true));
2582
2583
        $reader = $this->createMock(AuditReaderInterface::class);
2584
2585
        $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...
2586
            ->method('getReader')
2587
            ->with($this->equalTo('Foo'))
2588
            ->will($this->returnValue($reader));
2589
2590
        $reader->expects($this->once())
2591
            ->method('findRevisions')
2592
            ->with($this->equalTo('Foo'), $this->equalTo(123))
2593
            ->will($this->returnValue([]));
2594
2595
        $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...
2596
2597
        $this->assertSame($this->admin, $this->parameters['admin']);
2598
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2599
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2600
2601
        $this->assertSame('history', $this->parameters['action']);
2602
        $this->assertSame([], $this->parameters['revisions']);
2603
        $this->assertSame($object, $this->parameters['object']);
2604
2605
        $this->assertSame([], $this->session->getFlashBag()->all());
2606
        $this->assertSame('@SonataAdmin/CRUD/history.html.twig', $this->template);
2607
    }
2608
2609
    public function testAclActionAclNotEnabled(): void
2610
    {
2611
        $this->expectException(NotFoundHttpException::class, 'ACL are not enabled for this admin');
2612
2613
        $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...
2614
    }
2615
2616
    public function testAclActionNotFoundException(): void
2617
    {
2618
        $this->expectException(NotFoundHttpException::class);
2619
2620
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
2625
            ->method('getObject')
2626
            ->will($this->returnValue(false));
2627
2628
        $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...
2629
    }
2630
2631
    public function testAclActionAccessDenied(): void
2632
    {
2633
        $this->expectException(AccessDeniedException::class);
2634
2635
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2636
            ->method('isAclEnabled')
2637
            ->will($this->returnValue(true));
2638
2639
        $object = new \stdClass();
2640
2641
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
2646
            ->method('checkAccess')
2647
            ->with($this->equalTo('acl'), $this->equalTo($object))
2648
            ->will($this->throwException(new AccessDeniedException()));
2649
2650
        $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...
2651
    }
2652
2653
    public function testAclAction(): void
2654
    {
2655
        $this->request->query->set('id', 123);
2656
2657
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2658
            ->method('isAclEnabled')
2659
            ->will($this->returnValue(true));
2660
2661
        $object = new \stdClass();
2662
2663
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2664
            ->method('getObject')
2665
            ->will($this->returnValue($object));
2666
2667
        $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...
2668
            ->method('checkAccess')
2669
            ->will($this->returnValue(true));
2670
2671
        $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...
2672
            ->method('getSecurityInformation')
2673
            ->will($this->returnValue([]));
2674
2675
        $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...
2676
            ->method('getMaskBuilderClass')
2677
            ->will($this->returnValue(AdminPermissionMap::class));
2678
2679
        $aclUsersForm = $this->getMockBuilder(Form::class)
2680
            ->disableOriginalConstructor()
2681
            ->getMock();
2682
2683
        $aclUsersForm->expects($this->once())
2684
            ->method('createView')
2685
            ->will($this->returnValue($this->createMock(FormView::class)));
2686
2687
        $aclRolesForm = $this->getMockBuilder(Form::class)
2688
            ->disableOriginalConstructor()
2689
            ->getMock();
2690
2691
        $aclRolesForm->expects($this->once())
2692
            ->method('createView')
2693
            ->will($this->returnValue($this->createMock(FormView::class)));
2694
2695
        $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...
2696
            ->method('createAclUsersForm')
2697
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2698
            ->will($this->returnValue($aclUsersForm));
2699
2700
        $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...
2701
            ->method('createAclRolesForm')
2702
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2703
            ->will($this->returnValue($aclRolesForm));
2704
2705
        $aclSecurityHandler = $this->getMockBuilder(AclSecurityHandler::class)
2706
            ->disableOriginalConstructor()
2707
            ->getMock();
2708
2709
        $aclSecurityHandler->expects($this->any())
2710
            ->method('getObjectPermissions')
2711
            ->will($this->returnValue([]));
2712
2713
        $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...
2714
            ->method('getSecurityHandler')
2715
            ->will($this->returnValue($aclSecurityHandler));
2716
2717
        $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...
2718
2719
        $this->assertSame($this->admin, $this->parameters['admin']);
2720
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2721
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2722
2723
        $this->assertSame('acl', $this->parameters['action']);
2724
        $this->assertSame([], $this->parameters['permissions']);
2725
        $this->assertSame($object, $this->parameters['object']);
2726
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['users']);
2727
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['roles']);
2728
        $this->assertInstanceOf(FormView::class, $this->parameters['aclUsersForm']);
2729
        $this->assertInstanceOf(FormView::class, $this->parameters['aclRolesForm']);
2730
2731
        $this->assertSame([], $this->session->getFlashBag()->all());
2732
        $this->assertSame('@SonataAdmin/CRUD/acl.html.twig', $this->template);
2733
    }
2734
2735
    public function testAclActionInvalidUpdate(): void
2736
    {
2737
        $this->request->query->set('id', 123);
2738
        $this->request->request->set(AdminObjectAclManipulator::ACL_USERS_FORM_NAME, []);
2739
2740
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
2747
            ->method('getObject')
2748
            ->will($this->returnValue($object));
2749
2750
        $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...
2751
            ->method('checkAccess')
2752
            ->will($this->returnValue(true));
2753
2754
        $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...
2755
            ->method('getSecurityInformation')
2756
            ->will($this->returnValue([]));
2757
2758
        $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...
2759
            ->method('getMaskBuilderClass')
2760
            ->will($this->returnValue(AdminPermissionMap::class));
2761
2762
        $aclUsersForm = $this->getMockBuilder(Form::class)
2763
            ->disableOriginalConstructor()
2764
            ->getMock();
2765
2766
        $aclUsersForm->expects($this->once())
2767
            ->method('isValid')
2768
            ->will($this->returnValue(false));
2769
2770
        $aclUsersForm->expects($this->once())
2771
            ->method('createView')
2772
            ->will($this->returnValue($this->createMock(FormView::class)));
2773
2774
        $aclRolesForm = $this->getMockBuilder(Form::class)
2775
            ->disableOriginalConstructor()
2776
            ->getMock();
2777
2778
        $aclRolesForm->expects($this->once())
2779
            ->method('createView')
2780
            ->will($this->returnValue($this->createMock(FormView::class)));
2781
2782
        $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...
2783
            ->method('createAclUsersForm')
2784
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2785
            ->will($this->returnValue($aclUsersForm));
2786
2787
        $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...
2788
            ->method('createAclRolesForm')
2789
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2790
            ->will($this->returnValue($aclRolesForm));
2791
2792
        $aclSecurityHandler = $this->getMockBuilder(AclSecurityHandler::class)
2793
            ->disableOriginalConstructor()
2794
            ->getMock();
2795
2796
        $aclSecurityHandler->expects($this->any())
2797
            ->method('getObjectPermissions')
2798
            ->will($this->returnValue([]));
2799
2800
        $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...
2801
            ->method('getSecurityHandler')
2802
            ->will($this->returnValue($aclSecurityHandler));
2803
2804
        $this->request->setMethod('POST');
2805
2806
        $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...
2807
2808
        $this->assertSame($this->admin, $this->parameters['admin']);
2809
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2810
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2811
2812
        $this->assertSame('acl', $this->parameters['action']);
2813
        $this->assertSame([], $this->parameters['permissions']);
2814
        $this->assertSame($object, $this->parameters['object']);
2815
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['users']);
2816
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['roles']);
2817
        $this->assertInstanceOf(FormView::class, $this->parameters['aclUsersForm']);
2818
        $this->assertInstanceOf(FormView::class, $this->parameters['aclRolesForm']);
2819
2820
        $this->assertSame([], $this->session->getFlashBag()->all());
2821
        $this->assertSame('@SonataAdmin/CRUD/acl.html.twig', $this->template);
2822
    }
2823
2824
    public function testAclActionSuccessfulUpdate(): void
2825
    {
2826
        $this->request->query->set('id', 123);
2827
        $this->request->request->set(AdminObjectAclManipulator::ACL_ROLES_FORM_NAME, []);
2828
2829
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2830
            ->method('isAclEnabled')
2831
            ->will($this->returnValue(true));
2832
2833
        $object = new \stdClass();
2834
2835
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2836
            ->method('getObject')
2837
            ->will($this->returnValue($object));
2838
2839
        $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...
2840
            ->method('checkAccess')
2841
            ->will($this->returnValue(true));
2842
2843
        $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...
2844
            ->method('getSecurityInformation')
2845
            ->will($this->returnValue([]));
2846
2847
        $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...
2848
            ->method('getMaskBuilderClass')
2849
            ->will($this->returnValue(AdminPermissionMap::class));
2850
2851
        $aclUsersForm = $this->getMockBuilder(Form::class)
2852
            ->disableOriginalConstructor()
2853
            ->getMock();
2854
2855
        $aclUsersForm->expects($this->any())
2856
            ->method('createView')
2857
            ->will($this->returnValue($this->createMock(FormView::class)));
2858
2859
        $aclRolesForm = $this->getMockBuilder(Form::class)
2860
            ->disableOriginalConstructor()
2861
            ->getMock();
2862
2863
        $aclRolesForm->expects($this->any())
2864
            ->method('createView')
2865
            ->will($this->returnValue($this->createMock(FormView::class)));
2866
2867
        $aclRolesForm->expects($this->once())
2868
            ->method('isValid')
2869
            ->will($this->returnValue(true));
2870
2871
        $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...
2872
            ->method('createAclUsersForm')
2873
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2874
            ->will($this->returnValue($aclUsersForm));
2875
2876
        $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...
2877
            ->method('createAclRolesForm')
2878
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2879
            ->will($this->returnValue($aclRolesForm));
2880
2881
        $aclSecurityHandler = $this->getMockBuilder(AclSecurityHandler::class)
2882
            ->disableOriginalConstructor()
2883
            ->getMock();
2884
2885
        $aclSecurityHandler->expects($this->any())
2886
            ->method('getObjectPermissions')
2887
            ->will($this->returnValue([]));
2888
2889
        $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...
2890
            ->method('getSecurityHandler')
2891
            ->will($this->returnValue($aclSecurityHandler));
2892
2893
        $this->expectTranslate('flash_acl_edit_success', [], 'SonataAdminBundle');
2894
2895
        $this->request->setMethod('POST');
2896
2897
        $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...
2898
2899
        $this->assertInstanceOf(RedirectResponse::class, $response);
2900
2901
        $this->assertSame(['flash_acl_edit_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
2902
        $this->assertSame('stdClass_acl', $response->getTargetUrl());
2903
    }
2904
2905
    public function testHistoryViewRevisionActionAccessDenied(): void
2906
    {
2907
        $this->expectException(AccessDeniedException::class);
2908
2909
        $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...
2910
            ->method('getObject')
2911
            ->will($this->returnValue(new \StdClass()));
2912
2913
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2914
            ->method('checkAccess')
2915
            ->with($this->equalTo('historyViewRevision'))
2916
            ->will($this->throwException(new AccessDeniedException()));
2917
2918
        $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...
2919
    }
2920
2921
    public function testHistoryViewRevisionActionNotFoundException(): void
2922
    {
2923
        $this->expectException(NotFoundHttpException::class, 'unable to find the object with id: 123');
2924
2925
        $this->request->query->set('id', 123);
2926
2927
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2928
            ->method('getObject')
2929
            ->will($this->returnValue(false));
2930
2931
        $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...
2932
    }
2933
2934
    public function testHistoryViewRevisionActionNoReader(): void
2935
    {
2936
        $this->expectException(NotFoundHttpException::class, 'unable to find the audit reader for class : Foo');
2937
2938
        $this->request->query->set('id', 123);
2939
2940
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2941
            ->method('checkAccess')
2942
            ->with($this->equalTo('historyViewRevision'))
2943
            ->will($this->returnValue(true));
2944
2945
        $object = new \stdClass();
2946
2947
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getObject')
2949
            ->will($this->returnValue($object));
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('getClass')
2953
            ->will($this->returnValue('Foo'));
2954
2955
        $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...
2956
            ->method('hasReader')
2957
            ->with($this->equalTo('Foo'))
2958
            ->will($this->returnValue(false));
2959
2960
        $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...
2961
    }
2962
2963
    public function testHistoryViewRevisionActionNotFoundRevision(): void
2964
    {
2965
        $this->expectException(NotFoundHttpException::class, 'unable to find the targeted object `123` from the revision `456` with classname : `Foo`');
2966
2967
        $this->request->query->set('id', 123);
2968
2969
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2970
            ->method('checkAccess')
2971
            ->with($this->equalTo('historyViewRevision'))
2972
            ->will($this->returnValue(true));
2973
2974
        $object = new \stdClass();
2975
2976
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
2977
            ->method('getObject')
2978
            ->will($this->returnValue($object));
2979
2980
        $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...
2981
            ->method('getClass')
2982
            ->will($this->returnValue('Foo'));
2983
2984
        $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...
2985
            ->method('hasReader')
2986
            ->with($this->equalTo('Foo'))
2987
            ->will($this->returnValue(true));
2988
2989
        $reader = $this->createMock(AuditReaderInterface::class);
2990
2991
        $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...
2992
            ->method('getReader')
2993
            ->with($this->equalTo('Foo'))
2994
            ->will($this->returnValue($reader));
2995
2996
        $reader->expects($this->once())
2997
            ->method('find')
2998
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
2999
            ->will($this->returnValue(null));
3000
3001
        $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...
3002
    }
3003
3004
    public function testHistoryViewRevisionAction(): void
3005
    {
3006
        $this->request->query->set('id', 123);
3007
3008
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3009
            ->method('checkAccess')
3010
            ->with($this->equalTo('historyViewRevision'))
3011
            ->will($this->returnValue(true));
3012
3013
        $object = new \stdClass();
3014
3015
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3016
            ->method('getObject')
3017
            ->will($this->returnValue($object));
3018
3019
        $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...
3020
            ->method('getClass')
3021
            ->will($this->returnValue('Foo'));
3022
3023
        $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...
3024
            ->method('hasReader')
3025
            ->with($this->equalTo('Foo'))
3026
            ->will($this->returnValue(true));
3027
3028
        $reader = $this->createMock(AuditReaderInterface::class);
3029
3030
        $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...
3031
            ->method('getReader')
3032
            ->with($this->equalTo('Foo'))
3033
            ->will($this->returnValue($reader));
3034
3035
        $objectRevision = new \stdClass();
3036
        $objectRevision->revision = 456;
3037
3038
        $reader->expects($this->once())
3039
            ->method('find')
3040
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3041
            ->will($this->returnValue($objectRevision));
3042
3043
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
3050
            ->method('getShow')
3051
            ->will($this->returnValue($fieldDescriptionCollection));
3052
3053
        $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...
3054
3055
        $this->assertSame($this->admin, $this->parameters['admin']);
3056
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
3057
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3058
3059
        $this->assertSame('show', $this->parameters['action']);
3060
        $this->assertSame($objectRevision, $this->parameters['object']);
3061
        $this->assertSame($fieldDescriptionCollection, $this->parameters['elements']);
3062
3063
        $this->assertSame([], $this->session->getFlashBag()->all());
3064
        $this->assertSame('@SonataAdmin/CRUD/show.html.twig', $this->template);
3065
    }
3066
3067
    public function testHistoryCompareRevisionsActionAccessDenied(): void
3068
    {
3069
        $this->expectException(AccessDeniedException::class);
3070
3071
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3072
            ->method('checkAccess')
3073
            ->with($this->equalTo('historyCompareRevisions'))
3074
            ->will($this->throwException(new AccessDeniedException()));
3075
3076
        $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...
3077
    }
3078
3079
    public function testHistoryCompareRevisionsActionNotFoundException(): void
3080
    {
3081
        $this->expectException(NotFoundHttpException::class, 'unable to find the object with id: 123');
3082
3083
        $this->request->query->set('id', 123);
3084
3085
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3086
            ->method('checkAccess')
3087
            ->with($this->equalTo('historyCompareRevisions'))
3088
            ->will($this->returnValue(true));
3089
3090
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3091
            ->method('getObject')
3092
            ->will($this->returnValue(false));
3093
3094
        $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...
3095
    }
3096
3097
    public function testHistoryCompareRevisionsActionNoReader(): void
3098
    {
3099
        $this->expectException(NotFoundHttpException::class, 'unable to find the audit reader for class : Foo');
3100
3101
        $this->request->query->set('id', 123);
3102
3103
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3104
            ->method('checkAccess')
3105
            ->with($this->equalTo('historyCompareRevisions'))
3106
            ->will($this->returnValue(true));
3107
3108
        $object = new \stdClass();
3109
3110
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3111
            ->method('getObject')
3112
            ->will($this->returnValue($object));
3113
3114
        $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...
3115
            ->method('getClass')
3116
            ->will($this->returnValue('Foo'));
3117
3118
        $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...
3119
            ->method('hasReader')
3120
            ->with($this->equalTo('Foo'))
3121
            ->will($this->returnValue(false));
3122
3123
        $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...
3124
    }
3125
3126
    public function testHistoryCompareRevisionsActionNotFoundBaseRevision(): void
3127
    {
3128
        $this->expectException(NotFoundHttpException::class, 'unable to find the targeted object `123` from the revision `456` with classname : `Foo`');
3129
3130
        $this->request->query->set('id', 123);
3131
3132
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3133
            ->method('checkAccess')
3134
            ->with($this->equalTo('historyCompareRevisions'))
3135
            ->will($this->returnValue(true));
3136
3137
        $object = new \stdClass();
3138
3139
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3140
            ->method('getObject')
3141
            ->will($this->returnValue($object));
3142
3143
        $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...
3144
            ->method('getClass')
3145
            ->will($this->returnValue('Foo'));
3146
3147
        $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...
3148
            ->method('hasReader')
3149
            ->with($this->equalTo('Foo'))
3150
            ->will($this->returnValue(true));
3151
3152
        $reader = $this->createMock(AuditReaderInterface::class);
3153
3154
        $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...
3155
            ->method('getReader')
3156
            ->with($this->equalTo('Foo'))
3157
            ->will($this->returnValue($reader));
3158
3159
        // once because it will not be found and therefore the second call won't be executed
3160
        $reader->expects($this->once())
3161
            ->method('find')
3162
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3163
            ->will($this->returnValue(null));
3164
3165
        $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...
3166
    }
3167
3168
    public function testHistoryCompareRevisionsActionNotFoundCompareRevision(): void
3169
    {
3170
        $this->expectException(NotFoundHttpException::class, 'unable to find the targeted object `123` from the revision `789` with classname : `Foo`');
3171
3172
        $this->request->query->set('id', 123);
3173
3174
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3175
            ->method('checkAccess')
3176
            ->with($this->equalTo('historyCompareRevisions'))
3177
            ->will($this->returnValue(true));
3178
3179
        $object = new \stdClass();
3180
3181
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3182
            ->method('getObject')
3183
            ->will($this->returnValue($object));
3184
3185
        $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...
3186
            ->method('getClass')
3187
            ->will($this->returnValue('Foo'));
3188
3189
        $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...
3190
            ->method('hasReader')
3191
            ->with($this->equalTo('Foo'))
3192
            ->will($this->returnValue(true));
3193
3194
        $reader = $this->createMock(AuditReaderInterface::class);
3195
3196
        $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...
3197
            ->method('getReader')
3198
            ->with($this->equalTo('Foo'))
3199
            ->will($this->returnValue($reader));
3200
3201
        $objectRevision = new \stdClass();
3202
        $objectRevision->revision = 456;
3203
3204
        // first call should return, so the second call will throw an exception
3205
        $reader->expects($this->at(0))
3206
            ->method('find')
3207
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3208
            ->will($this->returnValue($objectRevision));
3209
3210
        $reader->expects($this->at(1))
3211
            ->method('find')
3212
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(789))
3213
            ->will($this->returnValue(null));
3214
3215
        $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...
3216
    }
3217
3218
    public function testHistoryCompareRevisionsActionAction(): void
3219
    {
3220
        $this->request->query->set('id', 123);
3221
3222
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3223
            ->method('checkAccess')
3224
            ->with($this->equalTo('historyCompareRevisions'))
3225
            ->will($this->returnValue(true));
3226
3227
        $object = new \stdClass();
3228
3229
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3230
            ->method('getObject')
3231
            ->will($this->returnValue($object));
3232
3233
        $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...
3234
            ->method('getClass')
3235
            ->will($this->returnValue('Foo'));
3236
3237
        $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...
3238
            ->method('hasReader')
3239
            ->with($this->equalTo('Foo'))
3240
            ->will($this->returnValue(true));
3241
3242
        $reader = $this->createMock(AuditReaderInterface::class);
3243
3244
        $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...
3245
            ->method('getReader')
3246
            ->with($this->equalTo('Foo'))
3247
            ->will($this->returnValue($reader));
3248
3249
        $objectRevision = new \stdClass();
3250
        $objectRevision->revision = 456;
3251
3252
        $compareObjectRevision = new \stdClass();
3253
        $compareObjectRevision->revision = 789;
3254
3255
        $reader->expects($this->at(0))
3256
            ->method('find')
3257
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3258
            ->will($this->returnValue($objectRevision));
3259
3260
        $reader->expects($this->at(1))
3261
            ->method('find')
3262
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(789))
3263
            ->will($this->returnValue($compareObjectRevision));
3264
3265
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3266
            ->method('setSubject')
3267
            ->with($this->equalTo($objectRevision))
3268
            ->will($this->returnValue(null));
3269
3270
        $fieldDescriptionCollection = new FieldDescriptionCollection();
3271
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getShow')
3273
            ->will($this->returnValue($fieldDescriptionCollection));
3274
3275
        $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...
3276
3277
        $this->assertSame($this->admin, $this->parameters['admin']);
3278
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
3279
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3280
3281
        $this->assertSame('show', $this->parameters['action']);
3282
        $this->assertSame($objectRevision, $this->parameters['object']);
3283
        $this->assertSame($compareObjectRevision, $this->parameters['object_compare']);
3284
        $this->assertSame($fieldDescriptionCollection, $this->parameters['elements']);
3285
3286
        $this->assertSame([], $this->session->getFlashBag()->all());
3287
        $this->assertSame('@SonataAdmin/CRUD/show_compare.html.twig', $this->template);
3288
    }
3289
3290
    public function testBatchActionWrongMethod(): void
3291
    {
3292
        $this->expectException(NotFoundHttpException::class, 'Invalid request type "GET", POST expected');
3293
3294
        $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...
3295
    }
3296
3297
    public function testBatchActionActionNotDefined(): void
3298
    {
3299
        $this->expectException(\RuntimeException::class, 'The `foo` batch action is not defined');
3300
3301
        $batchActions = [];
3302
3303
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getBatchActions')
3305
            ->will($this->returnValue($batchActions));
3306
3307
        $this->request->setMethod('POST');
3308
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3309
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3310
3311
        $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...
3312
    }
3313
3314
    public function testBatchActionActionInvalidCsrfToken(): void
3315
    {
3316
        $this->request->setMethod('POST');
3317
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3318
        $this->request->request->set('_sonata_csrf_token', 'CSRF-INVALID');
3319
3320
        try {
3321
            $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...
3322
        } catch (HttpException $e) {
3323
            $this->assertSame('The csrf token is not valid, CSRF attack?', $e->getMessage());
3324
            $this->assertSame(400, $e->getStatusCode());
3325
        }
3326
    }
3327
3328
    public function testBatchActionMethodNotExist(): void
3329
    {
3330
        $this->expectException(\RuntimeException::class, 'A `Sonata\AdminBundle\Controller\CRUDController::batchActionFoo` method must be callable');
3331
3332
        $batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3333
3334
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
3340
            ->method('getDatagrid')
3341
            ->will($this->returnValue($datagrid));
3342
3343
        $this->request->setMethod('POST');
3344
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3345
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3346
3347
        $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...
3348
    }
3349
3350
    public function testBatchActionWithoutConfirmation(): void
3351
    {
3352
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3353
3354
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3355
            ->method('getBatchActions')
3356
            ->will($this->returnValue($batchActions));
3357
3358
        $datagrid = $this->createMock(DatagridInterface::class);
3359
3360
        $query = $this->createMock(ProxyQueryInterface::class);
3361
        $datagrid->expects($this->once())
3362
            ->method('getQuery')
3363
            ->will($this->returnValue($query));
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('getDatagrid')
3367
            ->will($this->returnValue($datagrid));
3368
3369
        $modelManager = $this->createMock(ModelManagerInterface::class);
3370
3371
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3372
            ->method('checkAccess')
3373
            ->with($this->equalTo('batchDelete'))
3374
            ->will($this->returnValue(true));
3375
3376
        $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...
3377
            ->method('getModelManager')
3378
            ->will($this->returnValue($modelManager));
3379
3380
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3381
            ->method('getClass')
3382
            ->will($this->returnValue('Foo'));
3383
3384
        $modelManager->expects($this->once())
3385
            ->method('addIdentifiersToQuery')
3386
            ->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456']))
3387
            ->will($this->returnValue(true));
3388
3389
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
3390
3391
        $this->request->setMethod('POST');
3392
        $this->request->request->set('data', json_encode(['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false]));
3393
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3394
3395
        $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...
3396
3397
        $this->assertInstanceOf(RedirectResponse::class, $result);
3398
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3399
        $this->assertSame('list', $result->getTargetUrl());
3400
    }
3401
3402
    public function testBatchActionWithoutConfirmation2(): void
3403
    {
3404
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3405
3406
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3407
            ->method('getBatchActions')
3408
            ->will($this->returnValue($batchActions));
3409
3410
        $datagrid = $this->createMock(DatagridInterface::class);
3411
3412
        $query = $this->createMock(ProxyQueryInterface::class);
3413
        $datagrid->expects($this->once())
3414
            ->method('getQuery')
3415
            ->will($this->returnValue($query));
3416
3417
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3418
            ->method('getDatagrid')
3419
            ->will($this->returnValue($datagrid));
3420
3421
        $modelManager = $this->createMock(ModelManagerInterface::class);
3422
3423
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('checkAccess')
3425
            ->with($this->equalTo('batchDelete'))
3426
            ->will($this->returnValue(true));
3427
3428
        $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...
3429
            ->method('getModelManager')
3430
            ->will($this->returnValue($modelManager));
3431
3432
        $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...
3433
            ->method('getClass')
3434
            ->will($this->returnValue('Foo'));
3435
3436
        $modelManager->expects($this->once())
3437
            ->method('addIdentifiersToQuery')
3438
            ->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456']))
3439
            ->will($this->returnValue(true));
3440
3441
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
3442
3443
        $this->request->setMethod('POST');
3444
        $this->request->request->set('action', 'delete');
3445
        $this->request->request->set('idx', ['123', '456']);
3446
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3447
3448
        $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...
3449
3450
        $this->assertInstanceOf(RedirectResponse::class, $result);
3451
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3452
        $this->assertSame('list', $result->getTargetUrl());
3453
    }
3454
3455
    public function testBatchActionWithConfirmation(): void
3456
    {
3457
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'translation_domain' => 'FooBarBaz', 'ask_confirmation' => true]];
3458
3459
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3460
            ->method('getBatchActions')
3461
            ->will($this->returnValue($batchActions));
3462
3463
        $data = ['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false];
3464
3465
        $this->request->setMethod('POST');
3466
        $this->request->request->set('data', json_encode($data));
3467
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3468
3469
        $datagrid = $this->createMock(DatagridInterface::class);
3470
3471
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3472
            ->method('getDatagrid')
3473
            ->will($this->returnValue($datagrid));
3474
3475
        $form = $this->getMockBuilder(Form::class)
3476
            ->disableOriginalConstructor()
3477
            ->getMock();
3478
3479
        $form->expects($this->once())
3480
            ->method('createView')
3481
            ->will($this->returnValue($this->createMock(FormView::class)));
3482
3483
        $datagrid->expects($this->once())
3484
            ->method('getForm')
3485
            ->will($this->returnValue($form));
3486
3487
        $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...
3488
3489
        $this->assertSame($this->admin, $this->parameters['admin']);
3490
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
3491
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3492
3493
        $this->assertSame('list', $this->parameters['action']);
3494
        $this->assertSame($datagrid, $this->parameters['datagrid']);
3495
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
3496
        $this->assertSame($data, $this->parameters['data']);
3497
        $this->assertSame('csrf-token-123_sonata.batch', $this->parameters['csrf_token']);
3498
        $this->assertSame('Foo Bar', $this->parameters['action_label']);
3499
3500
        $this->assertSame([], $this->session->getFlashBag()->all());
3501
        $this->assertSame('@SonataAdmin/CRUD/batch_confirmation.html.twig', $this->template);
3502
    }
3503
3504
    public function testBatchActionNonRelevantAction(): void
3505
    {
3506
        $controller = new BatchAdminController();
3507
        $controller->setContainer($this->container);
3508
3509
        $batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3510
3511
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getDatagrid')
3519
            ->will($this->returnValue($datagrid));
3520
3521
        $this->expectTranslate('flash_batch_empty', [], 'SonataAdminBundle');
3522
3523
        $this->request->setMethod('POST');
3524
        $this->request->request->set('action', 'foo');
3525
        $this->request->request->set('idx', ['789']);
3526
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3527
3528
        $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...
3529
3530
        $this->assertInstanceOf(RedirectResponse::class, $result);
3531
        $this->assertSame(['flash_batch_empty'], $this->session->getFlashBag()->get('sonata_flash_info'));
3532
        $this->assertSame('list', $result->getTargetUrl());
3533
    }
3534
3535
    public function testBatchActionNonRelevantAction2(): void
3536
    {
3537
        $controller = new BatchAdminController();
3538
        $controller->setContainer($this->container);
3539
3540
        $batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3541
3542
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
3549
            ->method('getDatagrid')
3550
            ->will($this->returnValue($datagrid));
3551
3552
        $this->expectTranslate('flash_foo_error', [], 'SonataAdminBundle');
3553
3554
        $this->request->setMethod('POST');
3555
        $this->request->request->set('action', 'foo');
3556
        $this->request->request->set('idx', ['999']);
3557
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3558
3559
        $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...
3560
3561
        $this->assertInstanceOf(RedirectResponse::class, $result);
3562
        $this->assertSame(['flash_foo_error'], $this->session->getFlashBag()->get('sonata_flash_info'));
3563
        $this->assertSame('list', $result->getTargetUrl());
3564
    }
3565
3566
    public function testBatchActionNoItems(): void
3567
    {
3568
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => true]];
3569
3570
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

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

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

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

Loading history...
3577
            ->method('getDatagrid')
3578
            ->will($this->returnValue($datagrid));
3579
3580
        $this->expectTranslate('flash_batch_empty', [], 'SonataAdminBundle');
3581
3582
        $this->request->setMethod('POST');
3583
        $this->request->request->set('action', 'delete');
3584
        $this->request->request->set('idx', []);
3585
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3586
3587
        $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...
3588
3589
        $this->assertInstanceOf(RedirectResponse::class, $result);
3590
        $this->assertSame(['flash_batch_empty'], $this->session->getFlashBag()->get('sonata_flash_info'));
3591
        $this->assertSame('list', $result->getTargetUrl());
3592
    }
3593
3594
    public function testBatchActionNoItemsEmptyQuery(): void
3595
    {
3596
        $controller = new BatchAdminController();
3597
        $controller->setContainer($this->container);
3598
3599
        $batchActions = ['bar' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3600
3601
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3602
            ->method('getBatchActions')
3603
            ->will($this->returnValue($batchActions));
3604
3605
        $datagrid = $this->createMock(DatagridInterface::class);
3606
3607
        $query = $this->createMock(ProxyQueryInterface::class);
3608
        $datagrid->expects($this->once())
3609
            ->method('getQuery')
3610
            ->will($this->returnValue($query));
3611
3612
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3613
            ->method('getDatagrid')
3614
            ->will($this->returnValue($datagrid));
3615
3616
        $modelManager = $this->createMock(ModelManagerInterface::class);
3617
3618
        $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...
3619
            ->method('getModelManager')
3620
            ->will($this->returnValue($modelManager));
3621
3622
        $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...
3623
            ->method('getClass')
3624
            ->will($this->returnValue('Foo'));
3625
3626
        $this->request->setMethod('POST');
3627
        $this->request->request->set('action', 'bar');
3628
        $this->request->request->set('idx', []);
3629
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3630
3631
        $this->expectTranslate('flash_batch_no_elements_processed', [], 'SonataAdminBundle');
3632
        $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...
3633
3634
        $this->assertInstanceOf(Response::class, $result);
3635
        $this->assertRegExp('/Redirecting to list/', $result->getContent());
3636
    }
3637
3638
    public function testBatchActionWithRequesData(): void
3639
    {
3640
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3641
3642
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3643
            ->method('getBatchActions')
3644
            ->will($this->returnValue($batchActions));
3645
3646
        $datagrid = $this->createMock(DatagridInterface::class);
3647
3648
        $query = $this->createMock(ProxyQueryInterface::class);
3649
        $datagrid->expects($this->once())
3650
            ->method('getQuery')
3651
            ->will($this->returnValue($query));
3652
3653
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3654
            ->method('getDatagrid')
3655
            ->will($this->returnValue($datagrid));
3656
3657
        $modelManager = $this->createMock(ModelManagerInterface::class);
3658
3659
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AdminInterface>.

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

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

Loading history...
3660
            ->method('checkAccess')
3661
            ->with($this->equalTo('batchDelete'))
3662
            ->will($this->returnValue(true));
3663
3664
        $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...
3665
            ->method('getModelManager')
3666
            ->will($this->returnValue($modelManager));
3667
3668
        $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...
3669
            ->method('getClass')
3670
            ->will($this->returnValue('Foo'));
3671
3672
        $modelManager->expects($this->once())
3673
            ->method('addIdentifiersToQuery')
3674
            ->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456']))
3675
            ->will($this->returnValue(true));
3676
3677
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
3678
3679
        $this->request->setMethod('POST');
3680
        $this->request->request->set('data', json_encode(['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false]));
3681
        $this->request->request->set('foo', 'bar');
3682
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3683
3684
        $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...
3685
3686
        $this->assertInstanceOf(RedirectResponse::class, $result);
3687
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3688
        $this->assertSame('list', $result->getTargetUrl());
3689
        $this->assertSame('bar', $this->request->request->get('foo'));
3690
    }
3691
3692
    public function testItThrowsWhenCallingAnUndefinedMethod(): void
3693
    {
3694
        $this->expectException(
3695
            \LogicException::class
3696
        );
3697
        $this->expectExceptionMessage(
3698
            'Call to undefined method Sonata\AdminBundle\Controller\CRUDController::doesNotExist'
3699
        );
3700
        $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...
3701
    }
3702
3703
    /**
3704
     * @expectedDeprecation Method Sonata\AdminBundle\Controller\CRUDController::render has been renamed to Sonata\AdminBundle\Controller\CRUDController::renderWithExtraParams.
3705
     */
3706
    public function testRenderIsDeprecated(): void
3707
    {
3708
        $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...
3709
    }
3710
3711
    public function getCsrfProvider()
3712
    {
3713
        return $this->csrfProvider;
3714
    }
3715
3716
    public function getToStringValues()
3717
    {
3718
        return [
3719
            ['', ''],
3720
            ['Foo', 'Foo'],
3721
            ['&lt;a href=&quot;http://foo&quot;&gt;Bar&lt;/a&gt;', '<a href="http://foo">Bar</a>'],
3722
            ['&lt;&gt;&amp;&quot;&#039;abcdefghijklmnopqrstuvwxyz*-+.,?_()[]\/', '<>&"\'abcdefghijklmnopqrstuvwxyz*-+.,?_()[]\/'],
3723
        ];
3724
    }
3725
3726
    private function assertLoggerLogsModelManagerException($subject, $method): void
3727
    {
3728
        $exception = new ModelManagerException(
3729
            $message = 'message',
3730
            1234,
3731
            new \Exception($previousExceptionMessage = 'very useful message')
3732
        );
3733
3734
        $subject->expects($this->once())
3735
            ->method($method)
3736
            ->will($this->returnCallback(function () use ($exception): void {
3737
                throw $exception;
3738
            }));
3739
3740
        $this->logger->expects($this->once())
3741
            ->method('error')
3742
            ->with($message, [
3743
                'exception' => $exception,
3744
                'previous_exception_message' => $previousExceptionMessage,
3745
            ]);
3746
    }
3747
3748
    private function expectTranslate($id, array $parameters = [], $domain = null, $locale = null): void
3749
    {
3750
        $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...
3751
            ->method('trans')
3752
            ->with($this->equalTo($id), $this->equalTo($parameters), $this->equalTo($domain), $this->equalTo($locale))
3753
            ->will($this->returnValue($id));
3754
    }
3755
}
3756