class ExceptionHandlerTest

Hierarchy

  • class \Symfony\Component\Debug\Tests\ExceptionHandlerTest extends \Symfony\Component\Debug\Tests\PHPUnit_Framework_TestCase

Expanded class hierarchy of ExceptionHandlerTest

File

drupal/core/vendor/symfony/debug/Symfony/Component/Debug/Tests/ExceptionHandlerTest.php, line 18

Namespace

Symfony\Component\Debug\Tests
View source
class ExceptionHandlerTest extends \PHPUnit_Framework_TestCase {
  protected function setUp() {
    if (!class_exists('Symfony\\Component\\HttpFoundation\\Request')) {
      $this
        ->markTestSkipped('The "HttpFoundation" component is not available');
    }
  }
  public function testDebug() {
    $handler = new ExceptionHandler(false);
    $response = $handler
      ->createResponse(new \RuntimeException('Foo'));
    $this
      ->assertContains('<h1>Whoops, looks like something went wrong.</h1>', $response
      ->getContent());
    $this
      ->assertNotContains('<div class="block_exception clear_fix">', $response
      ->getContent());
    $handler = new ExceptionHandler(true);
    $response = $handler
      ->createResponse(new \RuntimeException('Foo'));
    $this
      ->assertContains('<h1>Whoops, looks like something went wrong.</h1>', $response
      ->getContent());
    $this
      ->assertContains('<div class="block_exception clear_fix">', $response
      ->getContent());
  }
  public function testStatusCode() {
    $handler = new ExceptionHandler(false);
    $response = $handler
      ->createResponse(new \RuntimeException('Foo'));
    $this
      ->assertEquals('500', $response
      ->getStatusCode());
    $this
      ->assertContains('Whoops, looks like something went wrong.', $response
      ->getContent());
    $response = $handler
      ->createResponse(new NotFoundHttpException('Foo'));
    $this
      ->assertEquals('404', $response
      ->getStatusCode());
    $this
      ->assertContains('Sorry, the page you are looking for could not be found.', $response
      ->getContent());
  }
  public function testHeaders() {
    $handler = new ExceptionHandler(false);
    $response = $handler
      ->createResponse(new MethodNotAllowedHttpException(array(
      'POST',
    )));
    $this
      ->assertEquals('405', $response
      ->getStatusCode());
    $this
      ->assertEquals('POST', $response->headers
      ->get('Allow'));
  }
  public function testNestedExceptions() {
    $handler = new ExceptionHandler(true);
    $response = $handler
      ->createResponse(new \RuntimeException('Foo', null, new \RuntimeException('Bar')));
  }

}

Members