1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace League\Tactician\Bundle\Tests\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use League\Tactician\Bundle\DependencyInjection\TacticianExtension; |
6
|
|
|
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; |
7
|
|
|
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; |
8
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
9
|
|
|
|
10
|
|
|
class TacticianExtensionTest extends AbstractExtensionTestCase |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Return an array of container extensions you need to be registered for each test (usually just the container |
14
|
|
|
* extension you are testing. |
15
|
|
|
* |
16
|
|
|
* @return ExtensionInterface[] |
17
|
|
|
*/ |
18
|
|
|
protected function getContainerExtensions() |
19
|
|
|
{ |
20
|
|
|
return [ |
21
|
|
|
new TacticianExtension() |
22
|
|
|
]; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
protected function getMinimalConfiguration() |
26
|
|
|
{ |
27
|
|
|
return [ |
28
|
|
|
'commandbus' => [ |
29
|
|
|
'default' => [ |
30
|
|
|
'middleware' => [ |
31
|
|
|
'my_middleware.custom.stuff', |
32
|
|
|
'tactician.middleware.command_handler', |
33
|
|
|
] |
34
|
|
|
] |
35
|
|
|
] |
36
|
|
|
]; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testCommandBusLoadsAndSetsDefault() |
40
|
|
|
{ |
41
|
|
|
$this->load([ |
42
|
|
|
'commandbus' => [ |
43
|
|
|
'bus_1' => [ |
44
|
|
|
'middleware' => [ |
45
|
|
|
'my_middleware.custom.stuff', |
46
|
|
|
'tactician.middleware.command_handler', |
47
|
|
|
] |
48
|
|
|
], |
49
|
|
|
'bus_2' => [ |
50
|
|
|
'middleware' => [ |
51
|
|
|
'my_middleware.custom.stuff', |
52
|
|
|
'tactician.middleware.command_handler', |
53
|
|
|
] |
54
|
|
|
], |
55
|
|
|
], |
56
|
|
|
'default_bus' => 'bus_2' |
57
|
|
|
]); |
58
|
|
|
|
59
|
|
|
$this->assertContainerBuilderHasService('tactician.commandbus.bus_1'); |
60
|
|
|
$this->assertContainerBuilderHasService('tactician.commandbus.bus_2'); |
61
|
|
|
$this->assertContainerBuilderHasParameter('tactician.commandbus.ids', ['default', 'bus_1', 'bus_2']); |
62
|
|
|
$this->assertContainerBuilderHasParameter('tactician.commandbus.default', 'bus_2'); |
63
|
|
|
$this->assertContainerBuilderHasParameter('tactician.method_inflector.default', 'tactician.handler.method_name_inflector.handle'); |
64
|
|
|
$this->assertContainerBuilderHasParameter('tactician.method_inflector.bus_1', 'tactician.handler.method_name_inflector.handle'); |
65
|
|
|
$this->assertContainerBuilderHasParameter('tactician.method_inflector.bus_2', 'tactician.handler.method_name_inflector.handle'); |
66
|
|
|
$this->assertContainerBuilderHasAlias('tactician.commandbus', 'tactician.commandbus.bus_2'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function testCommandBusLoadsAndSetsCorrectMethodInflector() |
70
|
|
|
{ |
71
|
|
|
$this->load([ |
72
|
|
|
'commandbus' => [ |
73
|
|
|
'bus_1' => [ |
74
|
|
|
'middleware' => [ |
75
|
|
|
'my_middleware.custom.stuff', |
76
|
|
|
'tactician.middleware.command_handler', |
77
|
|
|
], |
78
|
|
|
'method_inflector' => 'my.inflector.service' |
79
|
|
|
], |
80
|
|
|
'bus_2' => [ |
81
|
|
|
'middleware' => [ |
82
|
|
|
'my_middleware.custom.stuff', |
83
|
|
|
'tactician.middleware.command_handler', |
84
|
|
|
] |
85
|
|
|
], |
86
|
|
|
], |
87
|
|
|
'default_bus' => 'bus_2' |
88
|
|
|
]); |
89
|
|
|
|
90
|
|
|
$this->assertContainerBuilderHasParameter('tactician.method_inflector.bus_1', 'my.inflector.service'); |
91
|
|
|
$this->assertContainerBuilderHasParameter('tactician.method_inflector.bus_2', 'tactician.handler.method_name_inflector.handle'); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function testCommandBusLoadsAndConfigures() |
95
|
|
|
{ |
96
|
|
|
$middlewares = [ |
97
|
|
|
new Reference('my_middleware.custom.stuff'), |
98
|
|
|
new Reference('tactician.middleware.command_handler') |
99
|
|
|
]; |
100
|
|
|
|
101
|
|
|
$this->load([ |
102
|
|
|
'commandbus' => [ |
103
|
|
|
'bus_1' => [ |
104
|
|
|
'middleware' => [ |
105
|
|
|
'my_middleware.custom.stuff', |
106
|
|
|
'tactician.middleware.command_handler', |
107
|
|
|
] |
108
|
|
|
], |
109
|
|
|
'bus_2' => [ |
110
|
|
|
'middleware' => [ |
111
|
|
|
'my_middleware.custom.stuff', |
112
|
|
|
'tactician.middleware.command_handler', |
113
|
|
|
] |
114
|
|
|
], |
115
|
|
|
], |
116
|
|
|
'default_bus' => 'bus_2' |
117
|
|
|
]); |
118
|
|
|
|
119
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithArgument('tactician.commandbus.bus_1', 0, $middlewares); |
120
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithArgument('tactician.commandbus.bus_2', 0, $middlewares); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function testCommandBusLoadingDefault() |
124
|
|
|
{ |
125
|
|
|
$this->load(); |
126
|
|
|
$this->assertContainerBuilderHasService('tactician.commandbus.default'); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function testLoadSecurityConfiguration() |
130
|
|
|
{ |
131
|
|
|
$securitySettings = ['Some\Command' => ['ROLE_USER'], 'Some\Other\Command' => ['ROLE_ADMIN']]; |
132
|
|
|
|
133
|
|
|
$this->load([ |
134
|
|
|
'commandbus' => [ |
135
|
|
|
'default' => [ |
136
|
|
|
'middleware' => [ |
137
|
|
|
'tactician.middleware.security', |
138
|
|
|
'tactician.middleware.command_handler', |
139
|
|
|
] |
140
|
|
|
] |
141
|
|
|
], |
142
|
|
|
'security' => $securitySettings |
143
|
|
|
]); |
144
|
|
|
|
145
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithArgument('tactician.middleware.security_voter', 1, $securitySettings); |
146
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithTag('tactician.middleware.security_voter', 'security.voter'); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
public function testDefaultSecurityConfigurationIsAllowNothing() |
150
|
|
|
{ |
151
|
|
|
$this->load([ |
152
|
|
|
'commandbus' => [ |
153
|
|
|
'default' => [ |
154
|
|
|
'middleware' => [ |
155
|
|
|
'tactician.middleware.security', |
156
|
|
|
'tactician.middleware.command_handler', |
157
|
|
|
] |
158
|
|
|
] |
159
|
|
|
] |
160
|
|
|
]); |
161
|
|
|
|
162
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithArgument('tactician.middleware.security_voter', 1, []); |
163
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithTag('tactician.middleware.security_voter', 'security.voter'); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
public function testVoterIsNotLoadedWithoutSecurityMiddleware() |
167
|
|
|
{ |
168
|
|
|
$this->load(); |
169
|
|
|
|
170
|
|
|
$this->assertContainerBuilderNotHasService('tactician.middleware.security_voter'); |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
|