Completed
Push — 3.x ( 5349d6...5ea965 )
by Grégoire
04:11
created

CRUDControllerTest::testRenderIsDeprecated()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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

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

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

Loading history...
501
            ->method('setUniqid')
502
            ->will($this->returnCallback(function ($uniqid) use (&$uniqueId) {
503
                $uniqueId = $uniqid;
504
            }));
505
506
        $this->request->query->set('uniqid', 123456);
507
        $this->protectedTestedMethods['configure']->invoke($this->controller);
508
509
        $this->assertSame(123456, $uniqueId);
510
        $this->assertAttributeSame($this->admin, 'admin', $this->controller);
511
    }
512
513
    public function testConfigureChild()
514
    {
515
        $uniqueId = '';
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('setUniqid')
519
            ->will($this->returnCallback(function ($uniqid) use (&$uniqueId) {
520
                $uniqueId = $uniqid;
521
            }));
522
523
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
524
            ->method('isChild')
525
            ->will($this->returnValue(true));
526
527
        $adminParent = $this->getMockBuilder('Sonata\AdminBundle\Admin\AbstractAdmin')
528
            ->disableOriginalConstructor()
529
            ->getMock();
530
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

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

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

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

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

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

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

Loading history...
698
            ->method('checkAccess')
699
            ->with($this->equalTo('list'))
700
            ->will($this->returnValue(true));
701
702
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')
703
            ->disableOriginalConstructor()
704
            ->getMock();
705
706
        $form->expects($this->once())
707
            ->method('createView')
708
            ->will($this->returnValue($this->createMock('Symfony\Component\Form\FormView')));
709
710
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
711
            ->method('getDatagrid')
712
            ->will($this->returnValue($datagrid));
713
714
        $datagrid->expects($this->once())
715
            ->method('getForm')
716
            ->will($this->returnValue($form));
717
718
        $this->parameters = [];
719
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $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...
720
721
        $this->assertSame($this->admin, $this->parameters['admin']);
722
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
723
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
724
725
        $this->assertSame('list', $this->parameters['action']);
726
        $this->assertInstanceOf('Symfony\Component\Form\FormView', $this->parameters['form']);
727
        $this->assertInstanceOf('Sonata\AdminBundle\Datagrid\DatagridInterface', $this->parameters['datagrid']);
728
        $this->assertSame('csrf-token-123_sonata.batch', $this->parameters['csrf_token']);
729
        $this->assertSame([], $this->session->getFlashBag()->all());
730
        $this->assertSame('SonataAdminBundle:CRUD:list.html.twig', $this->template);
731
    }
732
733
    public function testBatchActionDeleteAccessDenied()
734
    {
735
        $this->expectException('Symfony\Component\Security\Core\Exception\AccessDeniedException');
736
737
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
738
            ->method('checkAccess')
739
            ->with($this->equalTo('batchDelete'))
740
            ->will($this->throwException(new AccessDeniedException()));
741
742
        $this->controller->batchActionDelete($this->createMock('Sonata\AdminBundle\Datagrid\ProxyQueryInterface'));
743
    }
744
745
    public function testBatchActionDelete()
746
    {
747
        $modelManager = $this->createMock('Sonata\AdminBundle\Model\ModelManagerInterface');
748
749
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
805
            ->method('getModelManager')
806
            ->will($this->returnValue($modelManager));
807
808
        $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...
809
            ->method('isDebug')
810
            ->will($this->returnValue(true));
811
812
        $this->controller->batchActionDelete($this->createMock('Sonata\AdminBundle\Datagrid\ProxyQueryInterface'));
813
    }
814
815
    public function testShowActionNotFoundException()
816
    {
817
        $this->expectException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException');
818
819
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
820
            ->method('getObject')
821
            ->will($this->returnValue(false));
822
823
        $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...
824
    }
825
826
    public function testShowActionAccessDenied()
827
    {
828
        $this->expectException('Symfony\Component\Security\Core\Exception\AccessDeniedException');
829
830
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
873
            ->method('checkAccess')
874
            ->with($this->equalTo('show'))
875
            ->will($this->returnValue(true));
876
877
        $show = $this->createMock('Sonata\AdminBundle\Admin\FieldDescriptionCollection');
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('getShow')
881
            ->will($this->returnValue($show));
882
883
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $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...
884
885
        $this->assertSame($this->admin, $this->parameters['admin']);
886
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
887
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
888
889
        $this->assertSame('show', $this->parameters['action']);
890
        $this->assertInstanceOf('Sonata\AdminBundle\Admin\FieldDescriptionCollection', $this->parameters['elements']);
891
        $this->assertSame($object, $this->parameters['object']);
892
893
        $this->assertSame([], $this->session->getFlashBag()->all());
894
        $this->assertSame('SonataAdminBundle:CRUD:show.html.twig', $this->template);
895
    }
896
897
    /**
898
     * @dataProvider getRedirectToTests
899
     */
900
    public function testRedirectTo($expected, $route, $queryParams, $hasActiveSubclass)
901
    {
902
        $this->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...
903
            ->method('hasActiveSubclass')
904
            ->will($this->returnValue($hasActiveSubclass));
905
906
        $object = new \stdClass();
907
908
        foreach ($queryParams as $key => $value) {
909
            $this->request->query->set($key, $value);
910
        }
911
912
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
913
            ->method('hasRoute')
914
            ->with($this->equalTo($route))
915
            ->will($this->returnValue(true));
916
917
        $this->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...
918
            ->method('hasAccess')
919
            ->with($this->equalTo($route))
920
            ->will($this->returnValue(true));
921
922
        $response = $this->protectedTestedMethods['redirectTo']->invoke($this->controller, $object, $this->request);
923
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response);
924
        $this->assertSame($expected, $response->getTargetUrl());
925
    }
926
927
    public function testRedirectToWithObject()
928
    {
929
        $this->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...
930
            ->method('hasActiveSubclass')
931
            ->will($this->returnValue(false));
932
933
        $object = new \stdClass();
934
935
        $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...
936
            ->method('hasRoute')
937
            ->with($this->equalTo('edit'))
938
            ->will($this->returnValue(true));
939
940
        $this->admin->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
941
            ->method('hasAccess')
942
            ->with($this->equalTo('edit'), $object)
943
            ->will($this->returnValue(false));
944
945
        $response = $this->protectedTestedMethods['redirectTo']->invoke($this->controller, $object, $this->request);
946
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response);
947
        $this->assertSame('list', $response->getTargetUrl());
948
    }
949
950
    public function getRedirectToTests()
951
    {
952
        return [
953
            ['stdClass_edit', 'edit', [], false],
954
            ['list', 'list', ['btn_update_and_list' => true], false],
955
            ['list', 'list', ['btn_create_and_list' => true], false],
956
            ['create', 'create', ['btn_create_and_create' => true], false],
957
            ['create?subclass=foo', 'create', ['btn_create_and_create' => true, 'subclass' => 'foo'], true],
958
        ];
959
    }
960
961
    public function testDeleteActionNotFoundException()
962
    {
963
        $this->expectException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException');
964
965
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
966
            ->method('getObject')
967
            ->will($this->returnValue(false));
968
969
        $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...
970
    }
971
972
    public function testDeleteActionAccessDenied()
973
    {
974
        $this->expectException('Symfony\Component\Security\Core\Exception\AccessDeniedException');
975
976
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
1155
            ->method('getObject')
1156
            ->will($this->returnValue($object));
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('checkAccess')
1160
            ->with($this->equalTo('delete'))
1161
            ->will($this->returnValue(true));
1162
1163
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
1378
            ->method('getObject')
1379
            ->will($this->returnValue(false));
1380
1381
        $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...
1382
    }
1383
1384
    public function testEditActionAccessDenied()
1385
    {
1386
        $this->expectException('Symfony\Component\Security\Core\Exception\AccessDeniedException');
1387
1388
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1393
            ->method('checkAccess')
1394
            ->with($this->equalTo('edit'))
1395
            ->will($this->throwException(new AccessDeniedException()));
1396
1397
        $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...
1398
    }
1399
1400
    public function testPreEdit()
1401
    {
1402
        $object = new \stdClass();
1403
        $object->foo = 123456;
1404
1405
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1410
            ->method('checkAccess')
1411
            ->with($this->equalTo('edit'))
1412
            ->will($this->returnValue(true));
1413
1414
        $controller = new PreCRUDController();
1415
        $controller->setContainer($this->container);
1416
1417
        $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...
1418
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
1419
        $this->assertSame('preEdit called: 123456', $response->getContent());
1420
    }
1421
1422
    public function testEditAction()
1423
    {
1424
        $object = new \stdClass();
1425
1426
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1431
            ->method('checkAccess')
1432
            ->with($this->equalTo('edit'))
1433
            ->will($this->returnValue(true));
1434
1435
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')
1436
            ->disableOriginalConstructor()
1437
            ->getMock();
1438
1439
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1440
            ->method('getForm')
1441
            ->will($this->returnValue($form));
1442
1443
        $formView = $this->createMock('Symfony\Component\Form\FormView');
1444
1445
        $form->expects($this->any())
1446
            ->method('createView')
1447
            ->will($this->returnValue($formView));
1448
1449
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\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...
1450
1451
        $this->assertSame($this->admin, $this->parameters['admin']);
1452
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
1453
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1454
1455
        $this->assertSame('edit', $this->parameters['action']);
1456
        $this->assertInstanceOf('Symfony\Component\Form\FormView', $this->parameters['form']);
1457
        $this->assertSame($object, $this->parameters['object']);
1458
        $this->assertSame([], $this->session->getFlashBag()->all());
1459
        $this->assertSame('SonataAdminBundle:CRUD:edit.html.twig', $this->template);
1460
    }
1461
1462
    /**
1463
     * @dataProvider getToStringValues
1464
     */
1465
    public function testEditActionSuccess($expectedToStringValue, $toStringValue)
1466
    {
1467
        $object = new \stdClass();
1468
1469
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
1487
            ->method('hasAccess')
1488
            ->with($this->equalTo('edit'))
1489
            ->will($this->returnValue(true));
1490
1491
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')
1492
            ->disableOriginalConstructor()
1493
            ->getMock();
1494
1495
        $form->expects($this->once())
1496
            ->method('getData')
1497
            ->will($this->returnValue($object));
1498
1499
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1500
            ->method('getForm')
1501
            ->will($this->returnValue($form));
1502
1503
        $form->expects($this->once())
1504
            ->method('isSubmitted')
1505
            ->will($this->returnValue(true));
1506
1507
        $form->expects($this->once())
1508
            ->method('isValid')
1509
            ->will($this->returnValue(true));
1510
1511
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1512
            ->method('toString')
1513
            ->with($this->equalTo($object))
1514
            ->will($this->returnValue($toStringValue));
1515
1516
        $this->expectTranslate('flash_edit_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1517
1518
        $this->request->setMethod('POST');
1519
1520
        $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...
1521
1522
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response);
1523
        $this->assertSame(['flash_edit_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
1524
        $this->assertSame('stdClass_edit', $response->getTargetUrl());
1525
    }
1526
1527
    /**
1528
     * @dataProvider getToStringValues
1529
     */
1530
    public function testEditActionError($expectedToStringValue, $toStringValue)
1531
    {
1532
        $object = new \stdClass();
1533
1534
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1539
            ->method('checkAccess')
1540
            ->with($this->equalTo('edit'))
1541
            ->will($this->returnValue(true));
1542
1543
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')
1544
            ->disableOriginalConstructor()
1545
            ->getMock();
1546
1547
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1548
            ->method('getForm')
1549
            ->will($this->returnValue($form));
1550
1551
        $form->expects($this->once())
1552
            ->method('isSubmitted')
1553
            ->will($this->returnValue(true));
1554
1555
        $form->expects($this->once())
1556
            ->method('isValid')
1557
            ->will($this->returnValue(false));
1558
1559
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1560
            ->method('toString')
1561
            ->with($this->equalTo($object))
1562
            ->will($this->returnValue($toStringValue));
1563
1564
        $this->expectTranslate('flash_edit_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1565
1566
        $this->request->setMethod('POST');
1567
1568
        $formView = $this->createMock('Symfony\Component\Form\FormView');
1569
1570
        $form->expects($this->any())
1571
            ->method('createView')
1572
            ->will($this->returnValue($formView));
1573
1574
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\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...
1575
1576
        $this->assertSame($this->admin, $this->parameters['admin']);
1577
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
1578
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1579
1580
        $this->assertSame('edit', $this->parameters['action']);
1581
        $this->assertInstanceOf('Symfony\Component\Form\FormView', $this->parameters['form']);
1582
        $this->assertSame($object, $this->parameters['object']);
1583
1584
        $this->assertSame(['sonata_flash_error' => ['flash_edit_error']], $this->session->getFlashBag()->all());
1585
        $this->assertSame('SonataAdminBundle:CRUD:edit.html.twig', $this->template);
1586
    }
1587
1588
    public function testEditActionAjaxSuccess()
1589
    {
1590
        $object = new \stdClass();
1591
1592
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

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

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

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

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

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

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

Loading history...
1610
            ->method('getForm')
1611
            ->will($this->returnValue($form));
1612
1613
        $form->expects($this->once())
1614
            ->method('isSubmitted')
1615
            ->will($this->returnValue(true));
1616
1617
        $form->expects($this->once())
1618
            ->method('isValid')
1619
            ->will($this->returnValue(true));
1620
1621
        $form->expects($this->once())
1622
            ->method('getData')
1623
            ->will($this->returnValue($object));
1624
1625
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1631
            ->method('toString')
1632
            ->will($this->returnValue('foo'));
1633
1634
        $this->request->setMethod('POST');
1635
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1636
1637
        $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...
1638
1639
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
1640
        $this->assertSame(json_encode(['result' => 'ok', 'objectId' => 'foo_normalized', 'objectName' => 'foo']), $response->getContent());
1641
        $this->assertSame([], $this->session->getFlashBag()->all());
1642
    }
1643
1644
    public function testEditActionAjaxError()
1645
    {
1646
        $object = new \stdClass();
1647
1648
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1649
            ->method('getObject')
1650
            ->will($this->returnValue($object));
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('checkAccess')
1654
            ->with($this->equalTo('edit'))
1655
            ->will($this->returnValue(true));
1656
1657
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')
1658
            ->disableOriginalConstructor()
1659
            ->getMock();
1660
1661
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1662
            ->method('getForm')
1663
            ->will($this->returnValue($form));
1664
1665
        $form->expects($this->once())
1666
            ->method('isSubmitted')
1667
            ->will($this->returnValue(true));
1668
1669
        $form->expects($this->once())
1670
            ->method('isValid')
1671
            ->will($this->returnValue(false));
1672
1673
        $this->request->setMethod('POST');
1674
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
1675
1676
        $formView = $this->createMock('Symfony\Component\Form\FormView');
1677
1678
        $form->expects($this->any())
1679
            ->method('createView')
1680
            ->will($this->returnValue($formView));
1681
1682
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\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...
1683
1684
        $this->assertSame($this->admin, $this->parameters['admin']);
1685
        $this->assertSame('SonataAdminBundle::ajax_layout.html.twig', $this->parameters['base_template']);
1686
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1687
1688
        $this->assertSame('edit', $this->parameters['action']);
1689
        $this->assertInstanceOf('Symfony\Component\Form\FormView', $this->parameters['form']);
1690
        $this->assertSame($object, $this->parameters['object']);
1691
1692
        $this->assertSame([], $this->session->getFlashBag()->all());
1693
        $this->assertSame('SonataAdminBundle:CRUD:edit.html.twig', $this->template);
1694
    }
1695
1696
    /**
1697
     * @dataProvider getToStringValues
1698
     */
1699
    public function testEditActionWithModelManagerException($expectedToStringValue, $toStringValue)
1700
    {
1701
        $object = new \stdClass();
1702
1703
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
1708
            ->method('checkAccess')
1709
            ->with($this->equalTo('edit'))
1710
            ->will($this->returnValue(true));
1711
1712
        $this->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...
1713
            ->method('getClass')
1714
            ->will($this->returnValue('stdClass'));
1715
1716
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')
1717
            ->disableOriginalConstructor()
1718
            ->getMock();
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('getForm')
1722
            ->will($this->returnValue($form));
1723
1724
        $form->expects($this->once())
1725
            ->method('isValid')
1726
            ->will($this->returnValue(true));
1727
1728
        $form->expects($this->once())
1729
            ->method('getData')
1730
            ->will($this->returnValue($object));
1731
1732
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1733
            ->method('toString')
1734
            ->with($this->equalTo($object))
1735
            ->will($this->returnValue($toStringValue));
1736
1737
        $this->expectTranslate('flash_edit_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
1738
1739
        $form->expects($this->once())
1740
            ->method('isSubmitted')
1741
            ->will($this->returnValue(true));
1742
        $this->request->setMethod('POST');
1743
1744
        $formView = $this->createMock('Symfony\Component\Form\FormView');
1745
1746
        $form->expects($this->any())
1747
            ->method('createView')
1748
            ->will($this->returnValue($formView));
1749
1750
        $this->assertLoggerLogsModelManagerException($this->admin, 'update');
1751
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\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...
1752
1753
        $this->assertSame($this->admin, $this->parameters['admin']);
1754
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
1755
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1756
1757
        $this->assertSame('edit', $this->parameters['action']);
1758
        $this->assertInstanceOf('Symfony\Component\Form\FormView', $this->parameters['form']);
1759
        $this->assertSame($object, $this->parameters['object']);
1760
1761
        $this->assertSame(['sonata_flash_error' => ['flash_edit_error']], $this->session->getFlashBag()->all());
1762
        $this->assertSame('SonataAdminBundle:CRUD:edit.html.twig', $this->template);
1763
    }
1764
1765
    public function testEditActionWithPreview()
1766
    {
1767
        $object = new \stdClass();
1768
1769
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

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

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

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

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

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

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

Loading history...
1787
            ->method('supportsPreviewMode')
1788
            ->will($this->returnValue(true));
1789
1790
        $formView = $this->createMock('Symfony\Component\Form\FormView');
1791
1792
        $form->expects($this->any())
1793
            ->method('createView')
1794
            ->will($this->returnValue($formView));
1795
1796
        $form->expects($this->once())
1797
            ->method('isSubmitted')
1798
            ->will($this->returnValue(true));
1799
1800
        $form->expects($this->once())
1801
            ->method('isValid')
1802
            ->will($this->returnValue(true));
1803
1804
        $this->request->setMethod('POST');
1805
        $this->request->request->set('btn_preview', 'Preview');
1806
1807
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\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...
1808
1809
        $this->assertSame($this->admin, $this->parameters['admin']);
1810
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
1811
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1812
1813
        $this->assertSame('edit', $this->parameters['action']);
1814
        $this->assertInstanceOf('Symfony\Component\Form\FormView', $this->parameters['form']);
1815
        $this->assertSame($object, $this->parameters['object']);
1816
1817
        $this->assertSame([], $this->session->getFlashBag()->all());
1818
        $this->assertSame('SonataAdminBundle:CRUD:preview.html.twig', $this->template);
1819
    }
1820
1821
    public function testEditActionWithLockException()
1822
    {
1823
        $object = new \stdClass();
1824
        $class = get_class($object);
1825
1826
        $this->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...
1827
            ->method('getObject')
1828
            ->will($this->returnValue($object));
1829
1830
        $this->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...
1831
            ->method('checkAccess')
1832
            ->with($this->equalTo('edit'))
1833
            ->will($this->returnValue(true));
1834
1835
        $this->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...
1836
            ->method('getClass')
1837
            ->will($this->returnValue($class));
1838
1839
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')
1840
            ->disableOriginalConstructor()
1841
            ->getMock();
1842
1843
        $form->expects($this->any())
1844
            ->method('isValid')
1845
            ->will($this->returnValue(true));
1846
1847
        $form->expects($this->once())
1848
            ->method('getData')
1849
            ->will($this->returnValue($object));
1850
1851
        $this->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...
1852
            ->method('getForm')
1853
            ->will($this->returnValue($form));
1854
1855
        $form->expects($this->any())
1856
            ->method('isSubmitted')
1857
            ->will($this->returnValue(true));
1858
        $this->request->setMethod('POST');
1859
1860
        $this->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...
1861
            ->method('update')
1862
            ->will($this->throwException(new LockException()));
1863
1864
        $this->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...
1865
            ->method('toString')
1866
            ->with($this->equalTo($object))
1867
            ->will($this->returnValue($class));
1868
1869
        $formView = $this->createMock('Symfony\Component\Form\FormView');
1870
1871
        $form->expects($this->any())
1872
            ->method('createView')
1873
            ->will($this->returnValue($formView));
1874
1875
        $this->expectTranslate('flash_lock_error', [
1876
            '%name%' => $class,
1877
            '%link_start%' => '<a href="stdClass_edit">',
1878
            '%link_end%' => '</a>',
1879
        ], 'SonataAdminBundle');
1880
1881
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\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...
1882
    }
1883
1884
    public function testCreateActionAccessDenied()
1885
    {
1886
        $this->expectException('Symfony\Component\Security\Core\Exception\AccessDeniedException');
1887
1888
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1889
            ->method('checkAccess')
1890
            ->with($this->equalTo('create'))
1891
            ->will($this->throwException(new AccessDeniedException()));
1892
1893
        $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...
1894
    }
1895
1896
    public function testPreCreate()
1897
    {
1898
        $object = new \stdClass();
1899
        $object->foo = 123456;
1900
1901
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1902
            ->method('checkAccess')
1903
            ->with($this->equalTo('create'))
1904
            ->will($this->returnValue(true));
1905
1906
        $this->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...
1907
            ->method('getClass')
1908
            ->will($this->returnValue('stdClass'));
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('getNewInstance')
1912
            ->will($this->returnValue($object));
1913
1914
        $controller = new PreCRUDController();
1915
        $controller->setContainer($this->container);
1916
1917
        $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...
1918
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
1919
        $this->assertSame('preCreate called: 123456', $response->getContent());
1920
    }
1921
1922
    public function testCreateAction()
1923
    {
1924
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1925
            ->method('checkAccess')
1926
            ->with($this->equalTo('create'))
1927
            ->will($this->returnValue(true));
1928
1929
        $object = new \stdClass();
1930
1931
        $this->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...
1932
            ->method('getClass')
1933
            ->will($this->returnValue('stdClass'));
1934
1935
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1936
            ->method('getNewInstance')
1937
            ->will($this->returnValue($object));
1938
1939
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')
1940
            ->disableOriginalConstructor()
1941
            ->getMock();
1942
1943
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
1944
            ->method('getForm')
1945
            ->will($this->returnValue($form));
1946
1947
        $formView = $this->createMock('Symfony\Component\Form\FormView');
1948
1949
        $form->expects($this->any())
1950
            ->method('createView')
1951
            ->will($this->returnValue($formView));
1952
1953
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\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...
1954
1955
        $this->assertSame($this->admin, $this->parameters['admin']);
1956
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
1957
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
1958
1959
        $this->assertSame('create', $this->parameters['action']);
1960
        $this->assertInstanceOf('Symfony\Component\Form\FormView', $this->parameters['form']);
1961
        $this->assertSame($object, $this->parameters['object']);
1962
1963
        $this->assertSame([], $this->session->getFlashBag()->all());
1964
        $this->assertSame('SonataAdminBundle:CRUD:edit.html.twig', $this->template);
1965
    }
1966
1967
    /**
1968
     * @dataProvider getToStringValues
1969
     */
1970
    public function testCreateActionSuccess($expectedToStringValue, $toStringValue)
1971
    {
1972
        $object = new \stdClass();
1973
1974
        $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...
1975
            ->method('checkAccess')
1976
            ->will($this->returnCallback(function ($name, $objectIn = null) use ($object) {
1977
                if ('edit' == $name) {
1978
                    return true;
1979
                }
1980
1981
                if ('create' != $name) {
1982
                    return false;
1983
                }
1984
1985
                if (null === $objectIn) {
1986
                    return true;
1987
                }
1988
1989
                return $objectIn === $object;
1990
            }));
1991
1992
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

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

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

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

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

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

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

Loading history...
2007
            ->method('create')
2008
            ->will($this->returnArgument(0));
2009
2010
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')
2011
            ->disableOriginalConstructor()
2012
            ->getMock();
2013
2014
        $this->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...
2015
            ->method('getClass')
2016
            ->will($this->returnValue('stdClass'));
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('getForm')
2020
            ->will($this->returnValue($form));
2021
2022
        $form->expects($this->once())
2023
            ->method('isSubmitted')
2024
            ->will($this->returnValue(true));
2025
2026
        $form->expects($this->once())
2027
            ->method('isValid')
2028
            ->will($this->returnValue(true));
2029
2030
        $form->expects($this->once())
2031
            ->method('getData')
2032
            ->will($this->returnValue($object));
2033
2034
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2035
            ->method('toString')
2036
            ->with($this->equalTo($object))
2037
            ->will($this->returnValue($toStringValue));
2038
2039
        $this->expectTranslate('flash_create_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
2040
2041
        $this->request->setMethod('POST');
2042
2043
        $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...
2044
2045
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response);
2046
        $this->assertSame(['flash_create_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
2047
        $this->assertSame('stdClass_edit', $response->getTargetUrl());
2048
    }
2049
2050
    public function testCreateActionAccessDenied2()
2051
    {
2052
        $this->expectException('Symfony\Component\Security\Core\Exception\AccessDeniedException');
2053
2054
        $object = new \stdClass();
2055
2056
        $this->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...
2057
            ->method('checkAccess')
2058
            ->will($this->returnCallback(function ($name, $object = null) {
2059
                if ('create' != $name) {
2060
                    throw new AccessDeniedException();
2061
                }
2062
                if (null === $object) {
2063
                    return true;
2064
                }
2065
2066
                throw new AccessDeniedException();
2067
            }));
2068
2069
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2070
            ->method('getNewInstance')
2071
            ->will($this->returnValue($object));
2072
2073
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')
2074
            ->disableOriginalConstructor()
2075
            ->getMock();
2076
2077
        $this->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...
2078
            ->method('getClass')
2079
            ->will($this->returnValue('stdClass'));
2080
2081
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2082
            ->method('getForm')
2083
            ->will($this->returnValue($form));
2084
2085
        $form->expects($this->once())
2086
            ->method('isSubmitted')
2087
            ->will($this->returnValue(true));
2088
2089
        $form->expects($this->once())
2090
            ->method('getData')
2091
            ->will($this->returnValue($object));
2092
2093
        $form->expects($this->once())
2094
            ->method('isValid')
2095
            ->will($this->returnValue(true));
2096
2097
        $this->request->setMethod('POST');
2098
2099
        $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...
2100
    }
2101
2102
    /**
2103
     * @dataProvider getToStringValues
2104
     */
2105
    public function testCreateActionError($expectedToStringValue, $toStringValue)
2106
    {
2107
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2108
            ->method('checkAccess')
2109
            ->with($this->equalTo('create'))
2110
            ->will($this->returnValue(true));
2111
2112
        $object = new \stdClass();
2113
2114
        $this->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...
2115
            ->method('getClass')
2116
            ->will($this->returnValue('stdClass'));
2117
2118
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2119
            ->method('getNewInstance')
2120
            ->will($this->returnValue($object));
2121
2122
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')
2123
            ->disableOriginalConstructor()
2124
            ->getMock();
2125
2126
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2127
            ->method('getForm')
2128
            ->will($this->returnValue($form));
2129
2130
        $form->expects($this->once())
2131
            ->method('isSubmitted')
2132
            ->will($this->returnValue(true));
2133
2134
        $form->expects($this->once())
2135
            ->method('isValid')
2136
            ->will($this->returnValue(false));
2137
2138
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2139
            ->method('toString')
2140
            ->with($this->equalTo($object))
2141
            ->will($this->returnValue($toStringValue));
2142
2143
        $this->expectTranslate('flash_create_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
2144
2145
        $this->request->setMethod('POST');
2146
2147
        $formView = $this->createMock('Symfony\Component\Form\FormView');
2148
2149
        $form->expects($this->any())
2150
            ->method('createView')
2151
            ->will($this->returnValue($formView));
2152
2153
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\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...
2154
2155
        $this->assertSame($this->admin, $this->parameters['admin']);
2156
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
2157
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2158
2159
        $this->assertSame('create', $this->parameters['action']);
2160
        $this->assertInstanceOf('Symfony\Component\Form\FormView', $this->parameters['form']);
2161
        $this->assertSame($object, $this->parameters['object']);
2162
2163
        $this->assertSame(['sonata_flash_error' => ['flash_create_error']], $this->session->getFlashBag()->all());
2164
        $this->assertSame('SonataAdminBundle:CRUD:edit.html.twig', $this->template);
2165
    }
2166
2167
    /**
2168
     * @dataProvider getToStringValues
2169
     */
2170
    public function testCreateActionWithModelManagerException($expectedToStringValue, $toStringValue)
2171
    {
2172
        $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...
2173
            ->method('checkAccess')
2174
            ->with($this->equalTo('create'))
2175
            ->will($this->returnValue(true));
2176
2177
        $this->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...
2178
            ->method('getClass')
2179
            ->will($this->returnValue('stdClass'));
2180
2181
        $object = new \stdClass();
2182
2183
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2184
            ->method('getNewInstance')
2185
            ->will($this->returnValue($object));
2186
2187
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')
2188
            ->disableOriginalConstructor()
2189
            ->getMock();
2190
2191
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2192
            ->method('getForm')
2193
            ->will($this->returnValue($form));
2194
2195
        $form->expects($this->once())
2196
            ->method('isValid')
2197
            ->will($this->returnValue(true));
2198
2199
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2200
            ->method('toString')
2201
            ->with($this->equalTo($object))
2202
            ->will($this->returnValue($toStringValue));
2203
2204
        $this->expectTranslate('flash_create_error', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');
2205
2206
        $form->expects($this->once())
2207
            ->method('isSubmitted')
2208
            ->will($this->returnValue(true));
2209
2210
        $form->expects($this->once())
2211
            ->method('getData')
2212
            ->will($this->returnValue($object));
2213
2214
        $this->request->setMethod('POST');
2215
2216
        $formView = $this->createMock('Symfony\Component\Form\FormView');
2217
2218
        $form->expects($this->any())
2219
            ->method('createView')
2220
            ->will($this->returnValue($formView));
2221
2222
        $this->assertLoggerLogsModelManagerException($this->admin, 'create');
2223
2224
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\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...
2225
2226
        $this->assertSame($this->admin, $this->parameters['admin']);
2227
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
2228
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2229
2230
        $this->assertSame('create', $this->parameters['action']);
2231
        $this->assertInstanceOf('Symfony\Component\Form\FormView', $this->parameters['form']);
2232
        $this->assertSame($object, $this->parameters['object']);
2233
2234
        $this->assertSame(['sonata_flash_error' => ['flash_create_error']], $this->session->getFlashBag()->all());
2235
        $this->assertSame('SonataAdminBundle:CRUD:edit.html.twig', $this->template);
2236
    }
2237
2238
    public function testCreateActionAjaxSuccess()
2239
    {
2240
        $object = new \stdClass();
2241
2242
        $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...
2243
            ->method('checkAccess')
2244
            ->will($this->returnCallback(function ($name, $objectIn = null) use ($object) {
2245
                if ('create' != $name) {
2246
                    return false;
2247
                }
2248
2249
                if (null === $objectIn) {
2250
                    return true;
2251
                }
2252
2253
                return $objectIn === $object;
2254
            }));
2255
2256
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
2261
            ->method('create')
2262
            ->will($this->returnArgument(0));
2263
2264
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')
2265
            ->disableOriginalConstructor()
2266
            ->getMock();
2267
2268
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2269
            ->method('getForm')
2270
            ->will($this->returnValue($form));
2271
2272
        $form->expects($this->once())
2273
            ->method('isSubmitted')
2274
            ->will($this->returnValue(true));
2275
2276
        $form->expects($this->once())
2277
            ->method('isValid')
2278
            ->will($this->returnValue(true));
2279
2280
        $form->expects($this->once())
2281
            ->method('getData')
2282
            ->will($this->returnValue($object));
2283
2284
        $this->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...
2285
            ->method('getClass')
2286
            ->will($this->returnValue('stdClass'));
2287
2288
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2289
            ->method('getNormalizedIdentifier')
2290
            ->with($this->equalTo($object))
2291
            ->will($this->returnValue('foo_normalized'));
2292
2293
        $this->request->setMethod('POST');
2294
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
2295
2296
        $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...
2297
2298
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
2299
        $this->assertSame(json_encode(['result' => 'ok', 'objectId' => 'foo_normalized']), $response->getContent());
2300
        $this->assertSame([], $this->session->getFlashBag()->all());
2301
    }
2302
2303
    public function testCreateActionAjaxError()
2304
    {
2305
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2306
            ->method('checkAccess')
2307
            ->with($this->equalTo('create'))
2308
            ->will($this->returnValue(true));
2309
2310
        $object = new \stdClass();
2311
2312
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2313
            ->method('getNewInstance')
2314
            ->will($this->returnValue($object));
2315
2316
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')
2317
            ->disableOriginalConstructor()
2318
            ->getMock();
2319
2320
        $this->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...
2321
            ->method('getClass')
2322
            ->will($this->returnValue('stdClass'));
2323
2324
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2325
            ->method('getForm')
2326
            ->will($this->returnValue($form));
2327
2328
        $form->expects($this->once())
2329
            ->method('isSubmitted')
2330
            ->will($this->returnValue(true));
2331
2332
        $form->expects($this->once())
2333
            ->method('isValid')
2334
            ->will($this->returnValue(false));
2335
2336
        $this->request->setMethod('POST');
2337
        $this->request->headers->set('X-Requested-With', 'XMLHttpRequest');
2338
2339
        $formView = $this->createMock('Symfony\Component\Form\FormView');
2340
2341
        $form->expects($this->any())
2342
            ->method('createView')
2343
            ->will($this->returnValue($formView));
2344
2345
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\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...
2346
2347
        $this->assertSame($this->admin, $this->parameters['admin']);
2348
        $this->assertSame('SonataAdminBundle::ajax_layout.html.twig', $this->parameters['base_template']);
2349
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2350
2351
        $this->assertSame('create', $this->parameters['action']);
2352
        $this->assertInstanceOf('Symfony\Component\Form\FormView', $this->parameters['form']);
2353
        $this->assertSame($object, $this->parameters['object']);
2354
2355
        $this->assertSame([], $this->session->getFlashBag()->all());
2356
        $this->assertSame('SonataAdminBundle:CRUD:edit.html.twig', $this->template);
2357
    }
2358
2359
    public function testCreateActionWithPreview()
2360
    {
2361
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2362
            ->method('checkAccess')
2363
            ->with($this->equalTo('create'))
2364
            ->will($this->returnValue(true));
2365
2366
        $object = new \stdClass();
2367
2368
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2369
            ->method('getNewInstance')
2370
            ->will($this->returnValue($object));
2371
2372
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')
2373
            ->disableOriginalConstructor()
2374
            ->getMock();
2375
2376
        $this->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...
2377
            ->method('getClass')
2378
            ->will($this->returnValue('stdClass'));
2379
2380
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
2385
            ->method('supportsPreviewMode')
2386
            ->will($this->returnValue(true));
2387
2388
        $formView = $this->createMock('Symfony\Component\Form\FormView');
2389
2390
        $form->expects($this->any())
2391
            ->method('createView')
2392
            ->will($this->returnValue($formView));
2393
2394
        $form->expects($this->once())
2395
            ->method('isSubmitted')
2396
            ->will($this->returnValue(true));
2397
2398
        $form->expects($this->once())
2399
            ->method('isValid')
2400
            ->will($this->returnValue(true));
2401
2402
        $this->request->setMethod('POST');
2403
        $this->request->request->set('btn_preview', 'Preview');
2404
2405
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\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...
2406
2407
        $this->assertSame($this->admin, $this->parameters['admin']);
2408
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
2409
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2410
2411
        $this->assertSame('create', $this->parameters['action']);
2412
        $this->assertInstanceOf('Symfony\Component\Form\FormView', $this->parameters['form']);
2413
        $this->assertSame($object, $this->parameters['object']);
2414
2415
        $this->assertSame([], $this->session->getFlashBag()->all());
2416
        $this->assertSame('SonataAdminBundle:CRUD:preview.html.twig', $this->template);
2417
    }
2418
2419
    public function testExportActionAccessDenied()
2420
    {
2421
        $this->expectException('Symfony\Component\Security\Core\Exception\AccessDeniedException');
2422
2423
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2424
            ->method('checkAccess')
2425
            ->with($this->equalTo('export'))
2426
            ->will($this->throwException(new AccessDeniedException()));
2427
2428
        $this->controller->exportAction($this->request);
2429
    }
2430
2431
    public function testExportActionWrongFormat()
2432
    {
2433
        $this->expectException('RuntimeException', 'Export in format `csv` is not allowed for class: `Foo`. Allowed formats are: `json`');
2434
2435
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
2441
            ->method('getExportFormats')
2442
            ->will($this->returnValue(['json']));
2443
2444
        $this->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...
2445
            ->method('getClass')
2446
            ->will($this->returnValue('Foo'));
2447
2448
        $this->request->query->set('format', 'csv');
2449
2450
        $this->controller->exportAction($this->request);
2451
    }
2452
2453
    public function testExportAction()
2454
    {
2455
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2456
            ->method('checkAccess')
2457
            ->with($this->equalTo('export'))
2458
            ->will($this->returnValue(true));
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('getExportFormats')
2462
            ->will($this->returnValue(['json']));
2463
2464
        $dataSourceIterator = $this->createMock('Exporter\Source\SourceIteratorInterface');
2465
2466
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2467
            ->method('getDataSourceIterator')
2468
            ->will($this->returnValue($dataSourceIterator));
2469
2470
        $this->request->query->set('format', 'json');
2471
2472
        $response = $this->controller->exportAction($this->request);
2473
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response);
2474
        $this->assertSame(200, $response->getStatusCode());
2475
        $this->assertSame([], $this->session->getFlashBag()->all());
2476
    }
2477
2478
    public function testHistoryActionAccessDenied()
2479
    {
2480
        $this->expectException('Symfony\Component\Security\Core\Exception\AccessDeniedException');
2481
2482
        $this->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...
2483
            ->method('getObject')
2484
            ->will($this->returnValue(new \StdClass()));
2485
2486
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2487
            ->method('checkAccess')
2488
            ->with($this->equalTo('history'))
2489
            ->will($this->throwException(new AccessDeniedException()));
2490
2491
        $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...
2492
    }
2493
2494
    public function testHistoryActionNotFoundException()
2495
    {
2496
        $this->expectException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException');
2497
2498
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2499
            ->method('getObject')
2500
            ->will($this->returnValue(false));
2501
2502
        $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...
2503
    }
2504
2505
    public function testHistoryActionNoReader()
2506
    {
2507
        $this->expectException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException', 'unable to find the audit reader for class : Foo');
2508
2509
        $this->request->query->set('id', 123);
2510
2511
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2512
            ->method('checkAccess')
2513
            ->with($this->equalTo('history'))
2514
            ->will($this->returnValue(true));
2515
2516
        $object = new \stdClass();
2517
2518
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2519
            ->method('getObject')
2520
            ->will($this->returnValue($object));
2521
2522
        $this->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...
2523
            ->method('getClass')
2524
            ->will($this->returnValue('Foo'));
2525
2526
        $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...
2527
            ->method('hasReader')
2528
            ->with($this->equalTo('Foo'))
2529
            ->will($this->returnValue(false));
2530
2531
        $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...
2532
    }
2533
2534
    public function testHistoryAction()
2535
    {
2536
        $this->request->query->set('id', 123);
2537
2538
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
2546
            ->method('getObject')
2547
            ->will($this->returnValue($object));
2548
2549
        $this->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...
2550
            ->method('getClass')
2551
            ->will($this->returnValue('Foo'));
2552
2553
        $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...
2554
            ->method('hasReader')
2555
            ->with($this->equalTo('Foo'))
2556
            ->will($this->returnValue(true));
2557
2558
        $reader = $this->createMock('Sonata\AdminBundle\Model\AuditReaderInterface');
2559
2560
        $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...
2561
            ->method('getReader')
2562
            ->with($this->equalTo('Foo'))
2563
            ->will($this->returnValue($reader));
2564
2565
        $reader->expects($this->once())
2566
            ->method('findRevisions')
2567
            ->with($this->equalTo('Foo'), $this->equalTo(123))
2568
            ->will($this->returnValue([]));
2569
2570
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $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...
2571
2572
        $this->assertSame($this->admin, $this->parameters['admin']);
2573
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
2574
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2575
2576
        $this->assertSame('history', $this->parameters['action']);
2577
        $this->assertSame([], $this->parameters['revisions']);
2578
        $this->assertSame($object, $this->parameters['object']);
2579
2580
        $this->assertSame([], $this->session->getFlashBag()->all());
2581
        $this->assertSame('SonataAdminBundle:CRUD:history.html.twig', $this->template);
2582
    }
2583
2584
    public function testAclActionAclNotEnabled()
2585
    {
2586
        $this->expectException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException', 'ACL are not enabled for this admin');
2587
2588
        $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...
2589
    }
2590
2591
    public function testAclActionNotFoundException()
2592
    {
2593
        $this->expectException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException');
2594
2595
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2596
            ->method('isAclEnabled')
2597
            ->will($this->returnValue(true));
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('getObject')
2601
            ->will($this->returnValue(false));
2602
2603
        $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...
2604
    }
2605
2606
    public function testAclActionAccessDenied()
2607
    {
2608
        $this->expectException('Symfony\Component\Security\Core\Exception\AccessDeniedException');
2609
2610
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2611
            ->method('isAclEnabled')
2612
            ->will($this->returnValue(true));
2613
2614
        $object = new \stdClass();
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('getObject')
2618
            ->will($this->returnValue($object));
2619
2620
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('checkAccess')
2622
            ->with($this->equalTo('acl'), $this->equalTo($object))
2623
            ->will($this->throwException(new AccessDeniedException()));
2624
2625
        $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...
2626
    }
2627
2628
    public function testAclAction()
2629
    {
2630
        $this->request->query->set('id', 123);
2631
2632
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
2639
            ->method('getObject')
2640
            ->will($this->returnValue($object));
2641
2642
        $this->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...
2643
            ->method('checkAccess')
2644
            ->will($this->returnValue(true));
2645
2646
        $this->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...
2647
            ->method('getSecurityInformation')
2648
            ->will($this->returnValue([]));
2649
2650
        $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...
2651
            ->method('getMaskBuilderClass')
2652
            ->will($this->returnValue('\Sonata\AdminBundle\Security\Acl\Permission\AdminPermissionMap'));
2653
2654
        $aclUsersForm = $this->getMockBuilder('Symfony\Component\Form\Form')
2655
            ->disableOriginalConstructor()
2656
            ->getMock();
2657
2658
        $aclUsersForm->expects($this->once())
2659
            ->method('createView')
2660
            ->will($this->returnValue($this->createMock('Symfony\Component\Form\FormView')));
2661
2662
        $aclRolesForm = $this->getMockBuilder('Symfony\Component\Form\Form')
2663
            ->disableOriginalConstructor()
2664
            ->getMock();
2665
2666
        $aclRolesForm->expects($this->once())
2667
            ->method('createView')
2668
            ->will($this->returnValue($this->createMock('Symfony\Component\Form\FormView')));
2669
2670
        $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...
2671
            ->method('createAclUsersForm')
2672
            ->with($this->isInstanceOf('Sonata\AdminBundle\Util\AdminObjectAclData'))
2673
            ->will($this->returnValue($aclUsersForm));
2674
2675
        $this->adminObjectAclManipulator->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundl...inObjectAclManipulator>.

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

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

Loading history...
2676
            ->method('createAclRolesForm')
2677
            ->with($this->isInstanceOf('Sonata\AdminBundle\Util\AdminObjectAclData'))
2678
            ->will($this->returnValue($aclRolesForm));
2679
2680
        $aclSecurityHandler = $this->getMockBuilder('Sonata\AdminBundle\Security\Handler\AclSecurityHandler')
2681
            ->disableOriginalConstructor()
2682
            ->getMock();
2683
2684
        $aclSecurityHandler->expects($this->any())
2685
            ->method('getObjectPermissions')
2686
            ->will($this->returnValue([]));
2687
2688
        $this->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...
2689
            ->method('getSecurityHandler')
2690
            ->will($this->returnValue($aclSecurityHandler));
2691
2692
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\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...
2693
2694
        $this->assertSame($this->admin, $this->parameters['admin']);
2695
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
2696
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2697
2698
        $this->assertSame('acl', $this->parameters['action']);
2699
        $this->assertSame([], $this->parameters['permissions']);
2700
        $this->assertSame($object, $this->parameters['object']);
2701
        $this->assertInstanceOf('\ArrayIterator', $this->parameters['users']);
2702
        $this->assertInstanceOf('\ArrayIterator', $this->parameters['roles']);
2703
        $this->assertInstanceOf('Symfony\Component\Form\FormView', $this->parameters['aclUsersForm']);
2704
        $this->assertInstanceOf('Symfony\Component\Form\FormView', $this->parameters['aclRolesForm']);
2705
2706
        $this->assertSame([], $this->session->getFlashBag()->all());
2707
        $this->assertSame('SonataAdminBundle:CRUD:acl.html.twig', $this->template);
2708
    }
2709
2710
    public function testAclActionInvalidUpdate()
2711
    {
2712
        $this->request->query->set('id', 123);
2713
        $this->request->request->set(AdminObjectAclManipulator::ACL_USERS_FORM_NAME, []);
2714
2715
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2716
            ->method('isAclEnabled')
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('checkAccess')
2727
            ->will($this->returnValue(true));
2728
2729
        $this->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...
2730
            ->method('getSecurityInformation')
2731
            ->will($this->returnValue([]));
2732
2733
        $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...
2734
            ->method('getMaskBuilderClass')
2735
            ->will($this->returnValue('\Sonata\AdminBundle\Security\Acl\Permission\AdminPermissionMap'));
2736
2737
        $aclUsersForm = $this->getMockBuilder('Symfony\Component\Form\Form')
2738
            ->disableOriginalConstructor()
2739
            ->getMock();
2740
2741
        $aclUsersForm->expects($this->once())
2742
            ->method('isValid')
2743
            ->will($this->returnValue(false));
2744
2745
        $aclUsersForm->expects($this->once())
2746
            ->method('createView')
2747
            ->will($this->returnValue($this->createMock('Symfony\Component\Form\FormView')));
2748
2749
        $aclRolesForm = $this->getMockBuilder('Symfony\Component\Form\Form')
2750
            ->disableOriginalConstructor()
2751
            ->getMock();
2752
2753
        $aclRolesForm->expects($this->once())
2754
            ->method('createView')
2755
            ->will($this->returnValue($this->createMock('Symfony\Component\Form\FormView')));
2756
2757
        $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...
2758
            ->method('createAclUsersForm')
2759
            ->with($this->isInstanceOf('Sonata\AdminBundle\Util\AdminObjectAclData'))
2760
            ->will($this->returnValue($aclUsersForm));
2761
2762
        $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...
2763
            ->method('createAclRolesForm')
2764
            ->with($this->isInstanceOf('Sonata\AdminBundle\Util\AdminObjectAclData'))
2765
            ->will($this->returnValue($aclRolesForm));
2766
2767
        $aclSecurityHandler = $this->getMockBuilder('Sonata\AdminBundle\Security\Handler\AclSecurityHandler')
2768
            ->disableOriginalConstructor()
2769
            ->getMock();
2770
2771
        $aclSecurityHandler->expects($this->any())
2772
            ->method('getObjectPermissions')
2773
            ->will($this->returnValue([]));
2774
2775
        $this->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...
2776
            ->method('getSecurityHandler')
2777
            ->will($this->returnValue($aclSecurityHandler));
2778
2779
        $this->request->setMethod('POST');
2780
2781
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\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...
2782
2783
        $this->assertSame($this->admin, $this->parameters['admin']);
2784
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
2785
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
2786
2787
        $this->assertSame('acl', $this->parameters['action']);
2788
        $this->assertSame([], $this->parameters['permissions']);
2789
        $this->assertSame($object, $this->parameters['object']);
2790
        $this->assertInstanceOf('\ArrayIterator', $this->parameters['users']);
2791
        $this->assertInstanceOf('\ArrayIterator', $this->parameters['roles']);
2792
        $this->assertInstanceOf('Symfony\Component\Form\FormView', $this->parameters['aclUsersForm']);
2793
        $this->assertInstanceOf('Symfony\Component\Form\FormView', $this->parameters['aclRolesForm']);
2794
2795
        $this->assertSame([], $this->session->getFlashBag()->all());
2796
        $this->assertSame('SonataAdminBundle:CRUD:acl.html.twig', $this->template);
2797
    }
2798
2799
    public function testAclActionSuccessfulUpdate()
2800
    {
2801
        $this->request->query->set('id', 123);
2802
        $this->request->request->set(AdminObjectAclManipulator::ACL_ROLES_FORM_NAME, []);
2803
2804
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
2811
            ->method('getObject')
2812
            ->will($this->returnValue($object));
2813
2814
        $this->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...
2815
            ->method('checkAccess')
2816
            ->will($this->returnValue(true));
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('getSecurityInformation')
2820
            ->will($this->returnValue([]));
2821
2822
        $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...
2823
            ->method('getMaskBuilderClass')
2824
            ->will($this->returnValue('\Sonata\AdminBundle\Security\Acl\Permission\AdminPermissionMap'));
2825
2826
        $aclUsersForm = $this->getMockBuilder('Symfony\Component\Form\Form')
2827
            ->disableOriginalConstructor()
2828
            ->getMock();
2829
2830
        $aclUsersForm->expects($this->any())
2831
            ->method('createView')
2832
            ->will($this->returnValue($this->createMock('Symfony\Component\Form\FormView')));
2833
2834
        $aclRolesForm = $this->getMockBuilder('Symfony\Component\Form\Form')
2835
            ->disableOriginalConstructor()
2836
            ->getMock();
2837
2838
        $aclRolesForm->expects($this->any())
2839
            ->method('createView')
2840
            ->will($this->returnValue($this->createMock('Symfony\Component\Form\FormView')));
2841
2842
        $aclRolesForm->expects($this->once())
2843
            ->method('isValid')
2844
            ->will($this->returnValue(true));
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('Sonata\AdminBundle\Util\AdminObjectAclData'))
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('Sonata\AdminBundle\Util\AdminObjectAclData'))
2854
            ->will($this->returnValue($aclRolesForm));
2855
2856
        $aclSecurityHandler = $this->getMockBuilder('Sonata\AdminBundle\Security\Handler\AclSecurityHandler')
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->expectTranslate('flash_acl_edit_success', [], 'SonataAdminBundle');
2869
2870
        $this->request->setMethod('POST');
2871
2872
        $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...
2873
2874
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response);
2875
2876
        $this->assertSame(['flash_acl_edit_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
2877
        $this->assertSame('stdClass_acl', $response->getTargetUrl());
2878
    }
2879
2880
    public function testHistoryViewRevisionActionAccessDenied()
2881
    {
2882
        $this->expectException('Symfony\Component\Security\Core\Exception\AccessDeniedException');
2883
2884
        $this->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...
2885
            ->method('getObject')
2886
            ->will($this->returnValue(new \StdClass()));
2887
2888
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2889
            ->method('checkAccess')
2890
            ->with($this->equalTo('historyViewRevision'))
2891
            ->will($this->throwException(new AccessDeniedException()));
2892
2893
        $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...
2894
    }
2895
2896
    public function testHistoryViewRevisionActionNotFoundException()
2897
    {
2898
        $this->expectException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException', 'unable to find the object with id: 123');
2899
2900
        $this->request->query->set('id', 123);
2901
2902
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2903
            ->method('getObject')
2904
            ->will($this->returnValue(false));
2905
2906
        $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...
2907
    }
2908
2909
    public function testHistoryViewRevisionActionNoReader()
2910
    {
2911
        $this->expectException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException', 'unable to find the audit reader for class : Foo');
2912
2913
        $this->request->query->set('id', 123);
2914
2915
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2916
            ->method('checkAccess')
2917
            ->with($this->equalTo('historyViewRevision'))
2918
            ->will($this->returnValue(true));
2919
2920
        $object = new \stdClass();
2921
2922
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2923
            ->method('getObject')
2924
            ->will($this->returnValue($object));
2925
2926
        $this->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...
2927
            ->method('getClass')
2928
            ->will($this->returnValue('Foo'));
2929
2930
        $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...
2931
            ->method('hasReader')
2932
            ->with($this->equalTo('Foo'))
2933
            ->will($this->returnValue(false));
2934
2935
        $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...
2936
    }
2937
2938
    public function testHistoryViewRevisionActionNotFoundRevision()
2939
    {
2940
        $this->expectException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException', 'unable to find the targeted object `123` from the revision `456` with classname : `Foo`');
2941
2942
        $this->request->query->set('id', 123);
2943
2944
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getObject')
2953
            ->will($this->returnValue($object));
2954
2955
        $this->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...
2956
            ->method('getClass')
2957
            ->will($this->returnValue('Foo'));
2958
2959
        $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...
2960
            ->method('hasReader')
2961
            ->with($this->equalTo('Foo'))
2962
            ->will($this->returnValue(true));
2963
2964
        $reader = $this->createMock('Sonata\AdminBundle\Model\AuditReaderInterface');
2965
2966
        $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...
2967
            ->method('getReader')
2968
            ->with($this->equalTo('Foo'))
2969
            ->will($this->returnValue($reader));
2970
2971
        $reader->expects($this->once())
2972
            ->method('find')
2973
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
2974
            ->will($this->returnValue(null));
2975
2976
        $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...
2977
    }
2978
2979
    public function testHistoryViewRevisionAction()
2980
    {
2981
        $this->request->query->set('id', 123);
2982
2983
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
2984
            ->method('checkAccess')
2985
            ->with($this->equalTo('historyViewRevision'))
2986
            ->will($this->returnValue(true));
2987
2988
        $object = new \stdClass();
2989
2990
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself 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('getObject')
2992
            ->will($this->returnValue($object));
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('getClass')
2996
            ->will($this->returnValue('Foo'));
2997
2998
        $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...
2999
            ->method('hasReader')
3000
            ->with($this->equalTo('Foo'))
3001
            ->will($this->returnValue(true));
3002
3003
        $reader = $this->createMock('Sonata\AdminBundle\Model\AuditReaderInterface');
3004
3005
        $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...
3006
            ->method('getReader')
3007
            ->with($this->equalTo('Foo'))
3008
            ->will($this->returnValue($reader));
3009
3010
        $objectRevision = new \stdClass();
3011
        $objectRevision->revision = 456;
3012
3013
        $reader->expects($this->once())
3014
            ->method('find')
3015
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3016
            ->will($this->returnValue($objectRevision));
3017
3018
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3019
            ->method('setSubject')
3020
            ->with($this->equalTo($objectRevision))
3021
            ->will($this->returnValue(null));
3022
3023
        $fieldDescriptionCollection = new FieldDescriptionCollection();
3024
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3025
            ->method('getShow')
3026
            ->will($this->returnValue($fieldDescriptionCollection));
3027
3028
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $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...
3029
3030
        $this->assertSame($this->admin, $this->parameters['admin']);
3031
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
3032
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3033
3034
        $this->assertSame('show', $this->parameters['action']);
3035
        $this->assertSame($objectRevision, $this->parameters['object']);
3036
        $this->assertSame($fieldDescriptionCollection, $this->parameters['elements']);
3037
3038
        $this->assertSame([], $this->session->getFlashBag()->all());
3039
        $this->assertSame('SonataAdminBundle:CRUD:show.html.twig', $this->template);
3040
    }
3041
3042
    public function testHistoryCompareRevisionsActionAccessDenied()
3043
    {
3044
        $this->expectException('Symfony\Component\Security\Core\Exception\AccessDeniedException');
3045
3046
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3047
            ->method('checkAccess')
3048
            ->with($this->equalTo('historyCompareRevisions'))
3049
            ->will($this->throwException(new AccessDeniedException()));
3050
3051
        $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...
3052
    }
3053
3054
    public function testHistoryCompareRevisionsActionNotFoundException()
3055
    {
3056
        $this->expectException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException', 'unable to find the object with id: 123');
3057
3058
        $this->request->query->set('id', 123);
3059
3060
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

Loading history...
3066
            ->method('getObject')
3067
            ->will($this->returnValue(false));
3068
3069
        $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...
3070
    }
3071
3072
    public function testHistoryCompareRevisionsActionNoReader()
3073
    {
3074
        $this->expectException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException', 'unable to find the audit reader for class : Foo');
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('checkAccess')
3080
            ->with($this->equalTo('historyCompareRevisions'))
3081
            ->will($this->returnValue(true));
3082
3083
        $object = new \stdClass();
3084
3085
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3086
            ->method('getObject')
3087
            ->will($this->returnValue($object));
3088
3089
        $this->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...
3090
            ->method('getClass')
3091
            ->will($this->returnValue('Foo'));
3092
3093
        $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...
3094
            ->method('hasReader')
3095
            ->with($this->equalTo('Foo'))
3096
            ->will($this->returnValue(false));
3097
3098
        $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...
3099
    }
3100
3101
    public function testHistoryCompareRevisionsActionNotFoundBaseRevision()
3102
    {
3103
        $this->expectException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException', 'unable to find the targeted object `123` from the revision `456` with classname : `Foo`');
3104
3105
        $this->request->query->set('id', 123);
3106
3107
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
3115
            ->method('getObject')
3116
            ->will($this->returnValue($object));
3117
3118
        $this->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...
3119
            ->method('getClass')
3120
            ->will($this->returnValue('Foo'));
3121
3122
        $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...
3123
            ->method('hasReader')
3124
            ->with($this->equalTo('Foo'))
3125
            ->will($this->returnValue(true));
3126
3127
        $reader = $this->createMock('Sonata\AdminBundle\Model\AuditReaderInterface');
3128
3129
        $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...
3130
            ->method('getReader')
3131
            ->with($this->equalTo('Foo'))
3132
            ->will($this->returnValue($reader));
3133
3134
        // once because it will not be found and therefore the second call won't be executed
3135
        $reader->expects($this->once())
3136
            ->method('find')
3137
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3138
            ->will($this->returnValue(null));
3139
3140
        $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...
3141
    }
3142
3143
    public function testHistoryCompareRevisionsActionNotFoundCompareRevision()
3144
    {
3145
        $this->expectException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException', 'unable to find the targeted object `123` from the revision `789` with classname : `Foo`');
3146
3147
        $this->request->query->set('id', 123);
3148
3149
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3150
            ->method('checkAccess')
3151
            ->with($this->equalTo('historyCompareRevisions'))
3152
            ->will($this->returnValue(true));
3153
3154
        $object = new \stdClass();
3155
3156
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3157
            ->method('getObject')
3158
            ->will($this->returnValue($object));
3159
3160
        $this->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...
3161
            ->method('getClass')
3162
            ->will($this->returnValue('Foo'));
3163
3164
        $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...
3165
            ->method('hasReader')
3166
            ->with($this->equalTo('Foo'))
3167
            ->will($this->returnValue(true));
3168
3169
        $reader = $this->createMock('Sonata\AdminBundle\Model\AuditReaderInterface');
3170
3171
        $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...
3172
            ->method('getReader')
3173
            ->with($this->equalTo('Foo'))
3174
            ->will($this->returnValue($reader));
3175
3176
        $objectRevision = new \stdClass();
3177
        $objectRevision->revision = 456;
3178
3179
        // first call should return, so the second call will throw an exception
3180
        $reader->expects($this->at(0))
3181
            ->method('find')
3182
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3183
            ->will($this->returnValue($objectRevision));
3184
3185
        $reader->expects($this->at(1))
3186
            ->method('find')
3187
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(789))
3188
            ->will($this->returnValue(null));
3189
3190
        $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...
3191
    }
3192
3193
    public function testHistoryCompareRevisionsActionAction()
3194
    {
3195
        $this->request->query->set('id', 123);
3196
3197
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3198
            ->method('checkAccess')
3199
            ->with($this->equalTo('historyCompareRevisions'))
3200
            ->will($this->returnValue(true));
3201
3202
        $object = new \stdClass();
3203
3204
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3205
            ->method('getObject')
3206
            ->will($this->returnValue($object));
3207
3208
        $this->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...
3209
            ->method('getClass')
3210
            ->will($this->returnValue('Foo'));
3211
3212
        $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...
3213
            ->method('hasReader')
3214
            ->with($this->equalTo('Foo'))
3215
            ->will($this->returnValue(true));
3216
3217
        $reader = $this->createMock('Sonata\AdminBundle\Model\AuditReaderInterface');
3218
3219
        $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...
3220
            ->method('getReader')
3221
            ->with($this->equalTo('Foo'))
3222
            ->will($this->returnValue($reader));
3223
3224
        $objectRevision = new \stdClass();
3225
        $objectRevision->revision = 456;
3226
3227
        $compareObjectRevision = new \stdClass();
3228
        $compareObjectRevision->revision = 789;
3229
3230
        $reader->expects($this->at(0))
3231
            ->method('find')
3232
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(456))
3233
            ->will($this->returnValue($objectRevision));
3234
3235
        $reader->expects($this->at(1))
3236
            ->method('find')
3237
            ->with($this->equalTo('Foo'), $this->equalTo(123), $this->equalTo(789))
3238
            ->will($this->returnValue($compareObjectRevision));
3239
3240
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3241
            ->method('setSubject')
3242
            ->with($this->equalTo($objectRevision))
3243
            ->will($this->returnValue(null));
3244
3245
        $fieldDescriptionCollection = new FieldDescriptionCollection();
3246
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3247
            ->method('getShow')
3248
            ->will($this->returnValue($fieldDescriptionCollection));
3249
3250
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $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...
3251
3252
        $this->assertSame($this->admin, $this->parameters['admin']);
3253
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
3254
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3255
3256
        $this->assertSame('show', $this->parameters['action']);
3257
        $this->assertSame($objectRevision, $this->parameters['object']);
3258
        $this->assertSame($compareObjectRevision, $this->parameters['object_compare']);
3259
        $this->assertSame($fieldDescriptionCollection, $this->parameters['elements']);
3260
3261
        $this->assertSame([], $this->session->getFlashBag()->all());
3262
        $this->assertSame('SonataAdminBundle:CRUD:show_compare.html.twig', $this->template);
3263
    }
3264
3265
    public function testBatchActionWrongMethod()
3266
    {
3267
        $this->expectException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException', 'Invalid request type "GET", POST expected');
3268
3269
        $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...
3270
    }
3271
3272
    /**
3273
     * NEXT_MAJOR: Remove this legacy group.
3274
     *
3275
     * @group legacy
3276
     */
3277
    public function testBatchActionActionNotDefined()
3278
    {
3279
        $this->expectException('RuntimeException', 'The `foo` batch action is not defined');
3280
3281
        $batchActions = [];
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('getBatchActions')
3285
            ->will($this->returnValue($batchActions));
3286
3287
        $this->request->setMethod('POST');
3288
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3289
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3290
3291
        $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...
3292
    }
3293
3294
    public function testBatchActionActionInvalidCsrfToken()
3295
    {
3296
        $this->request->setMethod('POST');
3297
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3298
        $this->request->request->set('_sonata_csrf_token', 'CSRF-INVALID');
3299
3300
        try {
3301
            $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...
3302
        } catch (HttpException $e) {
3303
            $this->assertSame('The csrf token is not valid, CSRF attack?', $e->getMessage());
3304
            $this->assertSame(400, $e->getStatusCode());
3305
        }
3306
    }
3307
3308
    /**
3309
     * NEXT_MAJOR: Remove this legacy group.
3310
     *
3311
     * @group legacy
3312
     */
3313
    public function testBatchActionMethodNotExist()
3314
    {
3315
        $this->expectException('RuntimeException', 'A `Sonata\AdminBundle\Controller\CRUDController::batchActionFoo` method must be callable');
3316
3317
        $batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3318
3319
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3320
            ->method('getBatchActions')
3321
            ->will($this->returnValue($batchActions));
3322
3323
        $datagrid = $this->createMock('\Sonata\AdminBundle\Datagrid\DatagridInterface');
3324
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3325
            ->method('getDatagrid')
3326
            ->will($this->returnValue($datagrid));
3327
3328
        $this->request->setMethod('POST');
3329
        $this->request->request->set('data', json_encode(['action' => 'foo', 'idx' => ['123', '456'], 'all_elements' => false]));
3330
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3331
3332
        $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...
3333
    }
3334
3335
    /**
3336
     * NEXT_MAJOR: Remove this legacy group.
3337
     *
3338
     * @group legacy
3339
     */
3340
    public function testBatchActionWithoutConfirmation()
3341
    {
3342
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3343
3344
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3345
            ->method('getBatchActions')
3346
            ->will($this->returnValue($batchActions));
3347
3348
        $datagrid = $this->createMock('\Sonata\AdminBundle\Datagrid\DatagridInterface');
3349
3350
        $query = $this->createMock('\Sonata\AdminBundle\Datagrid\ProxyQueryInterface');
3351
        $datagrid->expects($this->once())
3352
            ->method('getQuery')
3353
            ->will($this->returnValue($query));
3354
3355
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3356
            ->method('getDatagrid')
3357
            ->will($this->returnValue($datagrid));
3358
3359
        $modelManager = $this->createMock('Sonata\AdminBundle\Model\ModelManagerInterface');
3360
3361
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3362
            ->method('checkAccess')
3363
            ->with($this->equalTo('batchDelete'))
3364
            ->will($this->returnValue(true));
3365
3366
        $this->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...
3367
            ->method('getModelManager')
3368
            ->will($this->returnValue($modelManager));
3369
3370
        $this->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...
3371
            ->method('getClass')
3372
            ->will($this->returnValue('Foo'));
3373
3374
        $modelManager->expects($this->once())
3375
            ->method('addIdentifiersToQuery')
3376
            ->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456']))
3377
            ->will($this->returnValue(true));
3378
3379
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
3380
3381
        $this->request->setMethod('POST');
3382
        $this->request->request->set('data', json_encode(['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false]));
3383
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3384
3385
        $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...
3386
3387
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $result);
3388
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3389
        $this->assertSame('list?', $result->getTargetUrl());
3390
    }
3391
3392
    /**
3393
     * NEXT_MAJOR: Remove this legacy group.
3394
     *
3395
     * @group legacy
3396
     */
3397
    public function testBatchActionWithoutConfirmation2()
3398
    {
3399
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3400
3401
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3402
            ->method('getBatchActions')
3403
            ->will($this->returnValue($batchActions));
3404
3405
        $datagrid = $this->createMock('\Sonata\AdminBundle\Datagrid\DatagridInterface');
3406
3407
        $query = $this->createMock('\Sonata\AdminBundle\Datagrid\ProxyQueryInterface');
3408
        $datagrid->expects($this->once())
3409
            ->method('getQuery')
3410
            ->will($this->returnValue($query));
3411
3412
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3413
            ->method('getDatagrid')
3414
            ->will($this->returnValue($datagrid));
3415
3416
        $modelManager = $this->createMock('Sonata\AdminBundle\Model\ModelManagerInterface');
3417
3418
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
3424
            ->method('getModelManager')
3425
            ->will($this->returnValue($modelManager));
3426
3427
        $this->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...
3428
            ->method('getClass')
3429
            ->will($this->returnValue('Foo'));
3430
3431
        $modelManager->expects($this->once())
3432
            ->method('addIdentifiersToQuery')
3433
            ->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456']))
3434
            ->will($this->returnValue(true));
3435
3436
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
3437
3438
        $this->request->setMethod('POST');
3439
        $this->request->request->set('action', 'delete');
3440
        $this->request->request->set('idx', ['123', '456']);
3441
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3442
3443
        $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...
3444
3445
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $result);
3446
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3447
        $this->assertSame('list?', $result->getTargetUrl());
3448
    }
3449
3450
    /**
3451
     * NEXT_MAJOR: Remove this legacy group.
3452
     *
3453
     * @group legacy
3454
     */
3455
    public function testBatchActionWithConfirmation()
3456
    {
3457
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'translation_domain' => 'FooBarBaz', 'ask_confirmation' => true]];
3458
3459
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

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

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

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

Loading history...
3472
            ->method('getDatagrid')
3473
            ->will($this->returnValue($datagrid));
3474
3475
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')
3476
            ->disableOriginalConstructor()
3477
            ->getMock();
3478
3479
        $form->expects($this->once())
3480
            ->method('createView')
3481
            ->will($this->returnValue($this->createMock('Symfony\Component\Form\FormView')));
3482
3483
        $datagrid->expects($this->once())
3484
            ->method('getForm')
3485
            ->will($this->returnValue($form));
3486
3487
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $this->controller->batchAction($this->request));
0 ignored issues
show
Unused Code introduced by
The call to CRUDController::batchAction() has too many arguments starting with $this->request.

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

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

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

Loading history...
3488
3489
        $this->assertSame($this->admin, $this->parameters['admin']);
3490
        $this->assertSame('SonataAdminBundle::standard_layout.html.twig', $this->parameters['base_template']);
3491
        $this->assertSame($this->pool, $this->parameters['admin_pool']);
3492
3493
        $this->assertSame('list', $this->parameters['action']);
3494
        $this->assertSame($datagrid, $this->parameters['datagrid']);
3495
        $this->assertInstanceOf('Symfony\Component\Form\FormView', $this->parameters['form']);
3496
        $this->assertSame($data, $this->parameters['data']);
3497
        $this->assertSame('csrf-token-123_sonata.batch', $this->parameters['csrf_token']);
3498
        $this->assertSame('Foo Bar', $this->parameters['action_label']);
3499
3500
        $this->assertSame([], $this->session->getFlashBag()->all());
3501
        $this->assertSame('SonataAdminBundle:CRUD:batch_confirmation.html.twig', $this->template);
3502
    }
3503
3504
    /**
3505
     * NEXT_MAJOR: Remove this legacy group.
3506
     *
3507
     * @group legacy
3508
     */
3509
    public function testBatchActionNonRelevantAction()
3510
    {
3511
        $controller = new BatchAdminController();
3512
        $controller->setContainer($this->container);
3513
3514
        $batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3515
3516
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3517
            ->method('getBatchActions')
3518
            ->will($this->returnValue($batchActions));
3519
3520
        $datagrid = $this->createMock('\Sonata\AdminBundle\Datagrid\DatagridInterface');
3521
3522
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3523
            ->method('getDatagrid')
3524
            ->will($this->returnValue($datagrid));
3525
3526
        $this->expectTranslate('flash_batch_empty', [], 'SonataAdminBundle');
3527
3528
        $this->request->setMethod('POST');
3529
        $this->request->request->set('action', 'foo');
3530
        $this->request->request->set('idx', ['789']);
3531
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3532
3533
        $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...
3534
3535
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $result);
3536
        $this->assertSame(['flash_batch_empty'], $this->session->getFlashBag()->get('sonata_flash_info'));
3537
        $this->assertSame('list?', $result->getTargetUrl());
3538
    }
3539
3540
    /**
3541
     * NEXT_MAJOR: Remove this legacy group.
3542
     *
3543
     * @group legacy
3544
     */
3545
    public function testBatchActionNonRelevantAction2()
3546
    {
3547
        $controller = new BatchAdminController();
3548
        $controller->setContainer($this->container);
3549
3550
        $batchActions = ['foo' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3551
3552
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3553
            ->method('getBatchActions')
3554
            ->will($this->returnValue($batchActions));
3555
3556
        $datagrid = $this->createMock('\Sonata\AdminBundle\Datagrid\DatagridInterface');
3557
3558
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3559
            ->method('getDatagrid')
3560
            ->will($this->returnValue($datagrid));
3561
3562
        $this->expectTranslate('flash_foo_error', [], 'SonataAdminBundle');
3563
3564
        $this->request->setMethod('POST');
3565
        $this->request->request->set('action', 'foo');
3566
        $this->request->request->set('idx', ['999']);
3567
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3568
3569
        $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...
3570
3571
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $result);
3572
        $this->assertSame(['flash_foo_error'], $this->session->getFlashBag()->get('sonata_flash_info'));
3573
        $this->assertSame('list?', $result->getTargetUrl());
3574
    }
3575
3576
    /**
3577
     * NEXT_MAJOR: Remove this legacy group.
3578
     *
3579
     * @group legacy
3580
     */
3581
    public function testBatchActionNoItems()
3582
    {
3583
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => true]];
3584
3585
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3586
            ->method('getBatchActions')
3587
            ->will($this->returnValue($batchActions));
3588
3589
        $datagrid = $this->createMock('\Sonata\AdminBundle\Datagrid\DatagridInterface');
3590
3591
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3592
            ->method('getDatagrid')
3593
            ->will($this->returnValue($datagrid));
3594
3595
        $this->expectTranslate('flash_batch_empty', [], 'SonataAdminBundle');
3596
3597
        $this->request->setMethod('POST');
3598
        $this->request->request->set('action', 'delete');
3599
        $this->request->request->set('idx', []);
3600
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3601
3602
        $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...
3603
3604
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $result);
3605
        $this->assertSame(['flash_batch_empty'], $this->session->getFlashBag()->get('sonata_flash_info'));
3606
        $this->assertSame('list?', $result->getTargetUrl());
3607
    }
3608
3609
    /**
3610
     * NEXT_MAJOR: Remove this legacy group.
3611
     *
3612
     * @group legacy
3613
     */
3614
    public function testBatchActionNoItemsEmptyQuery()
3615
    {
3616
        $controller = new BatchAdminController();
3617
        $controller->setContainer($this->container);
3618
3619
        $batchActions = ['bar' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3620
3621
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3622
            ->method('getBatchActions')
3623
            ->will($this->returnValue($batchActions));
3624
3625
        $datagrid = $this->createMock('\Sonata\AdminBundle\Datagrid\DatagridInterface');
3626
3627
        $query = $this->createMock('\Sonata\AdminBundle\Datagrid\ProxyQueryInterface');
3628
        $datagrid->expects($this->once())
3629
            ->method('getQuery')
3630
            ->will($this->returnValue($query));
3631
3632
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3633
            ->method('getDatagrid')
3634
            ->will($this->returnValue($datagrid));
3635
3636
        $modelManager = $this->createMock('Sonata\AdminBundle\Model\ModelManagerInterface');
3637
3638
        $this->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...
3639
            ->method('getModelManager')
3640
            ->will($this->returnValue($modelManager));
3641
3642
        $this->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...
3643
            ->method('getClass')
3644
            ->will($this->returnValue('Foo'));
3645
3646
        $this->request->setMethod('POST');
3647
        $this->request->request->set('action', 'bar');
3648
        $this->request->request->set('idx', []);
3649
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3650
3651
        $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...
3652
3653
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $result);
3654
        $this->assertRegExp('/Redirecting to list/', $result->getContent());
3655
    }
3656
3657
    /**
3658
     * NEXT_MAJOR: Remove this legacy group.
3659
     *
3660
     * @group legacy
3661
     */
3662
    public function testBatchActionWithRequesData()
3663
    {
3664
        $batchActions = ['delete' => ['label' => 'Foo Bar', 'ask_confirmation' => false]];
3665
3666
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3667
            ->method('getBatchActions')
3668
            ->will($this->returnValue($batchActions));
3669
3670
        $datagrid = $this->createMock('\Sonata\AdminBundle\Datagrid\DatagridInterface');
3671
3672
        $query = $this->createMock('\Sonata\AdminBundle\Datagrid\ProxyQueryInterface');
3673
        $datagrid->expects($this->once())
3674
            ->method('getQuery')
3675
            ->will($this->returnValue($query));
3676
3677
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3678
            ->method('getDatagrid')
3679
            ->will($this->returnValue($datagrid));
3680
3681
        $modelManager = $this->createMock('Sonata\AdminBundle\Model\ModelManagerInterface');
3682
3683
        $this->admin->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.

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

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

Loading history...
3684
            ->method('checkAccess')
3685
            ->with($this->equalTo('batchDelete'))
3686
            ->will($this->returnValue(true));
3687
3688
        $this->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...
3689
            ->method('getModelManager')
3690
            ->will($this->returnValue($modelManager));
3691
3692
        $this->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...
3693
            ->method('getClass')
3694
            ->will($this->returnValue('Foo'));
3695
3696
        $modelManager->expects($this->once())
3697
            ->method('addIdentifiersToQuery')
3698
            ->with($this->equalTo('Foo'), $this->equalTo($query), $this->equalTo(['123', '456']))
3699
            ->will($this->returnValue(true));
3700
3701
        $this->expectTranslate('flash_batch_delete_success', [], 'SonataAdminBundle');
3702
3703
        $this->request->setMethod('POST');
3704
        $this->request->request->set('data', json_encode(['action' => 'delete', 'idx' => ['123', '456'], 'all_elements' => false]));
3705
        $this->request->request->set('foo', 'bar');
3706
        $this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.batch');
3707
3708
        $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...
3709
3710
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $result);
3711
        $this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
3712
        $this->assertSame('list?', $result->getTargetUrl());
3713
        $this->assertSame('bar', $this->request->request->get('foo'));
3714
    }
3715
3716
    public function testItThrowsWhenCallingAnUndefinedMethod()
3717
    {
3718
        $this->setExpectedException(
3719
            \LogicException::class,
3720
            'Call to undefined method Sonata\AdminBundle\Controller\CRUDController::doesNotExist'
3721
        );
3722
        $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...
3723
    }
3724
3725
    /**
3726
     * @expectedDeprecation Method Sonata\AdminBundle\Controller\CRUDController::render has been renamed to Sonata\AdminBundle\Controller\CRUDController::renderWithExtraParams
3727
     */
3728
    public function testRenderIsDeprecated()
3729
    {
3730
        $this->controller->render('toto.html.twig');
0 ignored issues
show
Deprecated Code introduced by
The method Sonata\AdminBundle\Contr...RUDController::render() has been deprecated.

This method has been deprecated.

Loading history...
3731
    }
3732
3733
    public function getCsrfProvider()
3734
    {
3735
        return $this->csrfProvider;
3736
    }
3737
3738
    public function getToStringValues()
3739
    {
3740
        return [
3741
            ['', ''],
3742
            ['Foo', 'Foo'],
3743
            ['&lt;a href=&quot;http://foo&quot;&gt;Bar&lt;/a&gt;', '<a href="http://foo">Bar</a>'],
3744
            ['&lt;&gt;&amp;&quot;&#039;abcdefghijklmnopqrstuvwxyz*-+.,?_()[]\/', '<>&"\'abcdefghijklmnopqrstuvwxyz*-+.,?_()[]\/'],
3745
        ];
3746
    }
3747
3748
    private function assertLoggerLogsModelManagerException($subject, $method)
3749
    {
3750
        $exception = new ModelManagerException(
3751
            $message = 'message',
3752
            1234,
3753
            new \Exception($previousExceptionMessage = 'very useful message')
3754
        );
3755
3756
        $subject->expects($this->once())
3757
            ->method($method)
3758
            ->will($this->returnCallback(function () use ($exception) {
3759
                throw $exception;
3760
            }));
3761
3762
        $this->logger->expects($this->once())
3763
            ->method('error')
3764
            ->with($message, [
3765
                'exception' => $exception,
3766
                'previous_exception_message' => $previousExceptionMessage,
3767
            ]);
3768
    }
3769
3770
    private function expectTranslate($id, array $parameters = [], $domain = null, $locale = null)
3771
    {
3772
        $this->translator->expects($this->once())
3773
            ->method('trans')
3774
            ->with($this->equalTo($id), $this->equalTo($parameters), $this->equalTo($domain), $this->equalTo($locale))
3775
            ->will($this->returnValue($id));
3776
    }
3777
}
3778