Completed
Push — 3.x ( 64aa95...b9739c )
by Christian
03:31
created

DashboardActionTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 6
dl 0
loc 44
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 24 1
A testdashboardActionStandardRequest() 0 6 1
A testDashboardActionAjaxLayout() 0 7 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\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\Response;
25
26
class DashboardActionTest extends TestCase
27
{
28
    private $action;
29
30
    protected function setUp(): void
31
    {
32
        $container = $this->createMock(ContainerInterface::class);
33
34
        $templateRegistry = $this->prophesize(MutableTemplateRegistryInterface::class);
35
        $templateRegistry->getTemplate('ajax')->willReturn('ajax.html');
36
        $templateRegistry->getTemplate('dashboard')->willReturn('dashboard.html');
37
        $templateRegistry->getTemplate('layout')->willReturn('layout.html');
38
39
        $pool = new Pool($container, 'title', 'logo.png');
0 ignored issues
show
Documentation introduced by
$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...
40
        $pool->setTemplateRegistry($templateRegistry->reveal());
41
42
        $templating = $this->createMock(EngineInterface::class);
43
44
        $breadcrumbsBuilder = $this->getMockForAbstractClass(BreadcrumbsBuilderInterface::class);
45
46
        $this->action = new DashboardAction(
47
            [],
48
            $breadcrumbsBuilder,
0 ignored issues
show
Documentation introduced by
$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...
49
            $templateRegistry->reveal(),
50
            $pool,
51
            $templating
0 ignored issues
show
Documentation introduced by
$templating is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...lating\EngineInterface>.

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...
52
        );
53
    }
54
55
    public function testdashboardActionStandardRequest()
56
    {
57
        $request = new Request();
58
59
        $this->assertInstanceOf(Response::class, ($this->action)($request));
60
    }
61
62
    public function testDashboardActionAjaxLayout(): void
63
    {
64
        $request = new Request();
65
        $request->headers->set('X-Requested-With', 'XMLHttpRequest');
66
67
        $this->assertInstanceOf(Response::class, ($this->action)($request));
68
    }
69
}
70