'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:----wbIhMV+EN1nDKW43mKwnJDmQcz8mr6XoDsT0RXlDVP+Cjs+EZgO/FBnwHdhcyfmLOuB/J9Hx4Yv9RCvw6OPpETITe8DWHugNfrRvkLEYumMxui1zW98iv4lpAX/I3qi2T9aoWm7DATP6OAq80mnCCDC9/m6wv36OiC3pXoBHSNYGK51QVMut50CfUQ1hNSDQlchNupmuNjFJy80XOrM6es8py3F6CvMk0PXJzzAaGi3uzOLtH6Wdvc7dka/b6ouVwFF9JUm4B9u3rjZAktwlPNwT5YWlU61pqbazBKQiRiT0LRj1/PsmNiNYe/bT+atOhogshLkCbaQIiHPM21m6eeVEl6pvlYmlhxVvQrLkLEkRlWSf77FrtUZOFiUGn9Y3VGbvJIG+XgVPG9aSvJlWu1+MUCuMSAcnriFBnJn8VTkIBa/PHLl/L6dL3QAHNFbz/wSsEVoGU2SqX+u3Jth2OJVtboFyaec1RFIzO2Ie9Sds6bpltgf4ydpTYfMOKkSP8y6H+rH4VOeujeyvsy5P2KJ17IWT+j9pX+c563zMcG371ConSrF31RcOP7FiOEA40CnUeLaadMfa7ibelVnleAQ4dRcKaBkgLh0q671H15SoS1U9tsP2XTYkSOekNoHjH5ZRQTMibUB1CJEXGpXO9+KN8CRa/L3+w9CzprNXBT8=----ATTACHMENT:----NTM4NTYwMzA0NTUzNzU1NCA3MzQ4NTY0MjYwMTM3NDEyIDI1OTIyMDYzNzA2OTg4NTU=