Completed
Push — 3.x ( db377c...cd74a2 )
by Andrey F.
12:41
created

testdashboardActionStandardRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 47
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 47
rs 9.0303
c 1
b 0
f 0
cc 1
eloc 30
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 PHPUnit\Framework\TestCase;
15
use Sonata\AdminBundle\Action\DashboardAction;
16
use Sonata\AdminBundle\Admin\BreadcrumbsBuilderInterface;
17
use Sonata\AdminBundle\Admin\Pool;
18
use Sonata\AdminBundle\Controller\CoreController;
19
use Sonata\AdminBundle\Templating\MutableTemplateRegistryInterface;
20
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
21
use Symfony\Component\DependencyInjection\ContainerInterface;
22
use Symfony\Component\HttpFoundation\Request;
23
use Symfony\Component\HttpFoundation\RequestStack;
24
use Symfony\Component\HttpFoundation\Response;
25
26
class CoreControllerTest extends TestCase
27
{
28
    /**
29
     * @group legacy
30
     */
31
    public function testdashboardActionStandardRequest()
32
    {
33
        $container = $this->createMock(ContainerInterface::class);
34
35
        $templateRegistry = $this->prophesize(MutableTemplateRegistryInterface::class);
36
        $templateRegistry->getTemplate('ajax')->willReturn('ajax.html');
37
        $templateRegistry->getTemplate('dashboard')->willReturn('dashboard.html');
38
        $templateRegistry->getTemplate('layout')->willReturn('layout.html');
39
40
        $pool = new Pool($container, 'title', 'logo.png');
41
        $pool->setTemplateRegistry($templateRegistry->reveal());
42
43
        $templating = $this->createMock(EngineInterface::class);
44
        $request = new Request();
45
46
        $requestStack = new RequestStack();
47
        $requestStack->push($request);
48
49
        $breadcrumbsBuilder = $this->getMockForAbstractClass(BreadcrumbsBuilderInterface::class);
50
51
        $values = [
52
            DashboardAction::class => $dashboardAction = new DashboardAction(
53
                [],
54
                $breadcrumbsBuilder,
55
                $templateRegistry->reveal(),
56
                $pool
57
            ),
58
            'templating' => $templating,
59
            'request_stack' => $requestStack,
60
        ];
61
        $dashboardAction->setContainer($container);
62
63
        $container->expects($this->any())->method('get')->will($this->returnCallback(function ($id) use ($values) {
64
            return $values[$id];
65
        }));
66
67
        $container->expects($this->any())
68
            ->method('has')
69
            ->will($this->returnCallback(function ($id) {
70
                return 'templating' === $id;
71
            }));
72
73
        $controller = new CoreController();
74
        $controller->setContainer($container);
75
76
        $this->isInstanceOf(Response::class, $controller->dashboardAction());
77
    }
78
79
    /**
80
     * @group legacy
81
     */
82
    public function testdashboardActionAjaxLayout()
83
    {
84
        $container = $this->createMock(ContainerInterface::class);
85
86
        $templateRegistry = $this->prophesize(MutableTemplateRegistryInterface::class);
87
        $templateRegistry->getTemplate('ajax')->willReturn('ajax.html');
88
        $templateRegistry->getTemplate('dashboard')->willReturn('dashboard.html');
89
        $templateRegistry->getTemplate('layout')->willReturn('layout.html');
90
        $breadcrumbsBuilder = $this->getMockForAbstractClass(BreadcrumbsBuilderInterface::class);
91
92
        $pool = new Pool($container, 'title', 'logo.png');
93
        $pool->setTemplateRegistry($templateRegistry->reveal());
94
95
        $templating = $this->createMock(EngineInterface::class);
96
        $request = new Request();
97
        $request->headers->set('X-Requested-With', 'XMLHttpRequest');
98
99
        $requestStack = new RequestStack();
100
        $requestStack->push($request);
101
102
        $values = [
103
            DashboardAction::class => $dashboardAction = new DashboardAction(
104
                [],
105
                $breadcrumbsBuilder,
106
                $templateRegistry->reveal(),
107
                $pool
108
            ),
109
            'templating' => $templating,
110
            'request_stack' => $requestStack,
111
        ];
112
        $dashboardAction->setContainer($container);
113
114
        $container->expects($this->any())->method('get')->will($this->returnCallback(function ($id) use ($values) {
115
            return $values[$id];
116
        }));
117
118
        $container->expects($this->any())
119
            ->method('has')
120
            ->will($this->returnCallback(function ($id) {
121
                return 'templating' === $id;
122
            }));
123
124
        $controller = new CoreController();
125
        $controller->setContainer($container);
126
127
        $response = $controller->dashboardAction($request);
0 ignored issues
show
Unused Code introduced by
The call to CoreController::dashboardAction() has too many arguments starting with $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...
128
129
        $this->isInstanceOf(Response::class, $response);
130
    }
131
}
132