Completed
Push — 3.x ( 097117...746d06 )
by Grégoire
04:29
created

testCreateActionRuntimeException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
655
            ->method('checkAccess')
656
            ->with($this->equalTo('list'))
657
            ->will($this->throwException(new AccessDeniedException()));
658
659
        $this->controller->listAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::listAction() has too many arguments starting with $this->request.

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

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

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

Loading history...
660
    }
661
662
    public function testPreList()
663
    {
664
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
670
            ->method('checkAccess')
671
            ->with($this->equalTo('list'))
672
            ->will($this->returnValue(true));
673
674
        $controller = new PreCRUDController();
675
        $controller->setContainer($this->container);
676
677
        $response = $controller->listAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to PreCRUDController::listAction() has too many arguments starting with $this->request.

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

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

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

Loading history...
678
        $this->assertInstanceOf(Response::class, $response);
679
        $this->assertSame('preList called', $response->getContent());
680
    }
681
682
    public function testListAction()
683
    {
684
        $datagrid = $this->createMock(DatagridInterface::class);
685
686
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

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

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

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

Loading history...
705
            ->method('getDatagrid')
706
            ->will($this->returnValue($datagrid));
707
708
        $datagrid->expects($this->once())
709
            ->method('getForm')
710
            ->will($this->returnValue($form));
711
712
        $this->parameters = [];
713
        $this->assertInstanceOf(Response::class, $this->controller->listAction($this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::listAction() has too many arguments starting with $this->request.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
799
            ->method('getModelManager')
800
            ->will($this->returnValue($modelManager));
801
802
        $this->kernel->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...Kernel\KernelInterface>.

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

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

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

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

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

Loading history...
814
            ->method('getObject')
815
            ->will($this->returnValue(false));
816
817
        $this->controller->showAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::showAction() has too many arguments starting with $this->request.

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

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

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

Loading history...
818
    }
819
820
    public function testShowActionAccessDenied()
821
    {
822
        $this->expectException(AccessDeniedException::class);
823
824
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
829
            ->method('checkAccess')
830
            ->with($this->equalTo('show'))
831
            ->will($this->throwException(new AccessDeniedException()));
832
833
        $this->controller->showAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::showAction() has too many arguments starting with $this->request.

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

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

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

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

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

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

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

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

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

Loading history...
849
            ->method('checkAccess')
850
            ->with($this->equalTo('show'))
851
            ->will($this->returnValue(true));
852
853
        $show = $this->createMock(FieldDescriptionCollection::class);
854
855
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
856
            ->method('getShow')
857
            ->will($this->returnValue($show));
858
859
        $show->expects($this->once())
860
            ->method('getElements')
861
            ->willReturn([]);
862
863
        $show->expects($this->once())
864
            ->method('count')
865
            ->willReturn(0);
866
867
        $this->controller->showAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::showAction() has too many arguments starting with $this->request.

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

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

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

Loading history...
868
    }
869
870
    public function testPreShow()
871
    {
872
        $object = new \stdClass();
873
        $object->foo = 123456;
874
875
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
876
            ->method('getObject')
877
            ->will($this->returnValue($object));
878
879
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
880
            ->method('checkAccess')
881
            ->with($this->equalTo('show'))
882
            ->will($this->returnValue(true));
883
884
        $controller = new PreCRUDController();
885
        $controller->setContainer($this->container);
886
887
        $response = $controller->showAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to PreCRUDController::showAction() has too many arguments starting with $this->request.

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

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

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

Loading history...
888
        $this->assertInstanceOf(Response::class, $response);
889
        $this->assertSame('preShow called: 123456', $response->getContent());
890
    }
891
892
    public function testShowAction()
893
    {
894
        $object = new \stdClass();
895
896
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
897
            ->method('getObject')
898
            ->will($this->returnValue($object));
899
900
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
901
            ->method('checkAccess')
902
            ->with($this->equalTo('show'))
903
            ->will($this->returnValue(true));
904
905
        $show = $this->createMock(FieldDescriptionCollection::class);
906
907
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
908
            ->method('getShow')
909
            ->will($this->returnValue($show));
910
911
        $show->expects($this->once())
912
            ->method('getElements')
913
            ->willReturn(['field' => 'fielddata']);
914
915
        $this->assertInstanceOf(Response::class, $this->controller->showAction(null, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::showAction() has too many arguments starting with $this->request.

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

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

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

Loading history...
916
917
        $this->assertSame($this->admin, $this->parameters['admin']);
918
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
919
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
920
921
        $this->assertSame('show', $this->parameters['action']);
922
        $this->assertInstanceOf(FieldDescriptionCollection::class, $this->parameters['elements']);
923
        $this->assertSame($object, $this->parameters['object']);
924
925
        $this->assertSame([], $this->session->getFlashBag()->all());
926
        $this->assertSame('@SonataAdmin/CRUD/show.html.twig', $this->template);
927
    }
928
929
    /**
930
     * @dataProvider getRedirectToTests
931
     */
932
    public function testRedirectTo($expected, $route, $queryParams, $hasActiveSubclass)
933
    {
934
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
935
            ->method('hasActiveSubclass')
936
            ->will($this->returnValue($hasActiveSubclass));
937
938
        $object = new \stdClass();
939
940
        foreach ($queryParams as $key => $value) {
941
            $this->request->query->set($key, $value);
942
        }
943
944
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
945
            ->method('hasRoute')
946
            ->with($this->equalTo($route))
947
            ->will($this->returnValue(true));
948
949
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
950
            ->method('hasAccess')
951
            ->with($this->equalTo($route))
952
            ->will($this->returnValue(true));
953
954
        $response = $this->protectedTestedMethods['redirectTo']->invoke($this->controller, $object, $this->request);
955
        $this->assertInstanceOf(RedirectResponse::class, $response);
956
        $this->assertSame($expected, $response->getTargetUrl());
957
    }
958
959
    public function testRedirectToWithObject()
960
    {
961
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
962
            ->method('hasActiveSubclass')
963
            ->will($this->returnValue(false));
964
965
        $object = new \stdClass();
966
967
        $this->admin->expects($this->at(0))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
968
            ->method('hasRoute')
969
            ->with($this->equalTo('edit'))
970
            ->will($this->returnValue(true));
971
972
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
998
            ->method('getObject')
999
            ->will($this->returnValue(false));
1000
1001
        $this->controller->deleteAction(1, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::deleteAction() has too many arguments starting with $this->request.

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

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

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

Loading history...
1002
    }
1003
1004
    public function testDeleteActionAccessDenied()
1005
    {
1006
        $this->expectException(AccessDeniedException::class);
1007
1008
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1013
            ->method('checkAccess')
1014
            ->with($this->equalTo('delete'))
1015
            ->will($this->throwException(new AccessDeniedException()));
1016
1017
        $this->controller->deleteAction(1, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::deleteAction() has too many arguments starting with $this->request.

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

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

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

Loading history...
1018
    }
1019
1020
    public function testPreDelete()
1021
    {
1022
        $object = new \stdClass();
1023
        $object->foo = 123456;
1024
1025
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1030
            ->method('checkAccess')
1031
            ->with($this->equalTo('delete'))
1032
            ->will($this->returnValue(true));
1033
1034
        $controller = new PreCRUDController();
1035
        $controller->setContainer($this->container);
1036
1037
        $response = $controller->deleteAction(null, $this->request);
0 ignored issues
show
Unused Code introduced by
The call to PreCRUDController::deleteAction() has too many arguments starting with $this->request.

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

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

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

Loading history...
1038
        $this->assertInstanceOf(Response::class, $response);
1039
        $this->assertSame('preDelete called: 123456', $response->getContent());
1040
    }
1041
1042
    public function testDeleteAction()
1043
    {
1044
        $object = new \stdClass();
1045
1046
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1051
            ->method('checkAccess')
1052
            ->with($this->equalTo('delete'))
1053
            ->will($this->returnValue(true));
1054
1055
        $this->assertInstanceOf(Response::class, $this->controller->deleteAction(1, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::deleteAction() has too many arguments starting with $this->request.

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

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

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

Loading history...
1056
1057
        $this->assertSame($this->admin, $this->parameters['admin']);
1058
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1059
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1060
1061
        $this->assertSame('delete', $this->parameters['action']);
1062
        $this->assertSame($object, $this->parameters['object']);
1063
        $this->assertSame('csrf-token-123_sonata.delete', $this->parameters['csrf_token']);
1064
1065
        $this->assertSame([], $this->session->getFlashBag()->all());
1066
        $this->assertSame('@SonataAdmin/CRUD/delete.html.twig', $this->template);
1067
    }
1068
1069
    /**
1070
     * @group legacy
1071
     * @expectedDeprecation Accessing a child that isn't connected to a given parent is deprecated since 3.34 and won't be allowed in 4.0.
1072
     */
1073
    public function testDeleteActionChildDeprecation()
1074
    {
1075
        $object = new \stdClass();
1076
        $object->parent = 'test';
1077
1078
        $object2 = new \stdClass();
1079
1080
        $admin = $this->createMock(PostAdmin::class);
1081
1082
        $admin->expects($this->once())
1083
            ->method('getObject')
1084
            ->will($this->returnValue($object2));
1085
1086
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1087
            ->method('getObject')
1088
            ->will($this->returnValue($object));
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\AbstractAdmin>.

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

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

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

Loading history...
1095
            ->method('getParentAssociationMapping')
1096
            ->will($this->returnValue('parent'));
1097
1098
        $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...
1099
    }
1100
1101
    public function testDeleteActionNoParentMappings()
1102
    {
1103
        $object = new \stdClass();
1104
1105
        $admin = $this->createMock(PostAdmin::class);
1106
1107
        $admin->expects($this->never())
1108
            ->method('getObject');
1109
1110
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1111
            ->method('getObject')
1112
            ->will($this->returnValue($object));
1113
1114
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1119
            ->method('getParentAssociationMapping')
1120
            ->will($this->returnValue(false));
1121
1122
        $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...
1123
    }
1124
1125
    public function testDeleteActionNoCsrfToken()
1126
    {
1127
        $this->csrfProvider = null;
1128
1129
        $object = new \stdClass();
1130
1131
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1132
            ->method('getObject')
1133
            ->will($this->returnValue($object));
1134
1135
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1136
            ->method('checkAccess')
1137
            ->with($this->equalTo('delete'))
1138
            ->will($this->returnValue(true));
1139
1140
        $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...
1141
1142
        $this->assertSame($this->admin, $this->parameters['admin']);
1143
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1144
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1145
1146
        $this->assertSame('delete', $this->parameters['action']);
1147
        $this->assertSame($object, $this->parameters['object']);
1148
        $this->assertFalse($this->parameters['csrf_token']);
1149
1150
        $this->assertSame([], $this->session->getFlashBag()->all());
1151
        $this->assertSame('@SonataAdmin/CRUD/delete.html.twig', $this->template);
1152
    }
1153
1154
    public function testDeleteActionAjaxSuccess1()
1155
    {
1156
        $object = new \stdClass();
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\AbstractAdmin>.

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
1199
1200
        $this->assertInstanceOf(Response::class, $response);
1201
        $this->assertSame(json_encode(['result' => 'ok']), $response->getContent());
1202
        $this->assertSame([], $this->session->getFlashBag()->all());
1203
    }
1204
1205
    public function testDeleteActionAjaxError()
1206
    {
1207
        $object = new \stdClass();
1208
1209
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1210
            ->method('getObject')
1211
            ->will($this->returnValue($object));
1212
1213
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1214
            ->method('checkAccess')
1215
            ->with($this->equalTo('delete'))
1216
            ->will($this->returnValue(true));
1217
1218
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

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

Loading history...
1230
1231
        $this->assertInstanceOf(Response::class, $response);
1232
        $this->assertSame(json_encode(['result' => 'error']), $response->getContent());
1233
        $this->assertSame([], $this->session->getFlashBag()->all());
1234
    }
1235
1236
    public function testDeleteActionWithModelManagerExceptionInDebugMode()
1237
    {
1238
        $this->expectException(ModelManagerException::class);
1239
1240
        $object = new \stdClass();
1241
1242
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1243
            ->method('getObject')
1244
            ->will($this->returnValue($object));
1245
1246
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1247
            ->method('checkAccess')
1248
            ->with($this->equalTo('delete'))
1249
            ->will($this->returnValue(true));
1250
1251
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1252
            ->method('delete')
1253
            ->will($this->returnCallback(function () {
1254
                throw new ModelManagerException();
1255
            }));
1256
1257
        $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...
1258
            ->method('isDebug')
1259
            ->will($this->returnValue(true));
1260
1261
        $this->request->setMethod('DELETE');
1262
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1263
1264
        $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...
1265
    }
1266
1267
    /**
1268
     * @dataProvider getToStringValues
1269
     */
1270
    public function testDeleteActionSuccess1($expectedToStringValue, $toStringValue)
1271
    {
1272
        $object = new \stdClass();
1273
1274
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1275
            ->method('getObject')
1276
            ->will($this->returnValue($object));
1277
1278
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1279
            ->method('toString')
1280
            ->with($this->equalTo($object))
1281
            ->will($this->returnValue($toStringValue));
1282
1283
        $this->expectTranslate('flash_delete_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1284
1285
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1286
            ->method('checkAccess')
1287
            ->with($this->equalTo('delete'))
1288
            ->will($this->returnValue(true));
1289
1290
        $this->request->setMethod('DELETE');
1291
1292
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1293
1294
        $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...
1295
1296
        $this->assertInstanceOf(RedirectResponse::class, $response);
1297
        $this->assertSame(['flash_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1298
        $this->assertSame('list', $response->getTargetUrl());
1299
    }
1300
1301
    /**
1302
     * @dataProvider getToStringValues
1303
     */
1304
    public function testDeleteActionSuccess2($expectedToStringValue, $toStringValue)
1305
    {
1306
        $object = new \stdClass();
1307
1308
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1309
            ->method('getObject')
1310
            ->will($this->returnValue($object));
1311
1312
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1313
            ->method('checkAccess')
1314
            ->with($this->equalTo('delete'))
1315
            ->will($this->returnValue(true));
1316
1317
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1318
            ->method('toString')
1319
            ->with($this->equalTo($object))
1320
            ->will($this->returnValue($toStringValue));
1321
1322
        $this->expectTranslate('flash_delete_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1323
1324
        $this->request->setMethod('POST');
1325
        $this->request->request->set('_method', 'DELETE');
1326
1327
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1328
1329
        $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...
1330
1331
        $this->assertInstanceOf(RedirectResponse::class, $response);
1332
        $this->assertSame(['flash_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1333
        $this->assertSame('list', $response->getTargetUrl());
1334
    }
1335
1336
    /**
1337
     * @dataProvider getToStringValues
1338
     */
1339
    public function testDeleteActionSuccessNoCsrfTokenProvider($expectedToStringValue, $toStringValue)
1340
    {
1341
        $this->csrfProvider = null;
1342
1343
        $object = new \stdClass();
1344
1345
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1346
            ->method('getObject')
1347
            ->will($this->returnValue($object));
1348
1349
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1350
            ->method('checkAccess')
1351
            ->with($this->equalTo('delete'))
1352
            ->will($this->returnValue(true));
1353
1354
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1355
            ->method('toString')
1356
            ->with($this->equalTo($object))
1357
            ->will($this->returnValue($toStringValue));
1358
1359
        $this->expectTranslate('flash_delete_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1360
1361
        $this->request->setMethod('POST');
1362
        $this->request->request->set('_method', 'DELETE');
1363
1364
        $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...
1365
1366
        $this->assertInstanceOf(RedirectResponse::class, $response);
1367
        $this->assertSame(['flash_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1368
        $this->assertSame('list', $response->getTargetUrl());
1369
    }
1370
1371
    public function testDeleteActionWrongRequestMethod()
1372
    {
1373
        $object = new \stdClass();
1374
1375
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1376
            ->method('getObject')
1377
            ->will($this->returnValue($object));
1378
1379
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1380
            ->method('checkAccess')
1381
            ->with($this->equalTo('delete'))
1382
            ->will($this->returnValue(true));
1383
1384
        //without POST request parameter "_method" should not be used as real REST method
1385
        $this->request->query->set('_method', 'DELETE');
1386
1387
        $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...
1388
1389
        $this->assertSame($this->admin, $this->parameters['admin']);
1390
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1391
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1392
1393
        $this->assertSame('delete', $this->parameters['action']);
1394
        $this->assertSame($object, $this->parameters['object']);
1395
        $this->assertSame('csrf-token-123_sonata.delete', $this->parameters['csrf_token']);
1396
1397
        $this->assertSame([], $this->session->getFlashBag()->all());
1398
        $this->assertSame('@SonataAdmin/CRUD/delete.html.twig', $this->template);
1399
    }
1400
1401
    /**
1402
     * @dataProvider getToStringValues
1403
     */
1404
    public function testDeleteActionError($expectedToStringValue, $toStringValue)
1405
    {
1406
        $object = new \stdClass();
1407
1408
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1413
            ->method('checkAccess')
1414
            ->with($this->equalTo('delete'))
1415
            ->will($this->returnValue(true));
1416
1417
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1418
            ->method('toString')
1419
            ->with($this->equalTo($object))
1420
            ->will($this->returnValue($toStringValue));
1421
1422
        $this->expectTranslate('flash_delete_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1423
1424
        $this->assertLoggerLogsModelManagerException($this->admin, 'delete');
1425
1426
        $this->request->setMethod('DELETE');
1427
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
1428
1429
        $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...
1430
1431
        $this->assertInstanceOf(RedirectResponse::class, $response);
1432
        $this->assertSame(['flash_delete_error'], $this->session->getFlashBag()->get('sonata_flash_error'));
1433
        $this->assertSame('list', $response->getTargetUrl());
1434
    }
1435
1436
    public function testDeleteActionInvalidCsrfToken()
1437
    {
1438
        $object = new \stdClass();
1439
1440
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1441
            ->method('getObject')
1442
            ->will($this->returnValue($object));
1443
1444
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1445
            ->method('checkAccess')
1446
            ->with($this->equalTo('delete'))
1447
            ->will($this->returnValue(true));
1448
1449
        $this->request->setMethod('POST');
1450
        $this->request->request->set('_method', 'DELETE');
1451
        $this->request->request->set('_sonata_csrf_token', 'CSRF-INVALID');
1452
1453
        try {
1454
            $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...
1455
        } catch (HttpException $e) {
1456
            $this->assertSame('The csrf token is not valid, CSRF attack?', $e->getMessage());
1457
            $this->assertSame(400, $e->getStatusCode());
1458
        }
1459
    }
1460
1461
    public function testEditActionNotFoundException()
1462
    {
1463
        $this->expectException(NotFoundHttpException::class);
1464
1465
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1466
            ->method('getObject')
1467
            ->will($this->returnValue(false));
1468
1469
        $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...
1470
    }
1471
1472
    public function testEditActionRuntimeException()
1473
    {
1474
        $this->expectException(\RuntimeException::class);
1475
1476
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1481
            ->method('checkAccess')
1482
            ->with($this->equalTo('edit'))
1483
            ->will($this->returnValue(true));
1484
1485
        $form = $this->createMock(Form::class);
1486
1487
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1488
            ->method('getForm')
1489
            ->will($this->returnValue($form));
1490
1491
        $form->expects($this->once())
1492
            ->method('all')
1493
            ->willReturn([]);
1494
1495
        $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...
1496
    }
1497
1498
    public function testEditActionAccessDenied()
1499
    {
1500
        $this->expectException(AccessDeniedException::class);
1501
1502
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1507
            ->method('checkAccess')
1508
            ->with($this->equalTo('edit'))
1509
            ->will($this->throwException(new AccessDeniedException()));
1510
1511
        $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...
1512
    }
1513
1514
    public function testPreEdit()
1515
    {
1516
        $object = new \stdClass();
1517
        $object->foo = 123456;
1518
1519
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1520
            ->method('getObject')
1521
            ->will($this->returnValue($object));
1522
1523
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1524
            ->method('checkAccess')
1525
            ->with($this->equalTo('edit'))
1526
            ->will($this->returnValue(true));
1527
1528
        $controller = new PreCRUDController();
1529
        $controller->setContainer($this->container);
1530
1531
        $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...
1532
        $this->assertInstanceOf(Response::class, $response);
1533
        $this->assertSame('preEdit called: 123456', $response->getContent());
1534
    }
1535
1536
    public function testEditAction()
1537
    {
1538
        $object = new \stdClass();
1539
1540
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1541
            ->method('getObject')
1542
            ->will($this->returnValue($object));
1543
1544
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1552
            ->method('getForm')
1553
            ->will($this->returnValue($form));
1554
1555
        $formView = $this->createMock(FormView::class);
1556
1557
        $form->expects($this->any())
1558
            ->method('createView')
1559
            ->will($this->returnValue($formView));
1560
1561
        $form->expects($this->once())
1562
            ->method('all')
1563
            ->willReturn(['field' => 'fielddata']);
1564
1565
        $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...
1566
1567
        $this->assertSame($this->admin, $this->parameters['admin']);
1568
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1569
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1570
1571
        $this->assertSame('edit', $this->parameters['action']);
1572
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1573
        $this->assertSame($object, $this->parameters['object']);
1574
        $this->assertSame([], $this->session->getFlashBag()->all());
1575
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1576
    }
1577
1578
    /**
1579
     * @dataProvider getToStringValues
1580
     */
1581
    public function testEditActionSuccess($expectedToStringValue, $toStringValue)
1582
    {
1583
        $object = new \stdClass();
1584
1585
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1586
            ->method('getObject')
1587
            ->will($this->returnValue($object));
1588
1589
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1590
            ->method('update')
1591
            ->will($this->returnArgument(0));
1592
1593
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1594
            ->method('checkAccess')
1595
            ->with($this->equalTo('edit'));
1596
1597
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1598
            ->method('hasRoute')
1599
            ->with($this->equalTo('edit'))
1600
            ->will($this->returnValue(true));
1601
1602
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1614
            ->method('getForm')
1615
            ->will($this->returnValue($form));
1616
1617
        $form->expects($this->once())
1618
            ->method('isSubmitted')
1619
            ->will($this->returnValue(true));
1620
1621
        $form->expects($this->once())
1622
            ->method('isValid')
1623
            ->will($this->returnValue(true));
1624
1625
        $form->expects($this->once())
1626
            ->method('all')
1627
            ->willReturn(['field' => 'fielddata']);
1628
1629
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1630
            ->method('toString')
1631
            ->with($this->equalTo($object))
1632
            ->will($this->returnValue($toStringValue));
1633
1634
        $this->expectTranslate('flash_edit_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1635
1636
        $this->request->setMethod('POST');
1637
1638
        $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...
1639
1640
        $this->assertInstanceOf(RedirectResponse::class, $response);
1641
        $this->assertSame(['flash_edit_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1642
        $this->assertSame('stdClass_edit', $response->getTargetUrl());
1643
    }
1644
1645
    /**
1646
     * @dataProvider getToStringValues
1647
     */
1648
    public function testEditActionError($expectedToStringValue, $toStringValue)
1649
    {
1650
        $object = new \stdClass();
1651
1652
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1653
            ->method('getObject')
1654
            ->will($this->returnValue($object));
1655
1656
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1657
            ->method('checkAccess')
1658
            ->with($this->equalTo('edit'))
1659
            ->will($this->returnValue(true));
1660
1661
        $form = $this->createMock(Form::class);
1662
1663
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1664
            ->method('getForm')
1665
            ->will($this->returnValue($form));
1666
1667
        $form->expects($this->once())
1668
            ->method('isSubmitted')
1669
            ->will($this->returnValue(true));
1670
1671
        $form->expects($this->once())
1672
            ->method('isValid')
1673
            ->will($this->returnValue(false));
1674
1675
        $form->expects($this->once())
1676
            ->method('all')
1677
            ->willReturn(['field' => 'fielddata']);
1678
1679
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1680
            ->method('toString')
1681
            ->with($this->equalTo($object))
1682
            ->will($this->returnValue($toStringValue));
1683
1684
        $this->expectTranslate('flash_edit_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1685
1686
        $this->request->setMethod('POST');
1687
1688
        $formView = $this->createMock(FormView::class);
1689
1690
        $form->expects($this->any())
1691
            ->method('createView')
1692
            ->will($this->returnValue($formView));
1693
1694
        $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...
1695
1696
        $this->assertSame($this->admin, $this->parameters['admin']);
1697
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1698
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1699
1700
        $this->assertSame('edit', $this->parameters['action']);
1701
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1702
        $this->assertSame($object, $this->parameters['object']);
1703
1704
        $this->assertSame(['sonata_flash_error' => ['flash_edit_error']], $this->session->getFlashBag()->all());
1705
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1706
    }
1707
1708
    public function testEditActionAjaxSuccess()
1709
    {
1710
        $object = new \stdClass();
1711
1712
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1717
            ->method('update')
1718
            ->will($this->returnArgument(0));
1719
1720
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1721
            ->method('checkAccess')
1722
            ->with($this->equalTo('edit'))
1723
            ->will($this->returnValue(true));
1724
1725
        $form = $this->createMock(Form::class);
1726
1727
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1728
            ->method('getForm')
1729
            ->will($this->returnValue($form));
1730
1731
        $form->expects($this->once())
1732
            ->method('isSubmitted')
1733
            ->will($this->returnValue(true));
1734
1735
        $form->expects($this->once())
1736
            ->method('isValid')
1737
            ->will($this->returnValue(true));
1738
1739
        $form->expects($this->once())
1740
            ->method('getData')
1741
            ->will($this->returnValue($object));
1742
1743
        $form->expects($this->once())
1744
            ->method('all')
1745
            ->willReturn(['field' => 'fielddata']);
1746
1747
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1748
            ->method('getNormalizedIdentifier')
1749
            ->with($this->equalTo($object))
1750
            ->will($this->returnValue('foo_normalized'));
1751
1752
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1753
            ->method('toString')
1754
            ->will($this->returnValue('foo'));
1755
1756
        $this->request->setMethod('POST');
1757
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1758
1759
        $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...
1760
1761
        $this->assertInstanceOf(Response::class, $response);
1762
        $this->assertSame(json_encode(['result' => 'ok', 'objectId' => 'foo_normalized', 'objectName' => 'foo']), $response->getContent());
1763
        $this->assertSame([], $this->session->getFlashBag()->all());
1764
    }
1765
1766
    public function testEditActionAjaxError()
1767
    {
1768
        $object = new \stdClass();
1769
1770
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1775
            ->method('checkAccess')
1776
            ->with($this->equalTo('edit'))
1777
            ->will($this->returnValue(true));
1778
1779
        $form = $this->createMock(Form::class);
1780
1781
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1782
            ->method('getForm')
1783
            ->will($this->returnValue($form));
1784
1785
        $form->expects($this->once())
1786
            ->method('isSubmitted')
1787
            ->will($this->returnValue(true));
1788
1789
        $form->expects($this->once())
1790
            ->method('isValid')
1791
            ->will($this->returnValue(false));
1792
1793
        $form->expects($this->once())
1794
            ->method('all')
1795
            ->willReturn(['field' => 'fielddata']);
1796
1797
        $this->request->setMethod('POST');
1798
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1799
1800
        $formView = $this->createMock(FormView::class);
1801
1802
        $form->expects($this->any())
1803
            ->method('createView')
1804
            ->will($this->returnValue($formView));
1805
1806
        $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...
1807
1808
        $this->assertSame($this->admin, $this->parameters['admin']);
1809
        $this->assertSame('@SonataAdmin/ajax_layout.html.twig', $this->parameters['base_template']);
1810
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1811
1812
        $this->assertSame('edit', $this->parameters['action']);
1813
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1814
        $this->assertSame($object, $this->parameters['object']);
1815
1816
        $this->assertSame([], $this->session->getFlashBag()->all());
1817
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1818
    }
1819
1820
    /**
1821
     * @dataProvider getToStringValues
1822
     */
1823
    public function testEditActionWithModelManagerException($expectedToStringValue, $toStringValue)
1824
    {
1825
        $object = new \stdClass();
1826
1827
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1828
            ->method('getObject')
1829
            ->will($this->returnValue($object));
1830
1831
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1832
            ->method('checkAccess')
1833
            ->with($this->equalTo('edit'))
1834
            ->will($this->returnValue(true));
1835
1836
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1837
            ->method('getClass')
1838
            ->will($this->returnValue('stdClass'));
1839
1840
        $form = $this->createMock(Form::class);
1841
1842
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1843
            ->method('getForm')
1844
            ->will($this->returnValue($form));
1845
1846
        $form->expects($this->once())
1847
            ->method('isValid')
1848
            ->will($this->returnValue(true));
1849
1850
        $form->expects($this->once())
1851
            ->method('getData')
1852
            ->will($this->returnValue($object));
1853
1854
        $form->expects($this->once())
1855
            ->method('all')
1856
            ->willReturn(['field' => 'fielddata']);
1857
1858
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1859
            ->method('toString')
1860
            ->with($this->equalTo($object))
1861
            ->will($this->returnValue($toStringValue));
1862
1863
        $this->expectTranslate('flash_edit_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1864
1865
        $form->expects($this->once())
1866
            ->method('isSubmitted')
1867
            ->will($this->returnValue(true));
1868
        $this->request->setMethod('POST');
1869
1870
        $formView = $this->createMock(FormView::class);
1871
1872
        $form->expects($this->any())
1873
            ->method('createView')
1874
            ->will($this->returnValue($formView));
1875
1876
        $this->assertLoggerLogsModelManagerException($this->admin, 'update');
1877
        $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...
1878
1879
        $this->assertSame($this->admin, $this->parameters['admin']);
1880
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1881
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1882
1883
        $this->assertSame('edit', $this->parameters['action']);
1884
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1885
        $this->assertSame($object, $this->parameters['object']);
1886
1887
        $this->assertSame(['sonata_flash_error' => ['flash_edit_error']], $this->session->getFlashBag()->all());
1888
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
1889
    }
1890
1891
    public function testEditActionWithPreview()
1892
    {
1893
        $object = new \stdClass();
1894
1895
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1896
            ->method('getObject')
1897
            ->will($this->returnValue($object));
1898
1899
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1900
            ->method('checkAccess')
1901
            ->with($this->equalTo('edit'))
1902
            ->will($this->returnValue(true));
1903
1904
        $form = $this->createMock(Form::class);
1905
1906
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1907
            ->method('getForm')
1908
            ->will($this->returnValue($form));
1909
1910
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1911
            ->method('supportsPreviewMode')
1912
            ->will($this->returnValue(true));
1913
1914
        $formView = $this->createMock(FormView::class);
1915
1916
        $form->expects($this->any())
1917
            ->method('createView')
1918
            ->will($this->returnValue($formView));
1919
1920
        $form->expects($this->once())
1921
            ->method('isSubmitted')
1922
            ->will($this->returnValue(true));
1923
1924
        $form->expects($this->once())
1925
            ->method('isValid')
1926
            ->will($this->returnValue(true));
1927
1928
        $form->expects($this->once())
1929
            ->method('all')
1930
            ->willReturn(['field' => 'fielddata']);
1931
1932
        $this->request->setMethod('POST');
1933
        $this->request->request->set('btn_preview', 'Preview');
1934
1935
        $this->assertInstanceOf(Response::class, $this->controller->editAction(null, $this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::editAction() has too many arguments starting with $this->request.

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

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

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

Loading history...
1936
1937
        $this->assertSame($this->admin, $this->parameters['admin']);
1938
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
1939
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1940
1941
        $this->assertSame('edit', $this->parameters['action']);
1942
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
1943
        $this->assertSame($object, $this->parameters['object']);
1944
1945
        $this->assertSame([], $this->session->getFlashBag()->all());
1946
        $this->assertSame('@SonataAdmin/CRUD/preview.html.twig', $this->template);
1947
    }
1948
1949
    public function testEditActionWithLockException()
1950
    {
1951
        $object = new \stdClass();
1952
        $class = \get_class($object);
1953
1954
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1955
            ->method('getObject')
1956
            ->will($this->returnValue($object));
1957
1958
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1959
            ->method('checkAccess')
1960
            ->with($this->equalTo('edit'))
1961
            ->will($this->returnValue(true));
1962
1963
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1964
            ->method('getClass')
1965
            ->will($this->returnValue($class));
1966
1967
        $form = $this->createMock(Form::class);
1968
1969
        $form->expects($this->any())
1970
            ->method('isValid')
1971
            ->will($this->returnValue(true));
1972
1973
        $form->expects($this->once())
1974
            ->method('getData')
1975
            ->will($this->returnValue($object));
1976
1977
        $form->expects($this->once())
1978
            ->method('all')
1979
            ->willReturn(['field' => 'fielddata']);
1980
1981
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1982
            ->method('getForm')
1983
            ->will($this->returnValue($form));
1984
1985
        $form->expects($this->any())
1986
            ->method('isSubmitted')
1987
            ->will($this->returnValue(true));
1988
        $this->request->setMethod('POST');
1989
1990
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1991
            ->method('update')
1992
            ->will($this->throwException(new LockException()));
1993
1994
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1995
            ->method('toString')
1996
            ->with($this->equalTo($object))
1997
            ->will($this->returnValue($class));
1998
1999
        $formView = $this->createMock(FormView::class);
2000
2001
        $form->expects($this->any())
2002
            ->method('createView')
2003
            ->will($this->returnValue($formView));
2004
2005
        $this->expectTranslate('flash_lock_error', [
2006
            '%name%' => $class,
2007
            '%link_start%' => '<a href="stdClass_edit">',
2008
            '%link_end%' => '</a>',
2009
        ], 'SonataAdminBundle');
2010
2011
        $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...
2012
    }
2013
2014
    public function testCreateActionAccessDenied()
2015
    {
2016
        $this->expectException(AccessDeniedException::class);
2017
2018
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2019
            ->method('checkAccess')
2020
            ->with($this->equalTo('create'))
2021
            ->will($this->throwException(new AccessDeniedException()));
2022
2023
        $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...
2024
    }
2025
2026
    public function testCreateActionRuntimeException()
2027
    {
2028
        $this->expectException(\RuntimeException::class);
2029
2030
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2031
            ->method('checkAccess')
2032
            ->with($this->equalTo('create'))
2033
            ->will($this->returnValue(true));
2034
2035
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
2040
            ->method('getNewInstance')
2041
            ->will($this->returnValue(new \stdClass()));
2042
2043
        $form = $this->createMock(Form::class);
2044
2045
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2046
            ->method('getForm')
2047
            ->will($this->returnValue($form));
2048
2049
        $form->expects($this->once())
2050
            ->method('all')
2051
            ->willReturn([]);
2052
2053
        $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...
2054
    }
2055
2056
    public function testPreCreate()
2057
    {
2058
        $object = new \stdClass();
2059
        $object->foo = 123456;
2060
2061
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2062
            ->method('checkAccess')
2063
            ->with($this->equalTo('create'))
2064
            ->will($this->returnValue(true));
2065
2066
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2067
            ->method('getClass')
2068
            ->will($this->returnValue('stdClass'));
2069
2070
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2071
            ->method('getNewInstance')
2072
            ->will($this->returnValue($object));
2073
2074
        $controller = new PreCRUDController();
2075
        $controller->setContainer($this->container);
2076
2077
        $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...
2078
        $this->assertInstanceOf(Response::class, $response);
2079
        $this->assertSame('preCreate called: 123456', $response->getContent());
2080
    }
2081
2082
    public function testCreateAction()
2083
    {
2084
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2085
            ->method('checkAccess')
2086
            ->with($this->equalTo('create'))
2087
            ->will($this->returnValue(true));
2088
2089
        $object = new \stdClass();
2090
2091
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2092
            ->method('getClass')
2093
            ->will($this->returnValue('stdClass'));
2094
2095
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2096
            ->method('getNewInstance')
2097
            ->will($this->returnValue($object));
2098
2099
        $form = $this->createMock(Form::class);
2100
2101
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2102
            ->method('getForm')
2103
            ->will($this->returnValue($form));
2104
2105
        $form->expects($this->once())
2106
            ->method('all')
2107
            ->willReturn(['field' => 'fielddata']);
2108
2109
        $formView = $this->createMock(FormView::class);
2110
2111
        $form->expects($this->any())
2112
            ->method('createView')
2113
            ->will($this->returnValue($formView));
2114
2115
        $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...
2116
2117
        $this->assertSame($this->admin, $this->parameters['admin']);
2118
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2119
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2120
2121
        $this->assertSame('create', $this->parameters['action']);
2122
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2123
        $this->assertSame($object, $this->parameters['object']);
2124
2125
        $this->assertSame([], $this->session->getFlashBag()->all());
2126
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
2127
    }
2128
2129
    /**
2130
     * @dataProvider getToStringValues
2131
     */
2132
    public function testCreateActionSuccess($expectedToStringValue, $toStringValue)
2133
    {
2134
        $object = new \stdClass();
2135
2136
        $this->admin->expects($this->exactly(2))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2137
            ->method('checkAccess')
2138
            ->will($this->returnCallback(function ($name, $objectIn = null) use ($object) {
2139
                if ('edit' == $name) {
2140
                    return true;
2141
                }
2142
2143
                if ('create' != $name) {
2144
                    return false;
2145
                }
2146
2147
                if (null === $objectIn) {
2148
                    return true;
2149
                }
2150
2151
                return $objectIn === $object;
2152
            }));
2153
2154
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2155
            ->method('hasRoute')
2156
            ->with($this->equalTo('edit'))
2157
            ->will($this->returnValue(true));
2158
2159
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2160
            ->method('hasAccess')
2161
            ->with($this->equalTo('edit'))
2162
            ->will($this->returnValue(true));
2163
2164
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2165
            ->method('getNewInstance')
2166
            ->will($this->returnValue($object));
2167
2168
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2169
            ->method('create')
2170
            ->will($this->returnArgument(0));
2171
2172
        $form = $this->createMock(Form::class);
2173
2174
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2175
            ->method('getClass')
2176
            ->will($this->returnValue('stdClass'));
2177
2178
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2179
            ->method('getForm')
2180
            ->will($this->returnValue($form));
2181
2182
        $form->expects($this->once())
2183
            ->method('all')
2184
            ->willReturn(['field' => 'fielddata']);
2185
2186
        $form->expects($this->once())
2187
            ->method('isSubmitted')
2188
            ->will($this->returnValue(true));
2189
2190
        $form->expects($this->once())
2191
            ->method('isValid')
2192
            ->will($this->returnValue(true));
2193
2194
        $form->expects($this->once())
2195
            ->method('getData')
2196
            ->will($this->returnValue($object));
2197
2198
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2199
            ->method('toString')
2200
            ->with($this->equalTo($object))
2201
            ->will($this->returnValue($toStringValue));
2202
2203
        $this->expectTranslate('flash_create_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
2204
2205
        $this->request->setMethod('POST');
2206
2207
        $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...
2208
2209
        $this->assertInstanceOf(RedirectResponse::class, $response);
2210
        $this->assertSame(['flash_create_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
2211
        $this->assertSame('stdClass_edit', $response->getTargetUrl());
2212
    }
2213
2214
    public function testCreateActionAccessDenied2()
2215
    {
2216
        $this->expectException(AccessDeniedException::class);
2217
2218
        $object = new \stdClass();
2219
2220
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2221
            ->method('checkAccess')
2222
            ->will($this->returnCallback(function ($name, $object = null) {
2223
                if ('create' != $name) {
2224
                    throw new AccessDeniedException();
2225
                }
2226
                if (null === $object) {
2227
                    return true;
2228
                }
2229
2230
                throw new AccessDeniedException();
2231
            }));
2232
2233
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2234
            ->method('getNewInstance')
2235
            ->will($this->returnValue($object));
2236
2237
        $form = $this->createMock(Form::class);
2238
2239
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2240
            ->method('getClass')
2241
            ->will($this->returnValue('stdClass'));
2242
2243
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2244
            ->method('getForm')
2245
            ->will($this->returnValue($form));
2246
2247
        $form->expects($this->once())
2248
            ->method('all')
2249
            ->willReturn(['field' => 'fielddata']);
2250
2251
        $form->expects($this->once())
2252
            ->method('isSubmitted')
2253
            ->will($this->returnValue(true));
2254
2255
        $form->expects($this->once())
2256
            ->method('getData')
2257
            ->will($this->returnValue($object));
2258
2259
        $form->expects($this->once())
2260
            ->method('isValid')
2261
            ->will($this->returnValue(true));
2262
2263
        $this->request->setMethod('POST');
2264
2265
        $this->controller->createAction($this->request);
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::createAction() has too many arguments starting with $this->request.

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

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

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

Loading history...
2266
    }
2267
2268
    /**
2269
     * @dataProvider getToStringValues
2270
     */
2271
    public function testCreateActionError($expectedToStringValue, $toStringValue)
2272
    {
2273
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2274
            ->method('checkAccess')
2275
            ->with($this->equalTo('create'))
2276
            ->will($this->returnValue(true));
2277
2278
        $object = new \stdClass();
2279
2280
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2281
            ->method('getClass')
2282
            ->will($this->returnValue('stdClass'));
2283
2284
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2285
            ->method('getNewInstance')
2286
            ->will($this->returnValue($object));
2287
2288
        $form = $this->createMock(Form::class);
2289
2290
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2291
            ->method('getForm')
2292
            ->will($this->returnValue($form));
2293
2294
        $form->expects($this->once())
2295
            ->method('all')
2296
            ->willReturn(['field' => 'fielddata']);
2297
2298
        $form->expects($this->once())
2299
            ->method('isSubmitted')
2300
            ->will($this->returnValue(true));
2301
2302
        $form->expects($this->once())
2303
            ->method('isValid')
2304
            ->will($this->returnValue(false));
2305
2306
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2307
            ->method('toString')
2308
            ->with($this->equalTo($object))
2309
            ->will($this->returnValue($toStringValue));
2310
2311
        $this->expectTranslate('flash_create_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
2312
2313
        $this->request->setMethod('POST');
2314
2315
        $formView = $this->createMock(FormView::class);
2316
2317
        $form->expects($this->any())
2318
            ->method('createView')
2319
            ->will($this->returnValue($formView));
2320
2321
        $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...
2322
2323
        $this->assertSame($this->admin, $this->parameters['admin']);
2324
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2325
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2326
2327
        $this->assertSame('create', $this->parameters['action']);
2328
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2329
        $this->assertSame($object, $this->parameters['object']);
2330
2331
        $this->assertSame(['sonata_flash_error' => ['flash_create_error']], $this->session->getFlashBag()->all());
2332
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
2333
    }
2334
2335
    /**
2336
     * @dataProvider getToStringValues
2337
     */
2338
    public function testCreateActionWithModelManagerException($expectedToStringValue, $toStringValue)
2339
    {
2340
        $this->admin->expects($this->exactly(2))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2341
            ->method('checkAccess')
2342
            ->with($this->equalTo('create'))
2343
            ->will($this->returnValue(true));
2344
2345
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2346
            ->method('getClass')
2347
            ->will($this->returnValue('stdClass'));
2348
2349
        $object = new \stdClass();
2350
2351
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2352
            ->method('getNewInstance')
2353
            ->will($this->returnValue($object));
2354
2355
        $form = $this->createMock(Form::class);
2356
2357
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2358
            ->method('getForm')
2359
            ->will($this->returnValue($form));
2360
2361
        $form->expects($this->once())
2362
            ->method('all')
2363
            ->willReturn(['field' => 'fielddata']);
2364
2365
        $form->expects($this->once())
2366
            ->method('isValid')
2367
            ->will($this->returnValue(true));
2368
2369
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2370
            ->method('toString')
2371
            ->with($this->equalTo($object))
2372
            ->will($this->returnValue($toStringValue));
2373
2374
        $this->expectTranslate('flash_create_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
2375
2376
        $form->expects($this->once())
2377
            ->method('isSubmitted')
2378
            ->will($this->returnValue(true));
2379
2380
        $form->expects($this->once())
2381
            ->method('getData')
2382
            ->will($this->returnValue($object));
2383
2384
        $this->request->setMethod('POST');
2385
2386
        $formView = $this->createMock(FormView::class);
2387
2388
        $form->expects($this->any())
2389
            ->method('createView')
2390
            ->will($this->returnValue($formView));
2391
2392
        $this->assertLoggerLogsModelManagerException($this->admin, 'create');
2393
2394
        $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...
2395
2396
        $this->assertSame($this->admin, $this->parameters['admin']);
2397
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2398
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2399
2400
        $this->assertSame('create', $this->parameters['action']);
2401
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2402
        $this->assertSame($object, $this->parameters['object']);
2403
2404
        $this->assertSame(['sonata_flash_error' => ['flash_create_error']], $this->session->getFlashBag()->all());
2405
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
2406
    }
2407
2408
    public function testCreateActionAjaxSuccess()
2409
    {
2410
        $object = new \stdClass();
2411
2412
        $this->admin->expects($this->exactly(2))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2413
            ->method('checkAccess')
2414
            ->will($this->returnCallback(function ($name, $objectIn = null) use ($object) {
2415
                if ('create' != $name) {
2416
                    return false;
2417
                }
2418
2419
                if (null === $objectIn) {
2420
                    return true;
2421
                }
2422
2423
                return $objectIn === $object;
2424
            }));
2425
2426
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2427
            ->method('getNewInstance')
2428
            ->will($this->returnValue($object));
2429
2430
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2431
            ->method('create')
2432
            ->will($this->returnArgument(0));
2433
2434
        $form = $this->createMock(Form::class);
2435
2436
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2437
            ->method('getForm')
2438
            ->will($this->returnValue($form));
2439
2440
        $form->expects($this->once())
2441
            ->method('all')
2442
            ->willReturn(['field' => 'fielddata']);
2443
2444
        $form->expects($this->once())
2445
            ->method('isSubmitted')
2446
            ->will($this->returnValue(true));
2447
2448
        $form->expects($this->once())
2449
            ->method('isValid')
2450
            ->will($this->returnValue(true));
2451
2452
        $form->expects($this->once())
2453
            ->method('getData')
2454
            ->will($this->returnValue($object));
2455
2456
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
2461
            ->method('getNormalizedIdentifier')
2462
            ->with($this->equalTo($object))
2463
            ->will($this->returnValue('foo_normalized'));
2464
2465
        $this->request->setMethod('POST');
2466
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
2467
2468
        $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...
2469
2470
        $this->assertInstanceOf(Response::class, $response);
2471
        $this->assertSame(json_encode(['result' => 'ok', 'objectId' => 'foo_normalized']), $response->getContent());
2472
        $this->assertSame([], $this->session->getFlashBag()->all());
2473
    }
2474
2475
    public function testCreateActionAjaxError()
2476
    {
2477
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
2485
            ->method('getNewInstance')
2486
            ->will($this->returnValue($object));
2487
2488
        $form = $this->createMock(Form::class);
2489
2490
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2491
            ->method('getClass')
2492
            ->will($this->returnValue('stdClass'));
2493
2494
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2495
            ->method('getForm')
2496
            ->will($this->returnValue($form));
2497
2498
        $form->expects($this->once())
2499
            ->method('all')
2500
            ->willReturn(['field' => 'fielddata']);
2501
2502
        $form->expects($this->once())
2503
            ->method('isSubmitted')
2504
            ->will($this->returnValue(true));
2505
2506
        $form->expects($this->once())
2507
            ->method('isValid')
2508
            ->will($this->returnValue(false));
2509
2510
        $this->request->setMethod('POST');
2511
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
2512
2513
        $formView = $this->createMock(FormView::class);
2514
2515
        $form->expects($this->any())
2516
            ->method('createView')
2517
            ->will($this->returnValue($formView));
2518
2519
        $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...
2520
2521
        $this->assertSame($this->admin, $this->parameters['admin']);
2522
        $this->assertSame('@SonataAdmin/ajax_layout.html.twig', $this->parameters['base_template']);
2523
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2524
2525
        $this->assertSame('create', $this->parameters['action']);
2526
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2527
        $this->assertSame($object, $this->parameters['object']);
2528
2529
        $this->assertSame([], $this->session->getFlashBag()->all());
2530
        $this->assertSame('@SonataAdmin/CRUD/edit.html.twig', $this->template);
2531
    }
2532
2533
    public function testCreateActionWithPreview()
2534
    {
2535
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
2543
            ->method('getNewInstance')
2544
            ->will($this->returnValue($object));
2545
2546
        $form = $this->createMock(Form::class);
2547
2548
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2549
            ->method('getClass')
2550
            ->will($this->returnValue('stdClass'));
2551
2552
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2553
            ->method('getForm')
2554
            ->will($this->returnValue($form));
2555
2556
        $form->expects($this->once())
2557
            ->method('all')
2558
            ->willReturn(['field' => 'fielddata']);
2559
2560
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2561
            ->method('supportsPreviewMode')
2562
            ->will($this->returnValue(true));
2563
2564
        $formView = $this->createMock(FormView::class);
2565
2566
        $form->expects($this->any())
2567
            ->method('createView')
2568
            ->will($this->returnValue($formView));
2569
2570
        $form->expects($this->once())
2571
            ->method('isSubmitted')
2572
            ->will($this->returnValue(true));
2573
2574
        $form->expects($this->once())
2575
            ->method('isValid')
2576
            ->will($this->returnValue(true));
2577
2578
        $this->request->setMethod('POST');
2579
        $this->request->request->set('btn_preview', 'Preview');
2580
2581
        $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...
2582
2583
        $this->assertSame($this->admin, $this->parameters['admin']);
2584
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2585
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2586
2587
        $this->assertSame('create', $this->parameters['action']);
2588
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
2589
        $this->assertSame($object, $this->parameters['object']);
2590
2591
        $this->assertSame([], $this->session->getFlashBag()->all());
2592
        $this->assertSame('@SonataAdmin/CRUD/preview.html.twig', $this->template);
2593
    }
2594
2595
    public function testExportActionAccessDenied()
2596
    {
2597
        $this->expectException(AccessDeniedException::class);
2598
2599
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2600
            ->method('checkAccess')
2601
            ->with($this->equalTo('export'))
2602
            ->will($this->throwException(new AccessDeniedException()));
2603
2604
        $this->controller->exportAction($this->request);
2605
    }
2606
2607
    public function testExportActionWrongFormat()
2608
    {
2609
        $this->expectException(\RuntimeException::class, 'Export in format `csv` is not allowed for class: `Foo`. Allowed formats are: `json`');
2610
2611
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2612
            ->method('checkAccess')
2613
            ->with($this->equalTo('export'))
2614
            ->will($this->returnValue(true));
2615
2616
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2617
            ->method('getExportFormats')
2618
            ->will($this->returnValue(['json']));
2619
2620
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2621
            ->method('getClass')
2622
            ->will($this->returnValue('Foo'));
2623
2624
        $this->request->query->set('format', 'csv');
2625
2626
        $this->controller->exportAction($this->request);
2627
    }
2628
2629
    public function testExportAction()
2630
    {
2631
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2632
            ->method('checkAccess')
2633
            ->with($this->equalTo('export'))
2634
            ->will($this->returnValue(true));
2635
2636
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2637
            ->method('getExportFormats')
2638
            ->will($this->returnValue(['json']));
2639
2640
        $dataSourceIterator = $this->createMock(SourceIteratorInterface::class);
2641
2642
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2643
            ->method('getDataSourceIterator')
2644
            ->will($this->returnValue($dataSourceIterator));
2645
2646
        $this->request->query->set('format', 'json');
2647
2648
        $response = $this->controller->exportAction($this->request);
2649
        $this->assertInstanceOf(StreamedResponse::class, $response);
2650
        $this->assertSame(200, $response->getStatusCode());
2651
        $this->assertSame([], $this->session->getFlashBag()->all());
2652
    }
2653
2654
    public function testHistoryActionAccessDenied()
2655
    {
2656
        $this->expectException(AccessDeniedException::class);
2657
2658
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
2663
            ->method('checkAccess')
2664
            ->with($this->equalTo('history'))
2665
            ->will($this->throwException(new AccessDeniedException()));
2666
2667
        $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...
2668
    }
2669
2670
    public function testHistoryActionNotFoundException()
2671
    {
2672
        $this->expectException(NotFoundHttpException::class);
2673
2674
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2675
            ->method('getObject')
2676
            ->will($this->returnValue(false));
2677
2678
        $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...
2679
    }
2680
2681
    public function testHistoryActionNoReader()
2682
    {
2683
        $this->expectException(NotFoundHttpException::class, 'unable to find the audit reader for class : Foo');
2684
2685
        $this->request->query->set('id', 123);
2686
2687
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2688
            ->method('checkAccess')
2689
            ->with($this->equalTo('history'))
2690
            ->will($this->returnValue(true));
2691
2692
        $object = new \stdClass();
2693
2694
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2695
            ->method('getObject')
2696
            ->will($this->returnValue($object));
2697
2698
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2699
            ->method('getClass')
2700
            ->will($this->returnValue('Foo'));
2701
2702
        $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...
2703
            ->method('hasReader')
2704
            ->with($this->equalTo('Foo'))
2705
            ->will($this->returnValue(false));
2706
2707
        $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...
2708
    }
2709
2710
    public function testHistoryAction()
2711
    {
2712
        $this->request->query->set('id', 123);
2713
2714
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2715
            ->method('checkAccess')
2716
            ->with($this->equalTo('history'))
2717
            ->will($this->returnValue(true));
2718
2719
        $object = new \stdClass();
2720
2721
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2722
            ->method('getObject')
2723
            ->will($this->returnValue($object));
2724
2725
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2726
            ->method('getClass')
2727
            ->will($this->returnValue('Foo'));
2728
2729
        $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...
2730
            ->method('hasReader')
2731
            ->with($this->equalTo('Foo'))
2732
            ->will($this->returnValue(true));
2733
2734
        $reader = $this->createMock(AuditReaderInterface::class);
2735
2736
        $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...
2737
            ->method('getReader')
2738
            ->with($this->equalTo('Foo'))
2739
            ->will($this->returnValue($reader));
2740
2741
        $reader->expects($this->once())
2742
            ->method('findRevisions')
2743
            ->with($this->equalTo('Foo'), $this->equalTo(123))
2744
            ->will($this->returnValue([]));
2745
2746
        $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...
2747
2748
        $this->assertSame($this->admin, $this->parameters['admin']);
2749
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2750
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2751
2752
        $this->assertSame('history', $this->parameters['action']);
2753
        $this->assertSame([], $this->parameters['revisions']);
2754
        $this->assertSame($object, $this->parameters['object']);
2755
2756
        $this->assertSame([], $this->session->getFlashBag()->all());
2757
        $this->assertSame('@SonataAdmin/CRUD/history.html.twig', $this->template);
2758
    }
2759
2760
    public function testAclActionAclNotEnabled()
2761
    {
2762
        $this->expectException(NotFoundHttpException::class, 'ACL are not enabled for this admin');
2763
2764
        $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...
2765
    }
2766
2767
    public function testAclActionNotFoundException()
2768
    {
2769
        $this->expectException(NotFoundHttpException::class);
2770
2771
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2772
            ->method('isAclEnabled')
2773
            ->will($this->returnValue(true));
2774
2775
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2776
            ->method('getObject')
2777
            ->will($this->returnValue(false));
2778
2779
        $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...
2780
    }
2781
2782
    public function testAclActionAccessDenied()
2783
    {
2784
        $this->expectException(AccessDeniedException::class);
2785
2786
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2787
            ->method('isAclEnabled')
2788
            ->will($this->returnValue(true));
2789
2790
        $object = new \stdClass();
2791
2792
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2793
            ->method('getObject')
2794
            ->will($this->returnValue($object));
2795
2796
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2797
            ->method('checkAccess')
2798
            ->with($this->equalTo('acl'), $this->equalTo($object))
2799
            ->will($this->throwException(new AccessDeniedException()));
2800
2801
        $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...
2802
    }
2803
2804
    public function testAclAction()
2805
    {
2806
        $this->request->query->set('id', 123);
2807
2808
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2809
            ->method('isAclEnabled')
2810
            ->will($this->returnValue(true));
2811
2812
        $object = new \stdClass();
2813
2814
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2815
            ->method('getObject')
2816
            ->will($this->returnValue($object));
2817
2818
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2819
            ->method('checkAccess')
2820
            ->will($this->returnValue(true));
2821
2822
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2823
            ->method('getSecurityInformation')
2824
            ->will($this->returnValue([]));
2825
2826
        $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...
2827
            ->method('getMaskBuilderClass')
2828
            ->will($this->returnValue(AdminPermissionMap::class));
2829
2830
        $aclUsersForm = $this->getMockBuilder(Form::class)
2831
            ->disableOriginalConstructor()
2832
            ->getMock();
2833
2834
        $aclUsersForm->expects($this->once())
2835
            ->method('createView')
2836
            ->will($this->returnValue($this->createMock(FormView::class)));
2837
2838
        $aclRolesForm = $this->getMockBuilder(Form::class)
2839
            ->disableOriginalConstructor()
2840
            ->getMock();
2841
2842
        $aclRolesForm->expects($this->once())
2843
            ->method('createView')
2844
            ->will($this->returnValue($this->createMock(FormView::class)));
2845
2846
        $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...
2847
            ->method('createAclUsersForm')
2848
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2849
            ->will($this->returnValue($aclUsersForm));
2850
2851
        $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...
2852
            ->method('createAclRolesForm')
2853
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2854
            ->will($this->returnValue($aclRolesForm));
2855
2856
        $aclSecurityHandler = $this->getMockBuilder(AclSecurityHandler::class)
2857
            ->disableOriginalConstructor()
2858
            ->getMock();
2859
2860
        $aclSecurityHandler->expects($this->any())
2861
            ->method('getObjectPermissions')
2862
            ->will($this->returnValue([]));
2863
2864
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2865
            ->method('getSecurityHandler')
2866
            ->will($this->returnValue($aclSecurityHandler));
2867
2868
        $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...
2869
2870
        $this->assertSame($this->admin, $this->parameters['admin']);
2871
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2872
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2873
2874
        $this->assertSame('acl', $this->parameters['action']);
2875
        $this->assertSame([], $this->parameters['permissions']);
2876
        $this->assertSame($object, $this->parameters['object']);
2877
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['users']);
2878
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['roles']);
2879
        $this->assertInstanceOf(FormView::class, $this->parameters['aclUsersForm']);
2880
        $this->assertInstanceOf(FormView::class, $this->parameters['aclRolesForm']);
2881
2882
        $this->assertSame([], $this->session->getFlashBag()->all());
2883
        $this->assertSame('@SonataAdmin/CRUD/acl.html.twig', $this->template);
2884
    }
2885
2886
    public function testAclActionInvalidUpdate()
2887
    {
2888
        $this->request->query->set('id', 123);
2889
        $this->request->request->set(AdminObjectAclManipulator::ACL_USERS_FORM_NAME, []);
2890
2891
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2892
            ->method('isAclEnabled')
2893
            ->will($this->returnValue(true));
2894
2895
        $object = new \stdClass();
2896
2897
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2898
            ->method('getObject')
2899
            ->will($this->returnValue($object));
2900
2901
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2902
            ->method('checkAccess')
2903
            ->will($this->returnValue(true));
2904
2905
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2906
            ->method('getSecurityInformation')
2907
            ->will($this->returnValue([]));
2908
2909
        $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...
2910
            ->method('getMaskBuilderClass')
2911
            ->will($this->returnValue(AdminPermissionMap::class));
2912
2913
        $aclUsersForm = $this->getMockBuilder(Form::class)
2914
            ->disableOriginalConstructor()
2915
            ->getMock();
2916
2917
        $aclUsersForm->expects($this->once())
2918
            ->method('isValid')
2919
            ->will($this->returnValue(false));
2920
2921
        $aclUsersForm->expects($this->once())
2922
            ->method('createView')
2923
            ->will($this->returnValue($this->createMock(FormView::class)));
2924
2925
        $aclRolesForm = $this->getMockBuilder(Form::class)
2926
            ->disableOriginalConstructor()
2927
            ->getMock();
2928
2929
        $aclRolesForm->expects($this->once())
2930
            ->method('createView')
2931
            ->will($this->returnValue($this->createMock(FormView::class)));
2932
2933
        $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...
2934
            ->method('createAclUsersForm')
2935
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2936
            ->will($this->returnValue($aclUsersForm));
2937
2938
        $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...
2939
            ->method('createAclRolesForm')
2940
            ->with($this->isInstanceOf(AdminObjectAclData::class))
2941
            ->will($this->returnValue($aclRolesForm));
2942
2943
        $aclSecurityHandler = $this->getMockBuilder(AclSecurityHandler::class)
2944
            ->disableOriginalConstructor()
2945
            ->getMock();
2946
2947
        $aclSecurityHandler->expects($this->any())
2948
            ->method('getObjectPermissions')
2949
            ->will($this->returnValue([]));
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\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getSecurityHandler')
2953
            ->will($this->returnValue($aclSecurityHandler));
2954
2955
        $this->request->setMethod('POST');
2956
2957
        $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...
2958
2959
        $this->assertSame($this->admin, $this->parameters['admin']);
2960
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
2961
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2962
2963
        $this->assertSame('acl', $this->parameters['action']);
2964
        $this->assertSame([], $this->parameters['permissions']);
2965
        $this->assertSame($object, $this->parameters['object']);
2966
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['users']);
2967
        $this->assertInstanceOf(\ArrayIterator::class, $this->parameters['roles']);
2968
        $this->assertInstanceOf(FormView::class, $this->parameters['aclUsersForm']);
2969
        $this->assertInstanceOf(FormView::class, $this->parameters['aclRolesForm']);
2970
2971
        $this->assertSame([], $this->session->getFlashBag()->all());
2972
        $this->assertSame('@SonataAdmin/CRUD/acl.html.twig', $this->template);
2973
    }
2974
2975
    public function testAclActionSuccessfulUpdate()
2976
    {
2977
        $this->request->query->set('id', 123);
2978
        $this->request->request->set(AdminObjectAclManipulator::ACL_ROLES_FORM_NAME, []);
2979
2980
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2981
            ->method('isAclEnabled')
2982
            ->will($this->returnValue(true));
2983
2984
        $object = new \stdClass();
2985
2986
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2987
            ->method('getObject')
2988
            ->will($this->returnValue($object));
2989
2990
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2991
            ->method('checkAccess')
2992
            ->will($this->returnValue(true));
2993
2994
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2995
            ->method('getSecurityInformation')
2996
            ->will($this->returnValue([]));
2997
2998
        $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...
2999
            ->method('getMaskBuilderClass')
3000
            ->will($this->returnValue(AdminPermissionMap::class));
3001
3002
        $aclUsersForm = $this->getMockBuilder(Form::class)
3003
            ->disableOriginalConstructor()
3004
            ->getMock();
3005
3006
        $aclUsersForm->expects($this->any())
3007
            ->method('createView')
3008
            ->will($this->returnValue($this->createMock(FormView::class)));
3009
3010
        $aclRolesForm = $this->getMockBuilder(Form::class)
3011
            ->disableOriginalConstructor()
3012
            ->getMock();
3013
3014
        $aclRolesForm->expects($this->any())
3015
            ->method('createView')
3016
            ->will($this->returnValue($this->createMock(FormView::class)));
3017
3018
        $aclRolesForm->expects($this->once())
3019
            ->method('isValid')
3020
            ->will($this->returnValue(true));
3021
3022
        $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...
3023
            ->method('createAclUsersForm')
3024
            ->with($this->isInstanceOf(AdminObjectAclData::class))
3025
            ->will($this->returnValue($aclUsersForm));
3026
3027
        $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...
3028
            ->method('createAclRolesForm')
3029
            ->with($this->isInstanceOf(AdminObjectAclData::class))
3030
            ->will($this->returnValue($aclRolesForm));
3031
3032
        $aclSecurityHandler = $this->getMockBuilder(AclSecurityHandler::class)
3033
            ->disableOriginalConstructor()
3034
            ->getMock();
3035
3036
        $aclSecurityHandler->expects($this->any())
3037
            ->method('getObjectPermissions')
3038
            ->will($this->returnValue([]));
3039
3040
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3041
            ->method('getSecurityHandler')
3042
            ->will($this->returnValue($aclSecurityHandler));
3043
3044
        $this->expectTranslate('flash_acl_edit_success', [], 'SonataAdminBundle');
3045
3046
        $this->request->setMethod('POST');
3047
3048
        $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...
3049
3050
        $this->assertInstanceOf(RedirectResponse::class, $response);
3051
3052
        $this->assertSame(['flash_acl_edit_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3053
        $this->assertSame('stdClass_acl', $response->getTargetUrl());
3054
    }
3055
3056
    public function testHistoryViewRevisionActionAccessDenied()
3057
    {
3058
        $this->expectException(AccessDeniedException::class);
3059
3060
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
3065
            ->method('checkAccess')
3066
            ->with($this->equalTo('historyViewRevision'))
3067
            ->will($this->throwException(new AccessDeniedException()));
3068
3069
        $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...
3070
    }
3071
3072
    public function testHistoryViewRevisionActionNotFoundException()
3073
    {
3074
        $this->expectException(NotFoundHttpException::class, 'unable to find the object with id: 123');
3075
3076
        $this->request->query->set('id', 123);
3077
3078
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3079
            ->method('getObject')
3080
            ->will($this->returnValue(false));
3081
3082
        $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...
3083
    }
3084
3085
    public function testHistoryViewRevisionActionNoReader()
3086
    {
3087
        $this->expectException(NotFoundHttpException::class, 'unable to find the audit reader for class : Foo');
3088
3089
        $this->request->query->set('id', 123);
3090
3091
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3092
            ->method('checkAccess')
3093
            ->with($this->equalTo('historyViewRevision'))
3094
            ->will($this->returnValue(true));
3095
3096
        $object = new \stdClass();
3097
3098
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3099
            ->method('getObject')
3100
            ->will($this->returnValue($object));
3101
3102
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3103
            ->method('getClass')
3104
            ->will($this->returnValue('Foo'));
3105
3106
        $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...
3107
            ->method('hasReader')
3108
            ->with($this->equalTo('Foo'))
3109
            ->will($this->returnValue(false));
3110
3111
        $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...
3112
    }
3113
3114
    public function testHistoryViewRevisionActionNotFoundRevision()
3115
    {
3116
        $this->expectException(NotFoundHttpException::class, 'unable to find the targeted object `123` from the revision `456` with classname : `Foo`');
3117
3118
        $this->request->query->set('id', 123);
3119
3120
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3121
            ->method('checkAccess')
3122
            ->with($this->equalTo('historyViewRevision'))
3123
            ->will($this->returnValue(true));
3124
3125
        $object = new \stdClass();
3126
3127
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3128
            ->method('getObject')
3129
            ->will($this->returnValue($object));
3130
3131
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3132
            ->method('getClass')
3133
            ->will($this->returnValue('Foo'));
3134
3135
        $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...
3136
            ->method('hasReader')
3137
            ->with($this->equalTo('Foo'))
3138
            ->will($this->returnValue(true));
3139
3140
        $reader = $this->createMock(AuditReaderInterface::class);
3141
3142
        $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...
3143
            ->method('getReader')
3144
            ->with($this->equalTo('Foo'))
3145
            ->will($this->returnValue($reader));
3146
3147
        $reader->expects($this->once())
3148
            ->method('find')
3149
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3150
            ->will($this->returnValue(null));
3151
3152
        $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...
3153
    }
3154
3155
    public function testHistoryViewRevisionAction()
3156
    {
3157
        $this->request->query->set('id', 123);
3158
3159
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3160
            ->method('checkAccess')
3161
            ->with($this->equalTo('historyViewRevision'))
3162
            ->will($this->returnValue(true));
3163
3164
        $object = new \stdClass();
3165
3166
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3167
            ->method('getObject')
3168
            ->will($this->returnValue($object));
3169
3170
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3171
            ->method('getClass')
3172
            ->will($this->returnValue('Foo'));
3173
3174
        $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...
3175
            ->method('hasReader')
3176
            ->with($this->equalTo('Foo'))
3177
            ->will($this->returnValue(true));
3178
3179
        $reader = $this->createMock(AuditReaderInterface::class);
3180
3181
        $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...
3182
            ->method('getReader')
3183
            ->with($this->equalTo('Foo'))
3184
            ->will($this->returnValue($reader));
3185
3186
        $objectRevision = new \stdClass();
3187
        $objectRevision->revision = 456;
3188
3189
        $reader->expects($this->once())
3190
            ->method('find')
3191
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3192
            ->will($this->returnValue($objectRevision));
3193
3194
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3195
            ->method('setSubject')
3196
            ->with($this->equalTo($objectRevision))
3197
            ->will($this->returnValue(null));
3198
3199
        $fieldDescriptionCollection = new FieldDescriptionCollection();
3200
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3201
            ->method('getShow')
3202
            ->will($this->returnValue($fieldDescriptionCollection));
3203
3204
        $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...
3205
3206
        $this->assertSame($this->admin, $this->parameters['admin']);
3207
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
3208
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3209
3210
        $this->assertSame('show', $this->parameters['action']);
3211
        $this->assertSame($objectRevision, $this->parameters['object']);
3212
        $this->assertSame($fieldDescriptionCollection, $this->parameters['elements']);
3213
3214
        $this->assertSame([], $this->session->getFlashBag()->all());
3215
        $this->assertSame('@SonataAdmin/CRUD/show.html.twig', $this->template);
3216
    }
3217
3218
    public function testHistoryCompareRevisionsActionAccessDenied()
3219
    {
3220
        $this->expectException(AccessDeniedException::class);
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\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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->throwException(new AccessDeniedException()));
3226
3227
        $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...
3228
    }
3229
3230
    public function testHistoryCompareRevisionsActionNotFoundException()
3231
    {
3232
        $this->expectException(NotFoundHttpException::class, 'unable to find the object with id: 123');
3233
3234
        $this->request->query->set('id', 123);
3235
3236
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3237
            ->method('checkAccess')
3238
            ->with($this->equalTo('historyCompareRevisions'))
3239
            ->will($this->returnValue(true));
3240
3241
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3242
            ->method('getObject')
3243
            ->will($this->returnValue(false));
3244
3245
        $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...
3246
    }
3247
3248
    public function testHistoryCompareRevisionsActionNoReader()
3249
    {
3250
        $this->expectException(NotFoundHttpException::class, 'unable to find the audit reader for class : Foo');
3251
3252
        $this->request->query->set('id', 123);
3253
3254
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3255
            ->method('checkAccess')
3256
            ->with($this->equalTo('historyCompareRevisions'))
3257
            ->will($this->returnValue(true));
3258
3259
        $object = new \stdClass();
3260
3261
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3262
            ->method('getObject')
3263
            ->will($this->returnValue($object));
3264
3265
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3266
            ->method('getClass')
3267
            ->will($this->returnValue('Foo'));
3268
3269
        $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...
3270
            ->method('hasReader')
3271
            ->with($this->equalTo('Foo'))
3272
            ->will($this->returnValue(false));
3273
3274
        $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...
3275
    }
3276
3277
    public function testHistoryCompareRevisionsActionNotFoundBaseRevision()
3278
    {
3279
        $this->expectException(NotFoundHttpException::class, 'unable to find the targeted object `123` from the revision `456` with classname : `Foo`');
3280
3281
        $this->request->query->set('id', 123);
3282
3283
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3284
            ->method('checkAccess')
3285
            ->with($this->equalTo('historyCompareRevisions'))
3286
            ->will($this->returnValue(true));
3287
3288
        $object = new \stdClass();
3289
3290
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3291
            ->method('getObject')
3292
            ->will($this->returnValue($object));
3293
3294
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3295
            ->method('getClass')
3296
            ->will($this->returnValue('Foo'));
3297
3298
        $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...
3299
            ->method('hasReader')
3300
            ->with($this->equalTo('Foo'))
3301
            ->will($this->returnValue(true));
3302
3303
        $reader = $this->createMock(AuditReaderInterface::class);
3304
3305
        $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...
3306
            ->method('getReader')
3307
            ->with($this->equalTo('Foo'))
3308
            ->will($this->returnValue($reader));
3309
3310
        // once because it will not be found and therefore the second call won't be executed
3311
        $reader->expects($this->once())
3312
            ->method('find')
3313
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3314
            ->will($this->returnValue(null));
3315
3316
        $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...
3317
    }
3318
3319
    public function testHistoryCompareRevisionsActionNotFoundCompareRevision()
3320
    {
3321
        $this->expectException(NotFoundHttpException::class, 'unable to find the targeted object `123` from the revision `789` with classname : `Foo`');
3322
3323
        $this->request->query->set('id', 123);
3324
3325
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
3348
            ->method('getReader')
3349
            ->with($this->equalTo('Foo'))
3350
            ->will($this->returnValue($reader));
3351
3352
        $objectRevision = new \stdClass();
3353
        $objectRevision->revision = 456;
3354
3355
        // first call should return, so the second call will throw an exception
3356
        $reader->expects($this->at(0))
3357
            ->method('find')
3358
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3359
            ->will($this->returnValue($objectRevision));
3360
3361
        $reader->expects($this->at(1))
3362
            ->method('find')
3363
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(789))
3364
            ->will($this->returnValue(null));
3365
3366
        $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...
3367
    }
3368
3369
    public function testHistoryCompareRevisionsActionAction()
3370
    {
3371
        $this->request->query->set('id', 123);
3372
3373
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3374
            ->method('checkAccess')
3375
            ->with($this->equalTo('historyCompareRevisions'))
3376
            ->will($this->returnValue(true));
3377
3378
        $object = new \stdClass();
3379
3380
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

Loading history...
3385
            ->method('getClass')
3386
            ->will($this->returnValue('Foo'));
3387
3388
        $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...
3389
            ->method('hasReader')
3390
            ->with($this->equalTo('Foo'))
3391
            ->will($this->returnValue(true));
3392
3393
        $reader = $this->createMock(AuditReaderInterface::class);
3394
3395
        $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...
3396
            ->method('getReader')
3397
            ->with($this->equalTo('Foo'))
3398
            ->will($this->returnValue($reader));
3399
3400
        $objectRevision = new \stdClass();
3401
        $objectRevision->revision = 456;
3402
3403
        $compareObjectRevision = new \stdClass();
3404
        $compareObjectRevision->revision = 789;
3405
3406
        $reader->expects($this->at(0))
3407
            ->method('find')
3408
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3409
            ->will($this->returnValue($objectRevision));
3410
3411
        $reader->expects($this->at(1))
3412
            ->method('find')
3413
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(789))
3414
            ->will($this->returnValue($compareObjectRevision));
3415
3416
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3417
            ->method('setSubject')
3418
            ->with($this->equalTo($objectRevision))
3419
            ->will($this->returnValue(null));
3420
3421
        $fieldDescriptionCollection = new FieldDescriptionCollection();
3422
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3423
            ->method('getShow')
3424
            ->will($this->returnValue($fieldDescriptionCollection));
3425
3426
        $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...
3427
3428
        $this->assertSame($this->admin, $this->parameters['admin']);
3429
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
3430
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3431
3432
        $this->assertSame('show', $this->parameters['action']);
3433
        $this->assertSame($objectRevision, $this->parameters['object']);
3434
        $this->assertSame($compareObjectRevision, $this->parameters['object_compare']);
3435
        $this->assertSame($fieldDescriptionCollection, $this->parameters['elements']);
3436
3437
        $this->assertSame([], $this->session->getFlashBag()->all());
3438
        $this->assertSame('@SonataAdmin/CRUD/show_compare.html.twig', $this->template);
3439
    }
3440
3441
    public function testBatchActionWrongMethod()
3442
    {
3443
        $this->expectException(NotFoundHttpException::class, 'Invalid request type "GET", POST expected');
3444
3445
        $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...
3446
    }
3447
3448
    /**
3449
     * NEXT_MAJOR: Remove this legacy group.
3450
     *
3451
     * @group legacy
3452
     */
3453
    public function testBatchActionActionNotDefined()
3454
    {
3455
        $this->expectException(\RuntimeException::class, 'The `foo` batch action is not defined');
3456
3457
        $batchActions = [];
3458
3459
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3460
            ->method('getBatchActions')
3461
            ->will($this->returnValue($batchActions));
3462
3463
        $this->request->setMethod('POST');
3464
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3465
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3466
3467
        $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...
3468
    }
3469
3470
    public function testBatchActionActionInvalidCsrfToken()
3471
    {
3472
        $this->request->setMethod('POST');
3473
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3474
        $this->request->request->set('_sonata_csrf_token', 'CSRF-INVALID');
3475
3476
        try {
3477
            $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...
3478
        } catch (HttpException $e) {
3479
            $this->assertSame('The csrf token is not valid, CSRF attack?', $e->getMessage());
3480
            $this->assertSame(400, $e->getStatusCode());
3481
        }
3482
    }
3483
3484
    /**
3485
     * NEXT_MAJOR: Remove this legacy group.
3486
     *
3487
     * @group legacy
3488
     */
3489
    public function testBatchActionMethodNotExist()
3490
    {
3491
        $this->expectException(\RuntimeException::class, 'A `Sonata\AdminBundle\Controller\CRUDController::batchActionFoo` method must be callable');
3492
3493
        $batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3494
3495
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3496
            ->method('getBatchActions')
3497
            ->will($this->returnValue($batchActions));
3498
3499
        $datagrid = $this->createMock(DatagridInterface::class);
3500
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3501
            ->method('getDatagrid')
3502
            ->will($this->returnValue($datagrid));
3503
3504
        $this->request->setMethod('POST');
3505
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3506
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3507
3508
        $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...
3509
    }
3510
3511
    /**
3512
     * NEXT_MAJOR: Remove this legacy group.
3513
     *
3514
     * @group legacy
3515
     */
3516
    public function testBatchActionWithoutConfirmation()
3517
    {
3518
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3519
3520
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3521
            ->method('getBatchActions')
3522
            ->will($this->returnValue($batchActions));
3523
3524
        $datagrid = $this->createMock(DatagridInterface::class);
3525
3526
        $query = $this->createMock(ProxyQueryInterface::class);
3527
        $datagrid->expects($this->once())
3528
            ->method('getQuery')
3529
            ->will($this->returnValue($query));
3530
3531
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3532
            ->method('getDatagrid')
3533
            ->will($this->returnValue($datagrid));
3534
3535
        $modelManager = $this->createMock(ModelManagerInterface::class);
3536
3537
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3538
            ->method('checkAccess')
3539
            ->with($this->equalTo('batchDelete'))
3540
            ->will($this->returnValue(true));
3541
3542
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3543
            ->method('getModelManager')
3544
            ->will($this->returnValue($modelManager));
3545
3546
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3547
            ->method('getClass')
3548
            ->will($this->returnValue('Foo'));
3549
3550
        $modelManager->expects($this->once())
3551
            ->method('addIdentifiersToQuery')
3552
            ->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456']))
3553
            ->will($this->returnValue(true));
3554
3555
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
3556
3557
        $this->request->setMethod('POST');
3558
        $this->request->request->set('data', json_encode(['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false]));
3559
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3560
3561
        $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...
3562
3563
        $this->assertInstanceOf(RedirectResponse::class, $result);
3564
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3565
        $this->assertSame('list', $result->getTargetUrl());
3566
    }
3567
3568
    /**
3569
     * NEXT_MAJOR: Remove this legacy group.
3570
     *
3571
     * @group legacy
3572
     */
3573
    public function testBatchActionWithoutConfirmation2()
3574
    {
3575
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3576
3577
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3578
            ->method('getBatchActions')
3579
            ->will($this->returnValue($batchActions));
3580
3581
        $datagrid = $this->createMock(DatagridInterface::class);
3582
3583
        $query = $this->createMock(ProxyQueryInterface::class);
3584
        $datagrid->expects($this->once())
3585
            ->method('getQuery')
3586
            ->will($this->returnValue($query));
3587
3588
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3589
            ->method('getDatagrid')
3590
            ->will($this->returnValue($datagrid));
3591
3592
        $modelManager = $this->createMock(ModelManagerInterface::class);
3593
3594
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3595
            ->method('checkAccess')
3596
            ->with($this->equalTo('batchDelete'))
3597
            ->will($this->returnValue(true));
3598
3599
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3600
            ->method('getModelManager')
3601
            ->will($this->returnValue($modelManager));
3602
3603
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3604
            ->method('getClass')
3605
            ->will($this->returnValue('Foo'));
3606
3607
        $modelManager->expects($this->once())
3608
            ->method('addIdentifiersToQuery')
3609
            ->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456']))
3610
            ->will($this->returnValue(true));
3611
3612
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
3613
3614
        $this->request->setMethod('POST');
3615
        $this->request->request->set('action', 'delete');
3616
        $this->request->request->set('idx', ['123', '456']);
3617
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3618
3619
        $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...
3620
3621
        $this->assertInstanceOf(RedirectResponse::class, $result);
3622
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3623
        $this->assertSame('list', $result->getTargetUrl());
3624
    }
3625
3626
    /**
3627
     * NEXT_MAJOR: Remove this legacy group.
3628
     *
3629
     * @group legacy
3630
     */
3631
    public function testBatchActionWithConfirmation()
3632
    {
3633
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'translation_domain' => 'FooBarBaz', 'ask_confirmation' => true]];
3634
3635
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
3648
            ->method('getDatagrid')
3649
            ->will($this->returnValue($datagrid));
3650
3651
        $form = $this->getMockBuilder(Form::class)
3652
            ->disableOriginalConstructor()
3653
            ->getMock();
3654
3655
        $form->expects($this->once())
3656
            ->method('createView')
3657
            ->will($this->returnValue($this->createMock(FormView::class)));
3658
3659
        $datagrid->expects($this->once())
3660
            ->method('getForm')
3661
            ->will($this->returnValue($form));
3662
3663
        $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...
3664
3665
        $this->assertSame($this->admin, $this->parameters['admin']);
3666
        $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']);
3667
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3668
3669
        $this->assertSame('list', $this->parameters['action']);
3670
        $this->assertSame($datagrid, $this->parameters['datagrid']);
3671
        $this->assertInstanceOf(FormView::class, $this->parameters['form']);
3672
        $this->assertSame($data, $this->parameters['data']);
3673
        $this->assertSame('csrf-token-123_sonata.batch', $this->parameters['csrf_token']);
3674
        $this->assertSame('Foo Bar', $this->parameters['action_label']);
3675
3676
        $this->assertSame([], $this->session->getFlashBag()->all());
3677
        $this->assertSame('@SonataAdmin/CRUD/batch_confirmation.html.twig', $this->template);
3678
    }
3679
3680
    /**
3681
     * NEXT_MAJOR: Remove this legacy group.
3682
     *
3683
     * @group legacy
3684
     */
3685
    public function testBatchActionNonRelevantAction()
3686
    {
3687
        $controller = new BatchAdminController();
3688
        $controller->setContainer($this->container);
3689
3690
        $batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3691
3692
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3693
            ->method('getBatchActions')
3694
            ->will($this->returnValue($batchActions));
3695
3696
        $datagrid = $this->createMock(DatagridInterface::class);
3697
3698
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3699
            ->method('getDatagrid')
3700
            ->will($this->returnValue($datagrid));
3701
3702
        $this->expectTranslate('flash_batch_empty', [], 'SonataAdminBundle');
3703
3704
        $this->request->setMethod('POST');
3705
        $this->request->request->set('action', 'foo');
3706
        $this->request->request->set('idx', ['789']);
3707
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3708
3709
        $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...
3710
3711
        $this->assertInstanceOf(RedirectResponse::class, $result);
3712
        $this->assertSame(['flash_batch_empty'], $this->session->getFlashBag()->get('sonata_flash_info'));
3713
        $this->assertSame('list', $result->getTargetUrl());
3714
    }
3715
3716
    /**
3717
     * NEXT_MAJOR: Remove this legacy group.
3718
     *
3719
     * @group legacy
3720
     */
3721
    public function testBatchActionNonRelevantAction2()
3722
    {
3723
        $controller = new BatchAdminController();
3724
        $controller->setContainer($this->container);
3725
3726
        $batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3727
3728
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3729
            ->method('getBatchActions')
3730
            ->will($this->returnValue($batchActions));
3731
3732
        $datagrid = $this->createMock(DatagridInterface::class);
3733
3734
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3735
            ->method('getDatagrid')
3736
            ->will($this->returnValue($datagrid));
3737
3738
        $this->expectTranslate('flash_foo_error', [], 'SonataAdminBundle');
3739
3740
        $this->request->setMethod('POST');
3741
        $this->request->request->set('action', 'foo');
3742
        $this->request->request->set('idx', ['999']);
3743
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3744
3745
        $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...
3746
3747
        $this->assertInstanceOf(RedirectResponse::class, $result);
3748
        $this->assertSame(['flash_foo_error'], $this->session->getFlashBag()->get('sonata_flash_info'));
3749
        $this->assertSame('list', $result->getTargetUrl());
3750
    }
3751
3752
    /**
3753
     * NEXT_MAJOR: Remove this legacy group.
3754
     *
3755
     * @group legacy
3756
     */
3757
    public function testBatchActionNoItems()
3758
    {
3759
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => true]];
3760
3761
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3762
            ->method('getBatchActions')
3763
            ->will($this->returnValue($batchActions));
3764
3765
        $datagrid = $this->createMock(DatagridInterface::class);
3766
3767
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3768
            ->method('getDatagrid')
3769
            ->will($this->returnValue($datagrid));
3770
3771
        $this->expectTranslate('flash_batch_empty', [], 'SonataAdminBundle');
3772
3773
        $this->request->setMethod('POST');
3774
        $this->request->request->set('action', 'delete');
3775
        $this->request->request->set('idx', []);
3776
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3777
3778
        $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...
3779
3780
        $this->assertInstanceOf(RedirectResponse::class, $result);
3781
        $this->assertSame(['flash_batch_empty'], $this->session->getFlashBag()->get('sonata_flash_info'));
3782
        $this->assertSame('list', $result->getTargetUrl());
3783
    }
3784
3785
    /**
3786
     * NEXT_MAJOR: Remove this legacy group.
3787
     *
3788
     * @group legacy
3789
     */
3790
    public function testBatchActionNoItemsEmptyQuery()
3791
    {
3792
        $controller = new BatchAdminController();
3793
        $controller->setContainer($this->container);
3794
3795
        $batchActions = ['bar' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3796
3797
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3798
            ->method('getBatchActions')
3799
            ->will($this->returnValue($batchActions));
3800
3801
        $datagrid = $this->createMock(DatagridInterface::class);
3802
3803
        $query = $this->createMock(ProxyQueryInterface::class);
3804
        $datagrid->expects($this->once())
3805
            ->method('getQuery')
3806
            ->will($this->returnValue($query));
3807
3808
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3809
            ->method('getDatagrid')
3810
            ->will($this->returnValue($datagrid));
3811
3812
        $modelManager = $this->createMock(ModelManagerInterface::class);
3813
3814
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3815
            ->method('getModelManager')
3816
            ->will($this->returnValue($modelManager));
3817
3818
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3819
            ->method('getClass')
3820
            ->will($this->returnValue('Foo'));
3821
3822
        $this->request->setMethod('POST');
3823
        $this->request->request->set('action', 'bar');
3824
        $this->request->request->set('idx', []);
3825
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3826
3827
        $this->expectTranslate('flash_batch_no_elements_processed', [], 'SonataAdminBundle');
3828
        $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...
3829
3830
        $this->assertInstanceOf(Response::class, $result);
3831
        $this->assertRegExp('/Redirecting to list/', $result->getContent());
3832
    }
3833
3834
    /**
3835
     * NEXT_MAJOR: Remove this legacy group.
3836
     *
3837
     * @group legacy
3838
     */
3839
    public function testBatchActionWithRequesData()
3840
    {
3841
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3842
3843
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3844
            ->method('getBatchActions')
3845
            ->will($this->returnValue($batchActions));
3846
3847
        $datagrid = $this->createMock(DatagridInterface::class);
3848
3849
        $query = $this->createMock(ProxyQueryInterface::class);
3850
        $datagrid->expects($this->once())
3851
            ->method('getQuery')
3852
            ->will($this->returnValue($query));
3853
3854
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3855
            ->method('getDatagrid')
3856
            ->will($this->returnValue($datagrid));
3857
3858
        $modelManager = $this->createMock(ModelManagerInterface::class);
3859
3860
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3861
            ->method('checkAccess')
3862
            ->with($this->equalTo('batchDelete'))
3863
            ->will($this->returnValue(true));
3864
3865
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3866
            ->method('getModelManager')
3867
            ->will($this->returnValue($modelManager));
3868
3869
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3870
            ->method('getClass')
3871
            ->will($this->returnValue('Foo'));
3872
3873
        $modelManager->expects($this->once())
3874
            ->method('addIdentifiersToQuery')
3875
            ->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456']))
3876
            ->will($this->returnValue(true));
3877
3878
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
3879
3880
        $this->request->setMethod('POST');
3881
        $this->request->request->set('data', json_encode(['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false]));
3882
        $this->request->request->set('foo', 'bar');
3883
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3884
3885
        $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...
3886
3887
        $this->assertInstanceOf(RedirectResponse::class, $result);
3888
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3889
        $this->assertSame('list', $result->getTargetUrl());
3890
        $this->assertSame('bar', $this->request->request->get('foo'));
3891
    }
3892
3893
    public function testItThrowsWhenCallingAnUndefinedMethod()
3894
    {
3895
        $this->expectException(
3896
            \LogicException::class
3897
        );
3898
        $this->expectExceptionMessage(
3899
            'Call to undefined method Sonata\AdminBundle\Controller\CRUDController::doesNotExist'
3900
        );
3901
        $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...
3902
    }
3903
3904
    /**
3905
     * @expectedDeprecation Method Sonata\AdminBundle\Controller\CRUDController::render has been renamed to Sonata\AdminBundle\Controller\CRUDController::renderWithExtraParams.
3906
     */
3907
    public function testRenderIsDeprecated()
3908
    {
3909
        $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...
3910
    }
3911
3912
    public function getCsrfProvider()
3913
    {
3914
        return $this->csrfProvider;
3915
    }
3916
3917
    public function getToStringValues()
3918
    {
3919
        return [
3920
            ['', ''],
3921
            ['Foo', 'Foo'],
3922
            ['&lt;a href=&quot;http://foo&quot;&gt;Bar&lt;/a&gt;', '<a href="http://foo">Bar</a>'],
3923
            ['&lt;&gt;&amp;&quot;&#039;abcdefghijklmnopqrstuvwxyz*-+.,?_()[]\/', '<>&"\'abcdefghijklmnopqrstuvwxyz*-+.,?_()[]\/'],
3924
        ];
3925
    }
3926
3927
    private function assertLoggerLogsModelManagerException($subject, $method)
3928
    {
3929
        $exception = new ModelManagerException(
3930
            $message = 'message',
3931
            1234,
3932
            new \Exception($previousExceptionMessage = 'very useful message')
3933
        );
3934
3935
        $subject->expects($this->once())
3936
            ->method($method)
3937
            ->will($this->returnCallback(function () use ($exception) {
3938
                throw $exception;
3939
            }));
3940
3941
        $this->logger->expects($this->once())
3942
            ->method('error')
3943
            ->with($message, [
3944
                'exception' => $exception,
3945
                'previous_exception_message' => $previousExceptionMessage,
3946
            ]);
3947
    }
3948
3949
    private function expectTranslate($id, array $parameters = [], $domain = null, $locale = null)
3950
    {
3951
        $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...
3952
            ->method('trans')
3953
            ->with($this->equalTo($id), $this->equalTo($parameters), $this->equalTo($domain), $this->equalTo($locale))
3954
            ->will($this->returnValue($id));
3955
    }
3956
}
3957