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; |
15
|
|
|
|
16
|
|
|
use PHPUnit\Framework\TestCase; |
17
|
|
|
use Sonata\AdminBundle\DependencyInjection\Compiler\AddDependencyCallsCompilerPass; |
18
|
|
|
use Sonata\AdminBundle\DependencyInjection\Compiler\AddFilterTypeCompilerPass; |
19
|
|
|
use Sonata\AdminBundle\DependencyInjection\Compiler\AdminMakerCompilerPass; |
20
|
|
|
use Sonata\AdminBundle\DependencyInjection\Compiler\ExtensionCompilerPass; |
21
|
|
|
use Sonata\AdminBundle\DependencyInjection\Compiler\GlobalVariablesCompilerPass; |
22
|
|
|
use Sonata\AdminBundle\SonataAdminBundle; |
23
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
24
|
|
|
use Symfony\Component\DependencyInjection\Compiler\PassConfig; |
25
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @author Andrej Hudec <[email protected]> |
29
|
|
|
*/ |
30
|
|
|
class SonataAdminBundleTest extends TestCase |
31
|
|
|
{ |
32
|
|
|
public function testBuild(): void |
33
|
|
|
{ |
34
|
|
|
$containerBuilder = $this->getMockBuilder(ContainerBuilder::class) |
35
|
|
|
->setMethods(['addCompilerPass', 'getParameter']) |
36
|
|
|
->getMock(); |
37
|
|
|
|
38
|
|
|
$containerBuilder->expects($this->exactly(4)) |
39
|
|
|
->method('addCompilerPass') |
40
|
|
|
->will($this->returnCallback(function (CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION): void { |
|
|
|
|
41
|
|
|
if ($pass instanceof AddDependencyCallsCompilerPass) { |
42
|
|
|
return; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
if ($pass instanceof AddFilterTypeCompilerPass) { |
46
|
|
|
return; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
if ($pass instanceof ExtensionCompilerPass) { |
50
|
|
|
return; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
if ($pass instanceof GlobalVariablesCompilerPass) { |
54
|
|
|
return; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$this->fail(sprintf( |
58
|
|
|
'CompilerPass is not one of the expected types. Expects "%s", "%s", "%s" or "%s", but got "%s".', |
59
|
|
|
AddDependencyCallsCompilerPass::class, |
60
|
|
|
AddFilterTypeCompilerPass::class, |
61
|
|
|
ExtensionCompilerPass::class, |
62
|
|
|
GlobalVariablesCompilerPass::class, |
63
|
|
|
\get_class($pass) |
64
|
|
|
)); |
65
|
|
|
})); |
66
|
|
|
|
67
|
|
|
$containerBuilder |
68
|
|
|
->expects($this->once()) |
69
|
|
|
->method('getParameter') |
70
|
|
|
->with('kernel.bundles') |
71
|
|
|
->willReturn([]); |
72
|
|
|
|
73
|
|
|
$bundle = new SonataAdminBundle(); |
74
|
|
|
$bundle->build($containerBuilder); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function testBuildWithMakerBundle(): void |
78
|
|
|
{ |
79
|
|
|
$containerBuilder = $this->getMockBuilder(ContainerBuilder::class) |
80
|
|
|
->setMethods(['addCompilerPass', 'getParameter']) |
81
|
|
|
->getMock(); |
82
|
|
|
|
83
|
|
|
$containerBuilder->expects($this->exactly(5)) |
84
|
|
|
->method('addCompilerPass') |
85
|
|
|
->will($this->returnCallback(function (CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION): void { |
86
|
|
|
if ($pass instanceof AddDependencyCallsCompilerPass) { |
87
|
|
|
return; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
if ($pass instanceof AddFilterTypeCompilerPass) { |
91
|
|
|
return; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
if ($pass instanceof ExtensionCompilerPass) { |
95
|
|
|
return; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
if ($pass instanceof GlobalVariablesCompilerPass) { |
99
|
|
|
return; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
if ($pass instanceof AdminMakerCompilerPass) { |
103
|
|
|
return; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
$this->fail(sprintf( |
107
|
|
|
'CompilerPass is not one of the expected types. Expects "%s", "%s", "%s", "%s" or "%s", but got "%s".', |
108
|
|
|
AddDependencyCallsCompilerPass::class, |
109
|
|
|
AddFilterTypeCompilerPass::class, |
110
|
|
|
ExtensionCompilerPass::class, |
111
|
|
|
GlobalVariablesCompilerPass::class, |
112
|
|
|
AdminMakerCompilerPass::class, |
113
|
|
|
\get_class($pass) |
114
|
|
|
)); |
115
|
|
|
})); |
116
|
|
|
|
117
|
|
|
$containerBuilder |
118
|
|
|
->expects($this->once()) |
119
|
|
|
->method('getParameter') |
120
|
|
|
->with('kernel.bundles') |
121
|
|
|
->willReturn(['MakerBundle' => 'foo']); |
122
|
|
|
|
123
|
|
|
$bundle = new SonataAdminBundle(); |
124
|
|
|
$bundle->build($containerBuilder); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.