|
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'); |
|
|
|
|
|
|
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, |
|
|
|
|
|
|
49
|
|
|
$templateRegistry->reveal(), |
|
50
|
|
|
$pool, |
|
51
|
|
|
$templating |
|
|
|
|
|
|
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
|
|
|
|
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: