Completed
Push — master ( e6c9d7...cc6bd7 )
by Grégoire
12:23
created

tests/Controller/CoreControllerTest.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\AdminBundle\Tests\Controller;
15
16
use PHPUnit\Framework\TestCase;
17
use Sonata\AdminBundle\Action\DashboardAction;
18
use Sonata\AdminBundle\Admin\BreadcrumbsBuilderInterface;
19
use Sonata\AdminBundle\Admin\Pool;
20
use Sonata\AdminBundle\Controller\CoreController;
21
use Sonata\AdminBundle\Templating\MutableTemplateRegistryInterface;
22
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
23
use Symfony\Component\DependencyInjection\ContainerInterface;
24
use Symfony\Component\HttpFoundation\Request;
25
use Symfony\Component\HttpFoundation\RequestStack;
26
use Symfony\Component\HttpFoundation\Response;
27
28
class CoreControllerTest extends TestCase
29
{
30
    /**
31
     * @doesNotPerformAssertions
32
     * @group legacy
33
     */
34
    public function testdashboardActionStandardRequest(): void
35
    {
36
        $container = $this->createMock(ContainerInterface::class);
37
38
        $templateRegistry = $this->prophesize(MutableTemplateRegistryInterface::class);
39
        $templateRegistry->getTemplate('ajax')->willReturn('ajax.html');
40
        $templateRegistry->getTemplate('dashboard')->willReturn('dashboard.html');
41
        $templateRegistry->getTemplate('layout')->willReturn('layout.html');
42
43
        $pool = new Pool($container, 'title', 'logo.png');
44
        $pool->setTemplateRegistry($templateRegistry->reveal());
45
46
        $templating = $this->createMock(EngineInterface::class);
47
        $request = new Request();
48
49
        $requestStack = new RequestStack();
50
        $requestStack->push($request);
51
52
        $breadcrumbsBuilder = $this->getMockForAbstractClass(BreadcrumbsBuilderInterface::class);
53
54
        $values = [
55
            DashboardAction::class => $dashboardAction = new DashboardAction(
56
                [],
57
                $breadcrumbsBuilder,
58
                $templateRegistry->reveal(),
59
                $pool
60
            ),
61
            'templating' => $templating,
62
            'request_stack' => $requestStack,
63
        ];
64
        $dashboardAction->setContainer($container);
65
66
        $container->expects($this->any())->method('get')->willReturnCallback(static function ($id) use ($values) {
67
            return $values[$id];
68
        });
69
70
        $container->expects($this->any())
71
            ->method('has')
72
            ->willReturnCallback(static function ($id) {
73
                return 'templating' === $id;
74
            });
75
76
        $controller = new CoreController();
77
        $controller->setContainer($container);
0 ignored issues
show
$container is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a null|object<Symfony\Comp...ion\ContainerInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
78
79
        $this->isInstanceOf(Response::class, $controller->dashboardAction());
80
    }
81
82
    /**
83
     * @doesNotPerformAssertions
84
     * @group legacy
85
     */
86
    public function testdashboardActionAjaxLayout(): void
87
    {
88
        $container = $this->createMock(ContainerInterface::class);
89
90
        $templateRegistry = $this->prophesize(MutableTemplateRegistryInterface::class);
91
        $templateRegistry->getTemplate('ajax')->willReturn('ajax.html');
92
        $templateRegistry->getTemplate('dashboard')->willReturn('dashboard.html');
93
        $templateRegistry->getTemplate('layout')->willReturn('layout.html');
94
        $breadcrumbsBuilder = $this->getMockForAbstractClass(BreadcrumbsBuilderInterface::class);
95
96
        $pool = new Pool($container, 'title', 'logo.png');
0 ignored issues
show
$container is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...ion\ContainerInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
97
        $pool->setTemplateRegistry($templateRegistry->reveal());
98
99
        $templating = $this->createMock(EngineInterface::class);
100
        $request = new Request();
101
        $request->headers->set('X-Requested-With', 'XMLHttpRequest');
102
103
        $requestStack = new RequestStack();
104
        $requestStack->push($request);
105
106
        $values = [
107
            DashboardAction::class => $dashboardAction = new DashboardAction(
108
                [],
109
                $breadcrumbsBuilder,
110
                $templateRegistry->reveal(),
111
                $pool
112
            ),
113
            'templating' => $templating,
114
            'request_stack' => $requestStack,
115
        ];
116
        $dashboardAction->setContainer($container);
117
118
        $container->expects($this->any())->method('get')->willReturnCallback(static function ($id) use ($values) {
119
            return $values[$id];
120
        });
121
122
        $container->expects($this->any())
123
            ->method('has')
124
            ->willReturnCallback(static function ($id) {
125
                return 'templating' === $id;
126
            });
127
128
        $controller = new CoreController();
129
        $controller->setContainer($container);
0 ignored issues
show
$container is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a null|object<Symfony\Comp...ion\ContainerInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
130
131
        $response = $controller->dashboardAction($request);
132
133
        $this->isInstanceOf(Response::class, $response);
134
    }
135
}
136