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\Definition; |
8
|
|
|
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; |
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(): array |
19
|
|
|
{ |
20
|
|
|
return [ |
21
|
|
|
new TacticianExtension() |
22
|
|
|
]; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testLoadSecurityConfiguration() |
26
|
|
|
{ |
27
|
|
|
$securitySettings = ['Some\Command' => ['ROLE_USER'], 'Some\Other\Command' => ['ROLE_ADMIN']]; |
28
|
|
|
|
29
|
|
|
$this->load([ |
30
|
|
|
'commandbus' => [ |
31
|
|
|
'default' => [ |
32
|
|
|
'middleware' => [ |
33
|
|
|
'tactician.middleware.security', |
34
|
|
|
'tactician.middleware.command_handler', |
35
|
|
|
] |
36
|
|
|
] |
37
|
|
|
], |
38
|
|
|
'security' => $securitySettings |
39
|
|
|
]); |
40
|
|
|
|
41
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithArgument('tactician.middleware.security_voter', 1, $securitySettings); |
42
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithTag('tactician.middleware.security_voter', 'security.voter'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testDefaultSecurityConfigurationIsAllowNothing() |
46
|
|
|
{ |
47
|
|
|
$this->load([ |
48
|
|
|
'commandbus' => [ |
49
|
|
|
'default' => [ |
50
|
|
|
'middleware' => [ |
51
|
|
|
'tactician.middleware.security', |
52
|
|
|
'tactician.middleware.command_handler', |
53
|
|
|
] |
54
|
|
|
] |
55
|
|
|
] |
56
|
|
|
]); |
57
|
|
|
|
58
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithArgument('tactician.middleware.security_voter', 1, []); |
59
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithTag('tactician.middleware.security_voter', 'security.voter'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testVoterIsNotLoadedWithoutSecurityMiddleware() |
63
|
|
|
{ |
64
|
|
|
$this->load(); |
65
|
|
|
|
66
|
|
|
$this->assertContainerBuilderNotHasService('tactician.middleware.security_voter'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function testLoggerMiddlewareIsCreated() |
70
|
|
|
{ |
71
|
|
|
$this->load(); |
72
|
|
|
|
73
|
|
|
$this->assertContainerBuilderHasService('tactician.middleware.logger'); |
74
|
|
|
$this->assertContainerBuilderHasService('tactician.logger.class_properties_formatter'); |
75
|
|
|
$this->assertContainerBuilderHasService('tactician.logger.class_name_formatter'); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|