Completed
Push — master ( a97f84...b5df1f )
by
unknown
11:58
created

tests/Action/DashboardActionTest.php (9 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\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,
0 ignored issues
show
$breadcrumbsBuilder is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Sonata\AdminBundl...crumbsBuilderInterface>.

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...
55
            $templateRegistry->reveal(),
56
            $pool
57
        );
58
        $values = [
59
            'templating' => $templating,
60
            'request_stack' => $requestStack,
61
        ];
62
        $dashboardAction->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...
63
64
        $container->expects($this->any())->method('get')->will($this->returnCallback(function ($id) use ($values) {
65
            return $values[$id];
66
        }));
67
68
        $container->expects($this->any())
69
            ->method('has')
70
            ->will($this->returnCallback(function ($id) {
71
                return 'templating' === $id;
72
            }));
73
74
        $this->isInstanceOf(Response::class, $dashboardAction($request));
0 ignored issues
show
The call to DashboardActionTest::isInstanceOf() has too many arguments starting with $dashboardAction($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...
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');
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...
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,
0 ignored issues
show
$breadcrumbsBuilder is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Sonata\AdminBundl...crumbsBuilderInterface>.

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...
103
            $templateRegistry->reveal(),
104
            $pool
105
        );
106
        $dashboardAction->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...
107
        $values = [
108
            'templating' => $templating,
109
            'request_stack' => $requestStack,
110
        ];
111
        $dashboardAction->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...
112
113
        $container->expects($this->any())->method('get')->will($this->returnCallback(function ($id) use ($values) {
114
            return $values[$id];
115
        }));
116
117
        $container->expects($this->any())
118
            ->method('has')
119
            ->will($this->returnCallback(function ($id) {
120
                return 'templating' === $id;
121
            }));
122
123
        $this->isInstanceOf(Response::class, $dashboardAction($request));
0 ignored issues
show
The call to DashboardActionTest::isInstanceOf() has too many arguments starting with $dashboardAction($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...
124
    }
125
}
126