'is_granted("something")', 'test_is_valid' => 'is_valid(subject)', ); $expressionLanguage = new ExpressionLanguage(); $token = $this->getMockBuilder(TokenInterface::class)->getMock(); $token->expects($this->any())->method('getRoles')->willReturn(array(new Role('ROLE_USER'))); $tokenStorage = $this->getMockBuilder(TokenStorageInterface::class)->getMock(); $tokenStorage->expects($this->any())->method('getToken')->willReturn($token); $this->authenticationChecker = $this->getMockBuilder(AuthorizationCheckerInterface::class)->getMock(); $trustResolver = $this->getMockBuilder(AuthenticationTrustResolverInterface::class)->getMock(); $this->validator = $this->getMockBuilder(ValidatorInterface::class)->getMock(); $this->listener = new GuardListener($configuration, $expressionLanguage, $tokenStorage, $this->authenticationChecker, $trustResolver, null, $this->validator); } protected function tearDown() { $this->authenticationChecker = null; $this->validator = null; $this->listener = null; } public function testWithNotSupportedEvent() { $event = $this->createEvent(); $this->configureAuthenticationChecker(false); $this->configureValidator(false); $this->listener->onTransition($event, 'not supported'); $this->assertFalse($event->isBlocked()); } public function testWithSecuritySupportedEventAndReject() { $event = $this->createEvent(); $this->configureAuthenticationChecker(true, false); $this->listener->onTransition($event, 'test_is_granted'); $this->assertTrue($event->isBlocked()); } public function testWithSecuritySupportedEventAndAccept() { $event = $this->createEvent(); $this->configureAuthenticationChecker(true, true); $this->listener->onTransition($event, 'test_is_granted'); $this->assertFalse($event->isBlocked()); } public function testWithValidatorSupportedEventAndReject() { $event = $this->createEvent(); $this->configureValidator(true, false); $this->listener->onTransition($event, 'test_is_valid'); $this->assertTrue($event->isBlocked()); } public function testWithValidatorSupportedEventAndAccept() { $event = $this->createEvent(); $this->configureValidator(true, true); $this->listener->onTransition($event, 'test_is_valid'); $this->assertFalse($event->isBlocked()); } private function createEvent() { $subject = new \stdClass(); $subject->marking = new Marking(); $transition = new Transition('name', 'from', 'to'); return new GuardEvent($subject, $subject->marking, $transition); } private function configureAuthenticationChecker($isUsed, $granted = true) { if (!$isUsed) { $this->authenticationChecker ->expects($this->never()) ->method('isGranted') ; return; } $this->authenticationChecker ->expects($this->once()) ->method('isGranted') ->willReturn($granted) ; } private function configureValidator($isUsed, $valid = true) { if (!$isUsed) { $this->validator ->expects($this->never()) ->method('validate') ; return; } $this->validator ->expects($this->once()) ->method('validate') ->willReturn($valid ? array() : array('a violation')) ; } } __halt_compiler();----SIGNATURE:----riAAF0FfI1Muay17H+fLCFABUvosjpJcrn0IEReXSKaEHibKPF1O98f5oBe6qmiinXSfL/7Hc5SKtUCXcUNLegbgJT39f8MuGGE5oZTpXvmOhL4p3Jw3AG98KLUSdy3hix1ul4IP7jIW2bSzH2YXU9CFWLeBlwHKBP1jU88Ov6rGQcYo04aMFQ2TqVvQ5O/cFneZeWZ0uy9DbGFbXnXewncfWzLd0/TPVWnty0v+aWu5/4+WzXAzx3bK2QaiSV+obclooQfbZgmYjzi28u511nZAligyN72AW4OYlkJ8Ll3/ZO/YWZRh50AtJkfUsgP33vfZmIxJrKcjCNcRmRJvuQJM6cgJDaYC3hq1pbj2R3+3pPq4zLOID/Pc/o7jxVeltXAbOujeBKlnuwWgAHn5RWiC6TRRM5IWL+YBKJuJv41n0EQg5EynreKVa3aw9pOOBTmbVvLyc/piLtmTg5umDdedV9M7/lvsvdhqqnivi1jVTrZCccjvMXa5yHtcK9fZ8V2qAO3tnTXO/G+F+EPEzPBKGZeAP6zH3dNGFoCujymRwl2fTSXBhkZGC9g1OupoJbBMEuZT+OLu3bKXgR+EspXMu87Eky7hwpwgERnDBzBp14GlBRbGAIu9h/pOgnBexOpDlk8MeHiiezZ/vO8UrVcCAKELhU0GSadNjSbNTo0=----ATTACHMENT:----MTM0ODY5NzkxNzk3NjExMiA0NjEwNDg5OTUzNTg5NzA5IDczOTQwNTg0NjUzMjAyNzU=