/**
  * @param Request $request
  * @param array   $formats
  */
 private function doTestUnauthorizedHttpExceptionHasCorrectChallenge(Request $request, array $formats)
 {
     $exception = new AuthenticationException();
     $event = new GetResponseForExceptionEvent(new TestKernel(), $request, 'foo', $exception);
     $listener = new AccessDeniedListener($formats, 'Basic realm="Restricted Area"', 'foo');
     // store the current error_log, and disable it temporarily
     $errorLog = ini_set('error_log', file_exists('/dev/null') ? '/dev/null' : 'nul');
     $listener->onKernelException($event);
     // restore the old error_log
     ini_set('error_log', $errorLog);
     $this->assertInstanceOf('Symfony\\Component\\HttpKernel\\Exception\\UnauthorizedHttpException', $event->getException());
     $this->assertEquals(401, $event->getException()->getStatusCode());
     $this->assertEquals('You are not authenticated', $event->getException()->getMessage());
     $headers = $event->getException()->getHeaders();
     $this->assertEquals('Basic realm="Restricted Area"', $headers['WWW-Authenticate']);
 }
 /**
  * @param Request $request
  * @param array $formats
  */
 private function doTestAuthenticationExceptionIsConvertedToAnHttpExceptionForRequest(Request $request, array $formats)
 {
     $exception = new AuthenticationException();
     $event = new GetResponseForExceptionEvent(new TestKernel(), $request, 'foo', $exception);
     $listener = new AccessDeniedListener($formats, 'foo');
     // store the current error_log, and disable it temporarily
     $errorLog = ini_set('error_log', file_exists('/dev/null') ? '/dev/null' : 'nul');
     $listener->onKernelException($event);
     // restore the old error_log
     ini_set('error_log', $errorLog);
     $this->assertInstanceOf('Symfony\\Component\\HttpKernel\\Exception\\HttpException', $event->getException());
     $this->assertEquals(401, $event->getException()->getStatusCode());
     $this->assertEquals('You are not authenticated', $event->getException()->getMessage());
 }