1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace League\Tactician\Bundle\Tests\DependencyInjection; |
5
|
|
|
|
6
|
|
|
use League\Tactician\Bundle\DependencyInjection\Configuration; |
7
|
|
|
use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
|
10
|
|
|
class ConfigurationTest extends TestCase |
11
|
|
|
{ |
12
|
|
|
use ConfigurationTestCaseTrait; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Return the instance of ConfigurationInterface that should be used by the |
16
|
|
|
* Configuration-specific assertions in this test-case |
17
|
|
|
* |
18
|
|
|
* @return \Symfony\Component\Config\Definition\ConfigurationInterface |
19
|
|
|
*/ |
20
|
|
|
protected function getConfiguration() |
21
|
|
|
{ |
22
|
|
|
return new Configuration(); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testBlankConfiguration() |
26
|
|
|
{ |
27
|
|
|
$this->assertConfigurationIsValid([]); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testDefaultConfiguration() |
31
|
|
|
{ |
32
|
|
|
$this->assertProcessedConfigurationEquals( |
33
|
|
|
[], |
34
|
|
|
[ |
35
|
|
|
'commandbus' => ['default' => ['middleware' => ['tactician.middleware.command_handler']]], |
36
|
|
|
'default_bus' => 'default', |
37
|
|
|
'method_inflector' => 'tactician.handler.method_name_inflector.handle', |
38
|
|
|
'security' => [], |
39
|
|
|
] |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testSimpleMiddleware() |
44
|
|
|
{ |
45
|
|
|
$this->assertConfigurationIsValid([ |
46
|
|
|
'tactician' => [ |
47
|
|
|
'commandbus' => [ |
48
|
|
|
'default' => [ |
49
|
|
|
'middleware' => [ |
50
|
|
|
'my_middleware' => 'some_middleware', |
51
|
|
|
'my_middleware2' => 'some_middleware', |
52
|
|
|
] |
53
|
|
|
] |
54
|
|
|
] |
55
|
|
|
] |
56
|
|
|
]); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testMiddlewareMustBeScalar() |
60
|
|
|
{ |
61
|
|
|
$this->assertConfigurationIsInvalid( |
62
|
|
|
[ |
63
|
|
|
'tactician' => [ |
64
|
|
|
'commandbus' => [ |
65
|
|
|
'default' => [ |
66
|
|
|
'middleware' => [ |
67
|
|
|
'my_middleware' => [], |
68
|
|
|
'my_middleware2' => 'some_middleware', |
69
|
|
|
] |
70
|
|
|
] |
71
|
|
|
] |
72
|
|
|
] |
73
|
|
|
], |
74
|
|
|
'Invalid type for path "tactician.commandbus.default.middleware.my_middleware". Expected scalar, but got array.' |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function testDefaultMiddlewareMustExist() |
79
|
|
|
{ |
80
|
|
|
$this->assertConfigurationIsInvalid( |
81
|
|
|
[ |
82
|
|
|
'tactician' => [ |
83
|
|
|
'default_bus' => 'foo', |
84
|
|
|
'commandbus' => [ |
85
|
|
|
'bar' => [ |
86
|
|
|
'middleware' => [ |
87
|
|
|
'my_middleware' => 'some_middleware', |
88
|
|
|
] |
89
|
|
|
] |
90
|
|
|
] |
91
|
|
|
] |
92
|
|
|
], |
93
|
|
|
'The default_bus "foo" was not defined as a command bus.' |
94
|
|
|
); |
95
|
|
|
|
96
|
|
|
$this->assertConfigurationIsInvalid( |
97
|
|
|
[ |
98
|
|
|
'tactician' => [ |
99
|
|
|
'commandbus' => [ |
100
|
|
|
'bar' => [ |
101
|
|
|
'middleware' => [ |
102
|
|
|
'my_middleware' => 'some_middleware', |
103
|
|
|
] |
104
|
|
|
] |
105
|
|
|
] |
106
|
|
|
] |
107
|
|
|
], |
108
|
|
|
'The default_bus "default" was not defined as a command bus.' |
109
|
|
|
); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function testMiddlewareDefinitionCannotBeEmpty() |
113
|
|
|
{ |
114
|
|
|
$this->assertConfigurationIsInvalid( |
115
|
|
|
[ |
116
|
|
|
'tactician' => [ |
117
|
|
|
'commandbus' => [ |
118
|
|
|
'default' => [ |
119
|
|
|
'middleware' => [ |
120
|
|
|
] |
121
|
|
|
] |
122
|
|
|
] |
123
|
|
|
] |
124
|
|
|
], |
125
|
|
|
'The path "tactician.commandbus.default.middleware" should have at least 1 element(s) defined.' |
126
|
|
|
); |
127
|
|
|
|
128
|
|
|
$this->assertConfigurationIsInvalid( |
129
|
|
|
[ |
130
|
|
|
'tactician' => [ |
131
|
|
|
'commandbus' => [ |
132
|
|
|
'foo' => [ |
133
|
|
|
'middleware' => [ |
134
|
|
|
] |
135
|
|
|
] |
136
|
|
|
] |
137
|
|
|
] |
138
|
|
|
], |
139
|
|
|
'The path "tactician.commandbus.foo.middleware" should have at least 1 element(s) defined.' |
140
|
|
|
); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public function testCommandHandlerMiddlewareIfPresentAndNotLastIsInvalid() |
144
|
|
|
{ |
145
|
|
|
$this->assertConfigurationIsInvalid( |
146
|
|
|
[ |
147
|
|
|
'tactician' => [ |
148
|
|
|
'commandbus' => [ |
149
|
|
|
'default' => [ |
150
|
|
|
'middleware' => [ |
151
|
|
|
'tactician.middleware.command_handler', |
152
|
|
|
'my_middleware.custom.stuff', |
153
|
|
|
|
154
|
|
|
] |
155
|
|
|
] |
156
|
|
|
] |
157
|
|
|
] |
158
|
|
|
], |
159
|
|
|
'"tactician.middleware.command_handler" should be the last middleware loaded when it is used.' |
160
|
|
|
); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
public function testCommandHandlerMiddlewarePresentAndLastIsValid() |
164
|
|
|
{ |
165
|
|
|
$this->assertConfigurationIsValid( |
166
|
|
|
[ |
167
|
|
|
'tactician' => [ |
168
|
|
|
'commandbus' => [ |
169
|
|
|
'default' => [ |
170
|
|
|
'middleware' => [ |
171
|
|
|
'my_middleware.custom.stuff', |
172
|
|
|
'tactician.middleware.command_handler', |
173
|
|
|
] |
174
|
|
|
] |
175
|
|
|
] |
176
|
|
|
] |
177
|
|
|
] |
178
|
|
|
); |
179
|
|
|
} |
180
|
|
|
public function testCommandHandlerMiddlewareNotPresentDoesNotAffectValidation() |
181
|
|
|
{ |
182
|
|
|
$this->assertConfigurationIsValid( |
183
|
|
|
[ |
184
|
|
|
'tactician' => [ |
185
|
|
|
'commandbus' => [ |
186
|
|
|
'default' => [ |
187
|
|
|
'middleware' => [ |
188
|
|
|
'my_middleware.custom.stuff', |
189
|
|
|
'my_middleware.custom.other_stuff', |
190
|
|
|
] |
191
|
|
|
] |
192
|
|
|
] |
193
|
|
|
] |
194
|
|
|
] |
195
|
|
|
); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
public function testCustomMethodInflectorCanBeSet() |
199
|
|
|
{ |
200
|
|
|
$this->assertConfigurationIsValid( |
201
|
|
|
[ |
202
|
|
|
'tactician' => [ |
203
|
|
|
'method_inflector' => 'some.inflector.service', |
204
|
|
|
'commandbus' => [ |
205
|
|
|
'default' => [ |
206
|
|
|
'middleware' => [ |
207
|
|
|
'my_middleware.custom.stuff', |
208
|
|
|
'my_middleware.custom.other_stuff', |
209
|
|
|
], |
210
|
|
|
], |
211
|
|
|
'second' => [ |
212
|
|
|
'middleware' => [ |
213
|
|
|
'my_middleware.custom.stuff', |
214
|
|
|
'my_middleware.custom.other_stuff', |
215
|
|
|
] |
216
|
|
|
] |
217
|
|
|
] |
218
|
|
|
] |
219
|
|
|
] |
220
|
|
|
); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
public function testSecurityConfiguration() |
224
|
|
|
{ |
225
|
|
|
$this->assertConfigurationIsValid([ |
226
|
|
|
'tactician' => [ |
227
|
|
|
'commandbus' => [ |
228
|
|
|
'default' => [ |
229
|
|
|
'middleware' => [ |
230
|
|
|
'my_middleware' => 'some_middleware', |
231
|
|
|
'my_middleware2' => 'some_middleware', |
232
|
|
|
] |
233
|
|
|
] |
234
|
|
|
], |
235
|
|
|
'security' => [ |
236
|
|
|
'Some\Command' => ['ROLE_USER'], |
237
|
|
|
'Some\Other\Command' => ['ROLE_ADMIN'], |
238
|
|
|
] |
239
|
|
|
] |
240
|
|
|
]); |
241
|
|
|
} |
242
|
|
|
} |
243
|
|
|
|