コード例 #1
0
 /**
  * Test the not found exception rendering
  */
 public function testNotFoundException()
 {
     // GIVEN
     // mock exception
     $exception = $this->getMock('\\Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException');
     $exception->expects($this->any())->method('getStatusCode')->will($this->returnValue(404));
     $event = $this->getMockEvent($exception);
     // mock an error page
     $page = $this->getMock('Sonata\\PageBundle\\Model\\PageInterface');
     // mock cms manager to return the mock error page and set it as current page
     $this->cmsManager = $this->getMock('Sonata\\PageBundle\\CmsManager\\CmsManagerInterface');
     $this->cmsManager->expects($this->once())->method('getPageByRouteName')->with($this->anything(), $this->equalTo('route_404'))->will($this->returnValue($page));
     $this->cmsManager->expects($this->once())->method('setCurrentPage')->with($this->equalTo($page));
     $this->cmsSelector->expects($this->any())->method('retrieve')->will($this->returnValue($this->cmsManager));
     // mocked site selector should return a site
     $this->siteSelector->expects($this->any())->method('retrieve')->will($this->returnValue($this->getMock('Sonata\\PageBundle\\Model\\SiteInterface')));
     // mocked decorator strategy should allow decorate
     $this->decoratorStrategy->expects($this->any())->method('isRouteNameDecorable')->will($this->returnValue(true));
     $this->decoratorStrategy->expects($this->any())->method('isRouteUriDecorable')->will($this->returnValue(true));
     // mocked page service manager should execute the page and return a response
     $response = $this->getMock('Symfony\\Component\\HttpFoundation\\Response');
     $this->pageServiceManager->expects($this->once())->method('execute')->with($this->equalTo($page))->will($this->returnValue($response));
     // WHEN
     $this->listener->onKernelException($event);
     // THEN
     // mock asserts
 }
コード例 #2
0
 /**
  * Handles a kernel exception.
  *
  * @param GetResponseForExceptionEvent $event
  *
  * @throws \Exception
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if ($this->tokenStorage && $this->tokenStorage->getToken() && !$this->tokenStorage->getToken() instanceof \Symfony\Component\Security\Core\Authentication\Token\AnonymousToken && $this->tokenStorage->getToken()->getProviderKey() && $this->tokenStorage->getToken()->getProviderKey() === 'admin' && ($event->getException() instanceof AccessDeniedHttpException || $event->getException() instanceof AccessDeniedException)) {
         $this->handleAccessDeniedError($event);
     }
     parent::onKernelException($event);
 }