14
14
use PHPUnit \Framework \TestCase ;
15
15
use Symfony \Bundle \FrameworkBundle \DependencyInjection \Compiler \WorkflowGuardListenerPass ;
16
16
use Symfony \Component \DependencyInjection \ContainerBuilder ;
17
- use Symfony \Component \DependencyInjection \Exception \LogicException ;
18
17
use Symfony \Component \Security \Core \Authentication \AuthenticationTrustResolverInterface ;
19
18
use Symfony \Component \Security \Core \Authentication \Token \Storage \TokenStorageInterface ;
20
19
use Symfony \Component \Security \Core \Authorization \AuthorizationCheckerInterface ;
21
20
use Symfony \Component \Security \Core \Role \RoleHierarchy ;
22
- use Symfony \Component \Workflow \ EventListener \ GuardListener ;
21
+ use Symfony \Component \Validator \ Validator \ ValidatorInterface ;
23
22
24
23
class WorkflowGuardListenerPassTest extends TestCase
25
24
{
@@ -29,53 +28,37 @@ class WorkflowGuardListenerPassTest extends TestCase
29
28
protected function setUp ()
30
29
{
31
30
$ this ->container = new ContainerBuilder ();
32
- $ this ->container ->register ('foo.listener.guard ' , GuardListener::class);
33
- $ this ->container ->register ('bar.listener.guard ' , GuardListener::class);
34
31
$ this ->compilerPass = new WorkflowGuardListenerPass ();
35
32
}
36
33
37
- public function testListenersAreNotRemovedIfParameterIsNotSet ()
34
+ public function testNoExeptionIfParameterIsNotSet ()
38
35
{
39
36
$ this ->compilerPass ->process ($ this ->container );
40
37
41
- $ this ->assertTrue ($ this ->container ->hasDefinition ('foo.listener.guard ' ));
42
- $ this ->assertTrue ($ this ->container ->hasDefinition ('bar.listener.guard ' ));
43
- }
44
-
45
- public function testParameterIsRemovedWhenThePassIsProcessed ()
46
- {
47
- $ this ->container ->setParameter ('workflow.has_guard_listeners ' , array ('foo.listener.guard ' , 'bar.listener.guard ' ));
48
-
49
- try {
50
- $ this ->compilerPass ->process ($ this ->container );
51
- } catch (LogicException $ e ) {
52
- // Here, we are not interested in the exception handling. This is tested further down.
53
- }
54
-
55
38
$ this ->assertFalse ($ this ->container ->hasParameter ('workflow.has_guard_listeners ' ));
56
39
}
57
40
58
- public function testListenersAreNotRemovedIfAllDependenciesArePresent ()
41
+ public function testNoExeptionIfAllDependenciesArePresent ()
59
42
{
60
- $ this ->container ->setParameter ('workflow.has_guard_listeners ' , array ( ' foo.listener.guard ' , ' bar.listener.guard ' ) );
43
+ $ this ->container ->setParameter ('workflow.has_guard_listeners ' , true );
61
44
$ this ->container ->register ('security.token_storage ' , TokenStorageInterface::class);
62
45
$ this ->container ->register ('security.authorization_checker ' , AuthorizationCheckerInterface::class);
63
46
$ this ->container ->register ('security.authentication.trust_resolver ' , AuthenticationTrustResolverInterface::class);
64
47
$ this ->container ->register ('security.role_hierarchy ' , RoleHierarchy::class);
48
+ $ this ->container ->register ('validator ' , ValidatorInterface::class);
65
49
66
50
$ this ->compilerPass ->process ($ this ->container );
67
51
68
- $ this ->assertTrue ($ this ->container ->hasDefinition ('foo.listener.guard ' ));
69
- $ this ->assertTrue ($ this ->container ->hasDefinition ('bar.listener.guard ' ));
52
+ $ this ->assertFalse ($ this ->container ->hasParameter ('workflow.has_guard_listeners ' ));
70
53
}
71
54
72
55
/**
73
56
* @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException
74
57
* @expectedExceptionMessage The "security.token_storage" service is needed to be able to use the workflow guard listener.
75
58
*/
76
- public function testListenersAreRemovedIfTheTokenStorageServiceIsNotPresent ()
59
+ public function testExceptionIfTheTokenStorageServiceIsNotPresent ()
77
60
{
78
- $ this ->container ->setParameter ('workflow.has_guard_listeners ' , array ( ' foo.listener.guard ' , ' bar.listener.guard ' ) );
61
+ $ this ->container ->setParameter ('workflow.has_guard_listeners ' , true );
79
62
$ this ->container ->register ('security.authorization_checker ' , AuthorizationCheckerInterface::class);
80
63
$ this ->container ->register ('security.authentication.trust_resolver ' , AuthenticationTrustResolverInterface::class);
81
64
$ this ->container ->register ('security.role_hierarchy ' , RoleHierarchy::class);
@@ -87,9 +70,9 @@ public function testListenersAreRemovedIfTheTokenStorageServiceIsNotPresent()
87
70
* @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException
88
71
* @expectedExceptionMessage The "security.authorization_checker" service is needed to be able to use the workflow guard listener.
89
72
*/
90
- public function testListenersAreRemovedIfTheAuthorizationCheckerServiceIsNotPresent ()
73
+ public function testExceptionIfTheAuthorizationCheckerServiceIsNotPresent ()
91
74
{
92
- $ this ->container ->setParameter ('workflow.has_guard_listeners ' , array ( ' foo.listener.guard ' , ' bar.listener.guard ' ) );
75
+ $ this ->container ->setParameter ('workflow.has_guard_listeners ' , true );
93
76
$ this ->container ->register ('security.token_storage ' , TokenStorageInterface::class);
94
77
$ this ->container ->register ('security.authentication.trust_resolver ' , AuthenticationTrustResolverInterface::class);
95
78
$ this ->container ->register ('security.role_hierarchy ' , RoleHierarchy::class);
@@ -101,9 +84,9 @@ public function testListenersAreRemovedIfTheAuthorizationCheckerServiceIsNotPres
101
84
* @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException
102
85
* @expectedExceptionMessage The "security.authentication.trust_resolver" service is needed to be able to use the workflow guard listener.
103
86
*/
104
- public function testListenersAreRemovedIfTheAuthenticationTrustResolverServiceIsNotPresent ()
87
+ public function testExceptionIfTheAuthenticationTrustResolverServiceIsNotPresent ()
105
88
{
106
- $ this ->container ->setParameter ('workflow.has_guard_listeners ' , array ( ' foo.listener.guard ' , ' bar.listener.guard ' ) );
89
+ $ this ->container ->setParameter ('workflow.has_guard_listeners ' , true );
107
90
$ this ->container ->register ('security.token_storage ' , TokenStorageInterface::class);
108
91
$ this ->container ->register ('security.authorization_checker ' , AuthorizationCheckerInterface::class);
109
92
$ this ->container ->register ('security.role_hierarchy ' , RoleHierarchy::class);
@@ -115,12 +98,27 @@ public function testListenersAreRemovedIfTheAuthenticationTrustResolverServiceIs
115
98
* @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException
116
99
* @expectedExceptionMessage The "security.role_hierarchy" service is needed to be able to use the workflow guard listener.
117
100
*/
118
- public function testListenersAreRemovedIfTheRoleHierarchyServiceIsNotPresent ()
101
+ public function testExceptionIfTheRoleHierarchyServiceIsNotPresent ()
102
+ {
103
+ $ this ->container ->setParameter ('workflow.has_guard_listeners ' , true );
104
+ $ this ->container ->register ('security.token_storage ' , TokenStorageInterface::class);
105
+ $ this ->container ->register ('security.authorization_checker ' , AuthorizationCheckerInterface::class);
106
+ $ this ->container ->register ('security.authentication.trust_resolver ' , AuthenticationTrustResolverInterface::class);
107
+
108
+ $ this ->compilerPass ->process ($ this ->container );
109
+ }
110
+
111
+ /**
112
+ * @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException
113
+ * The "validator" service is needed to be able to use the workflow guard listener.
114
+ */
115
+ public function testExceptionIfTheValidatorIsNotPresent ()
119
116
{
120
- $ this ->container ->setParameter ('workflow.has_guard_listeners ' , array ( ' foo.listener.guard ' , ' bar.listener.guard ' ) );
117
+ $ this ->container ->setParameter ('workflow.has_guard_listeners ' , true );
121
118
$ this ->container ->register ('security.token_storage ' , TokenStorageInterface::class);
122
119
$ this ->container ->register ('security.authorization_checker ' , AuthorizationCheckerInterface::class);
123
120
$ this ->container ->register ('security.authentication.trust_resolver ' , AuthenticationTrustResolverInterface::class);
121
+ $ this ->container ->register ('security.role_hierarchy ' , RoleHierarchy::class);
124
122
125
123
$ this ->compilerPass ->process ($ this ->container );
126
124
}
0 commit comments