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

tests/Action/DashboardActionTest.php (1 issue)

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\Action;
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\Templating\MutableTemplateRegistryInterface;
21
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
22
use Symfony\Component\DependencyInjection\ContainerInterface;
23
use Symfony\Component\HttpFoundation\Request;
24
use Symfony\Component\HttpFoundation\RequestStack;
25
use Symfony\Component\HttpFoundation\Response;
26
27
class DashboardActionTest extends TestCase
28
{
29
    /**
30
     * @doesNotPerformAssertions
31
     */
32
    public function testdashboardActionStandardRequest(): void
33
    {
34
        $container = $this->createMock(ContainerInterface::class);
35
36
        $templateRegistry = $this->prophesize(MutableTemplateRegistryInterface::class);
37
        $templateRegistry->getTemplate('ajax')->willReturn('ajax.html');
38
        $templateRegistry->getTemplate('dashboard')->willReturn('dashboard.html');
39
        $templateRegistry->getTemplate('layout')->willReturn('layout.html');
40
41
        $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...
42
        $pool->setTemplateRegistry($templateRegistry->reveal());
43
44
        $templating = $this->createMock(EngineInterface::class);
45
        $request = new Request();
46
47
        $requestStack = new RequestStack();
48
        $requestStack->push($request);
49
50
        $breadcrumbsBuilder = $this->getMockForAbstractClass(BreadcrumbsBuilderInterface::class);
51
52
        $dashboardAction = new DashboardAction(
53
            [],
54
            $breadcrumbsBuilder,
55
            $templateRegistry->reveal(),
56
            $pool
57
        );
58
        $values = [
59
            'templating' => $templating,
60
            'request_stack' => $requestStack,
61
        ];
62
        $dashboardAction->setContainer($container);
63
64
        $container->expects($this->any())->method('get')->willReturnCallback(static function ($id) use ($values) {
65
            return $values[$id];
66
        });
67
68
        $container->expects($this->any())
69
            ->method('has')
70
            ->willReturnCallback(static function ($id) {
71
                return 'templating' === $id;
72
            });
73
74
        $this->isInstanceOf(Response::class, $dashboardAction($request));
75
    }
76
77
    /**
78
     * @doesNotPerformAssertions
79
     */
80
    public function testDashboardActionAjaxLayout(): void
81
    {
82
        $container = $this->createMock(ContainerInterface::class);
83
84
        $templateRegistry = $this->prophesize(MutableTemplateRegistryInterface::class);
85
        $templateRegistry->getTemplate('ajax')->willReturn('ajax.html');
86
        $templateRegistry->getTemplate('dashboard')->willReturn('dashboard.html');
87
        $templateRegistry->getTemplate('layout')->willReturn('layout.html');
88
        $breadcrumbsBuilder = $this->getMockForAbstractClass(BreadcrumbsBuilderInterface::class);
89
90
        $pool = new Pool($container, 'title', 'logo.png');
91
        $pool->setTemplateRegistry($templateRegistry->reveal());
92
93
        $templating = $this->createMock(EngineInterface::class);
94
        $request = new Request();
95
        $request->headers->set('X-Requested-With', 'XMLHttpRequest');
96
97
        $requestStack = new RequestStack();
98
        $requestStack->push($request);
99
100
        $dashboardAction = new DashboardAction(
101
            [],
102
            $breadcrumbsBuilder,
103
            $templateRegistry->reveal(),
104
            $pool
105
        );
106
        $dashboardAction->setContainer($container);
107
        $values = [
108
            'templating' => $templating,
109
            'request_stack' => $requestStack,
110
        ];
111
        $dashboardAction->setContainer($container);
112
113
        $container->expects($this->any())->method('get')->willReturnCallback(static function ($id) use ($values) {
114
            return $values[$id];
115
        });
116
117
        $container->expects($this->any())
118
            ->method('has')
119
            ->willReturnCallback(static function ($id) {
120
                return 'templating' === $id;
121
            });
122
123
        $this->isInstanceOf(Response::class, $dashboardAction($request));
124
    }
125
}
126