public function visitMenuItem(MenuItem $item) { try { $request = $this->getClonedRequest($item->getUri()); $event = new GetResponseEvent($this->kernel, $request, HttpKernelInterface::MASTER_REQUEST); $this->accessListener->handle($event); } catch (AccessDeniedException $e) { $item->setDisplay(false); } catch (AuthenticationCredentialsNotFoundException $e) { } }
/** * @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException */ public function testHandleWhenTheSecurityTokenStorageHasNoToken() { $tokenStorage = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Authentication\\Token\\Storage\\TokenStorageInterface')->getMock(); $tokenStorage->expects($this->any())->method('getToken')->will($this->returnValue(null)); $listener = new AccessListener($tokenStorage, $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Authorization\\AccessDecisionManagerInterface')->getMock(), $this->getMockBuilder('Symfony\\Component\\Security\\Http\\AccessMapInterface')->getMock(), $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Authentication\\AuthenticationManagerInterface')->getMock()); $event = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent')->disableOriginalConstructor()->getMock(); $listener->handle($event); }
/** * @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException */ public function testHandleWhenTheSecurityContextHasNoToken() { $context = $this->getMock('Symfony\\Component\\Security\\Core\\SecurityContextInterface'); $context->expects($this->any())->method('getToken')->will($this->returnValue(null)); $listener = new AccessListener($context, $this->getMock('Symfony\\Component\\Security\\Core\\Authorization\\AccessDecisionManagerInterface'), $this->getMock('Symfony\\Component\\Security\\Http\\AccessMapInterface'), $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\AuthenticationManagerInterface')); $event = $this->getMock('Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent', array(), array(), '', false); $listener->handle($event); }