Completed
Push — master ( 285bc9...932fc1 )
by Marko
14s
created

CoreControllerTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 6
dl 0
loc 106
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testdashboardActionStandardRequest() 0 47 1
A testdashboardActionAjaxLayout() 0 49 1
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
     * @group legacy
32
     */
33
    public function testdashboardActionStandardRequest(): void
34
    {
35
        $container = $this->createMock(ContainerInterface::class);
36
37
        $templateRegistry = $this->prophesize(MutableTemplateRegistryInterface::class);
38
        $templateRegistry->getTemplate('ajax')->willReturn('ajax.html');
39
        $templateRegistry->getTemplate('dashboard')->willReturn('dashboard.html');
40
        $templateRegistry->getTemplate('layout')->willReturn('layout.html');
41
42
        $pool = new Pool($container, 'title', 'logo.png');
43
        $pool->setTemplateRegistry($templateRegistry->reveal());
44
45
        $templating = $this->createMock(EngineInterface::class);
46
        $request = new Request();
47
48
        $requestStack = new RequestStack();
49
        $requestStack->push($request);
50
51
        $breadcrumbsBuilder = $this->getMockForAbstractClass(BreadcrumbsBuilderInterface::class);
52
53
        $values = [
54
            DashboardAction::class => $dashboardAction = new DashboardAction(
55
                [],
56
                $breadcrumbsBuilder,
57
                $templateRegistry->reveal(),
58
                $pool
59
            ),
60
            'templating' => $templating,
61
            'request_stack' => $requestStack,
62
        ];
63
        $dashboardAction->setContainer($container);
64
65
        $container->expects($this->any())->method('get')->will($this->returnCallback(function ($id) use ($values) {
66
            return $values[$id];
67
        }));
68
69
        $container->expects($this->any())
70
            ->method('has')
71
            ->will($this->returnCallback(function ($id) {
72
                return 'templating' === $id;
73
            }));
74
75
        $controller = new CoreController();
76
        $controller->setContainer($container);
77
78
        $this->isInstanceOf(Response::class, $controller->dashboardAction());
79
    }
80
81
    /**
82
     * @group legacy
83
     */
84
    public function testdashboardActionAjaxLayout(): void
85
    {
86
        $container = $this->createMock(ContainerInterface::class);
87
88
        $templateRegistry = $this->prophesize(MutableTemplateRegistryInterface::class);
89
        $templateRegistry->getTemplate('ajax')->willReturn('ajax.html');
90
        $templateRegistry->getTemplate('dashboard')->willReturn('dashboard.html');
91
        $templateRegistry->getTemplate('layout')->willReturn('layout.html');
92
        $breadcrumbsBuilder = $this->getMockForAbstractClass(BreadcrumbsBuilderInterface::class);
93
94
        $pool = new Pool($container, 'title', 'logo.png');
95
        $pool->setTemplateRegistry($templateRegistry->reveal());
96
97
        $templating = $this->createMock(EngineInterface::class);
98
        $request = new Request();
99
        $request->headers->set('X-Requested-With', 'XMLHttpRequest');
100
101
        $requestStack = new RequestStack();
102
        $requestStack->push($request);
103
104
        $values = [
105
            DashboardAction::class => $dashboardAction = new DashboardAction(
106
                [],
107
                $breadcrumbsBuilder,
108
                $templateRegistry->reveal(),
109
                $pool
110
            ),
111
            'templating' => $templating,
112
            'request_stack' => $requestStack,
113
        ];
114
        $dashboardAction->setContainer($container);
115
116
        $container->expects($this->any())->method('get')->will($this->returnCallback(function ($id) use ($values) {
117
            return $values[$id];
118
        }));
119
120
        $container->expects($this->any())
121
            ->method('has')
122
            ->will($this->returnCallback(function ($id) {
123
                return 'templating' === $id;
124
            }));
125
126
        $controller = new CoreController();
127
        $controller->setContainer($container);
128
129
        $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...
130
131
        $this->isInstanceOf(Response::class, $response);
132
    }
133
}
134