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\DoctrineORMAdminBundle\Tests\DependencyInjection\Compiler; |
15
|
|
|
|
16
|
|
|
use PHPUnit\Framework\TestCase; |
17
|
|
|
use Sonata\DoctrineORMAdminBundle\DependencyInjection\Compiler\AddTemplatesCompilerPass; |
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
19
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
20
|
|
|
|
21
|
|
|
class AddTemplatesCompilerPassTest extends TestCase |
22
|
|
|
{ |
23
|
|
|
public function testDefaultBehavior(): void |
24
|
|
|
{ |
25
|
|
|
$container = $this->createMock(ContainerBuilder::class); |
26
|
|
|
|
27
|
|
|
$container |
28
|
|
|
->expects($this->any()) |
29
|
|
|
->method('getParameter') |
30
|
|
|
->willReturnCallback(static function ($value) { |
31
|
|
|
if ('sonata.admin.configuration.admin_services' === $value) { |
32
|
|
|
return [ |
33
|
|
|
'my.admin' => [ |
34
|
|
|
'templates' => [ |
35
|
|
|
'form' => ['myform.twig.html'], |
36
|
|
|
'filter' => ['myfilter.twig.html'], |
37
|
|
|
], |
38
|
|
|
], |
39
|
|
|
]; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
if ('sonata_doctrine_orm_admin.templates' === $value) { |
43
|
|
|
return [ |
44
|
|
|
'form' => ['default_form.twig.html'], |
45
|
|
|
'filter' => ['default_filter.twig.html'], |
46
|
|
|
]; |
47
|
|
|
} |
48
|
|
|
}) |
49
|
|
|
; |
50
|
|
|
|
51
|
|
|
$container |
52
|
|
|
->expects($this->any()) |
53
|
|
|
->method('findTaggedServiceIds') |
54
|
|
|
->willReturn(['my.admin' => [['manager_type' => 'orm']]]) |
55
|
|
|
; |
56
|
|
|
|
57
|
|
|
$definition = new Definition(null); |
58
|
|
|
|
59
|
|
|
$container |
60
|
|
|
->expects($this->any()) |
61
|
|
|
->method('getDefinition') |
62
|
|
|
->willReturn($definition) |
63
|
|
|
; |
64
|
|
|
|
65
|
|
|
$definition->addMethodCall('setFilterTheme', [['custom_call.twig.html']]); |
66
|
|
|
|
67
|
|
|
$compilerPass = new AddTemplatesCompilerPass(); |
68
|
|
|
$compilerPass->process($container); |
69
|
|
|
|
70
|
|
|
$expected = [ |
71
|
|
|
['setFilterTheme', [['custom_call.twig.html', 'myfilter.twig.html']]], |
72
|
|
|
['setFormTheme', [['default_form.twig.html', 'myform.twig.html']]], |
73
|
|
|
]; |
74
|
|
|
|
75
|
|
|
$this->assertSame($expected, $definition->getMethodCalls()); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|