@@ -21,16 +21,16 @@ class GuardListenerTest extends TestCase
2121 private $ authenticationChecker ;
2222 private $ validator ;
2323 private $ listener ;
24- private $ transition ;
24+ private $ configuration ;
2525
2626 protected function setUp ()
2727 {
28- $ configuration = array (
28+ $ this -> configuration = array (
2929 'test_is_granted ' => 'is_granted("something") ' ,
3030 'test_is_valid ' => 'is_valid(subject) ' ,
3131 'test_expression ' => array (
32- new GuardExpression ($ this -> getTransition ( true ), '!is_valid(subject) ' ),
33- new GuardExpression ($ this -> getTransition ( true ), 'is_valid(subject) ' ),
32+ new GuardExpression (new Transition ( ' name ' , ' from ' , ' to ' ), '!is_valid(subject) ' ),
33+ new GuardExpression (new Transition ( ' name ' , ' from ' , ' to ' ), 'is_valid(subject) ' ),
3434 ),
3535 );
3636 $ expressionLanguage = new ExpressionLanguage ();
@@ -41,7 +41,7 @@ protected function setUp()
4141 $ this ->authenticationChecker = $ this ->getMockBuilder (AuthorizationCheckerInterface::class)->getMock ();
4242 $ trustResolver = $ this ->getMockBuilder (AuthenticationTrustResolverInterface::class)->getMock ();
4343 $ this ->validator = $ this ->getMockBuilder (ValidatorInterface::class)->getMock ();
44- $ this ->listener = new GuardListener ($ configuration , $ expressionLanguage , $ tokenStorage , $ this ->authenticationChecker , $ trustResolver , null , $ this ->validator );
44+ $ this ->listener = new GuardListener ($ this -> configuration , $ expressionLanguage , $ tokenStorage , $ this ->authenticationChecker , $ trustResolver , null , $ this ->validator );
4545 }
4646
4747 protected function tearDown ()
@@ -104,16 +104,16 @@ public function testWithValidatorSupportedEventAndAccept()
104104
105105 public function testWithGuardExpressionWithNotSupportedTransition ()
106106 {
107- $ event = $ this ->createEvent (true );
108- $ this ->configureValidator (false , false );
107+ $ event = $ this ->createEvent ();
108+ $ this ->configureValidator (false );
109109 $ this ->listener ->onTransition ($ event , 'test_expression ' );
110110
111111 $ this ->assertFalse ($ event ->isBlocked ());
112112 }
113113
114114 public function testWithGuardExpressionWithSupportedTransition ()
115115 {
116- $ event = $ this ->createEvent ();
116+ $ event = $ this ->createEvent ($ this -> configuration [ ' test_expression ' ][ 1 ]-> getTransition () );
117117 $ this ->configureValidator (true , true );
118118 $ this ->listener ->onTransition ($ event , 'test_expression ' );
119119
@@ -122,18 +122,18 @@ public function testWithGuardExpressionWithSupportedTransition()
122122
123123 public function testGuardExpressionBlocks ()
124124 {
125- $ event = $ this ->createEvent ();
125+ $ event = $ this ->createEvent ($ this -> configuration [ ' test_expression ' ][ 1 ]-> getTransition () );
126126 $ this ->configureValidator (true , false );
127127 $ this ->listener ->onTransition ($ event , 'test_expression ' );
128128
129129 $ this ->assertTrue ($ event ->isBlocked ());
130130 }
131131
132- private function createEvent ($ newTransition = false )
132+ private function createEvent (Transition $ transition = null )
133133 {
134134 $ subject = new \stdClass ();
135135 $ subject ->marking = new Marking ();
136- $ transition = $ this -> getTransition ( $ newTransition );
136+ $ transition = $ transition ?: new Transition ( ' name ' , ' from ' , ' to ' );
137137
138138 return new GuardEvent ($ subject , $ subject ->marking , $ transition );
139139 }
@@ -173,13 +173,4 @@ private function configureValidator($isUsed, $valid = true)
173173 ->willReturn ($ valid ? array () : array ('a violation ' ))
174174 ;
175175 }
176-
177- private function getTransition ($ new = false )
178- {
179- if ($ new || !$ this ->transition ) {
180- $ this ->transition = new Transition ('name ' , 'from ' , 'to ' );
181- }
182-
183- return $ this ->transition ;
184- }
185176}
0 commit comments