'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:----Lb1ARCc21bZQUvj9lcjtdP0lt9dCPEA2Ua4P8WS1FJDMFcSzsNVYafiHapuQ3MfQ25hy9Ki+mo3R/RnSIUboCNG0VhdaKcd1MjJz+WzzCTMN4XsN/VKxp0opXUSGiTBrbQ6dBGUJko7oIUsa/auRHPQwrJaYWl5XVElZibc+lVxrMqUESuE8CNDGW9ibEfgFYpvf73q0f+kX3AjWGWFSplCsE6t4hLkpP9SVlbPj1R8sBWjqVMjW3DxbEiTElRKM8jmQ5edgrkwLfM3hg5Ji0iBtDOhh/aJao4GZuLZXlPcWeiWXGizOhjvfur3yfRHKEgOXmuYSxSdC+lfZNJVPIkqUA202M1lUU2mTqEbkXCxzXAAmywI40uxFotga0CDxl1xT0yHOvk+CTEcrBWle6AHGzUI1kpAduqcfYHlqWLYOBIzR5uGc4uWmIE14G9CibmRcRs6gUBmaJ6TLgGLGd1U+J1J/5mVcrTA41kQ15ezQeD1HRoi0Vdcxh9mY+rL/42DmnC0TXQ7+50dRf23totQABIFVK3+mDZoQC8bnoDbRbIbXskqvki3JphQpCIDK41a20pqbCcVochK6XHb900cnl9mru8DziDCLIQ58YkbNyxhvgI4feTcdJRfDVc3h9erMrRo2pga2/KiqwWjnjevNVenePWpXlI+gmsmJOto=----ATTACHMENT:----Nzk1OTg3ODk4MTM3NDMzMiAxODczNDg4NzQ3MDM4NzgyIDU1MDA1MzQ0OTQ1Mzg0