summaryrefslogtreecommitdiff
path: root/vendor/symfony/debug/Tests/ExceptionHandlerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/symfony/debug/Tests/ExceptionHandlerTest.php')
-rw-r--r--vendor/symfony/debug/Tests/ExceptionHandlerTest.php66
1 files changed, 48 insertions, 18 deletions
diff --git a/vendor/symfony/debug/Tests/ExceptionHandlerTest.php b/vendor/symfony/debug/Tests/ExceptionHandlerTest.php
index 4910fe5ec9..3a9af8b6b8 100644
--- a/vendor/symfony/debug/Tests/ExceptionHandlerTest.php
+++ b/vendor/symfony/debug/Tests/ExceptionHandlerTest.php
@@ -85,7 +85,7 @@ content="0;url=data:text/html;base64,PHNjcmlwdD5hbGVydCgndGVzdDMnKTwvc2NyaXB0Pg"
ob_start();
$handler->sendPhpResponse(new MethodNotAllowedHttpException(['POST']));
- $response = ob_get_clean();
+ ob_get_clean();
$expectedHeaders = [
['HTTP/1.0 405', true, null],
@@ -108,35 +108,65 @@ content="0;url=data:text/html;base64,PHNjcmlwdD5hbGVydCgndGVzdDMnKTwvc2NyaXB0Pg"
public function testHandle()
{
- $exception = new \Exception('foo');
+ $handler = new ExceptionHandler(true);
+ ob_start();
- $handler = $this->getMockBuilder('Symfony\Component\Debug\ExceptionHandler')->setMethods(['sendPhpResponse'])->getMock();
- $handler
- ->expects($this->exactly(2))
- ->method('sendPhpResponse');
+ $handler->handle(new \Exception('foo'));
- $handler->handle($exception);
+ $this->assertThatTheExceptionWasOutput(ob_get_clean(), \Exception::class, 'Exception', 'foo');
+ }
- $handler->setHandler(function ($e) use ($exception) {
- $this->assertSame($exception, $e);
+ public function testHandleWithACustomHandlerThatOutputsSomething()
+ {
+ $handler = new ExceptionHandler(true);
+ ob_start();
+ $handler->setHandler(function () {
+ echo 'ccc';
});
- $handler->handle($exception);
+ $handler->handle(new \Exception());
+ ob_end_flush(); // Necessary because of this PHP bug : https://bugs.php.net/bug.php?id=76563
+ $this->assertSame('ccc', ob_get_clean());
}
- public function testHandleOutOfMemoryException()
+ public function testHandleWithACustomHandlerThatOutputsNothing()
+ {
+ $handler = new ExceptionHandler(true);
+ $handler->setHandler(function () {});
+
+ $handler->handle(new \Exception('ccc'));
+
+ $this->assertThatTheExceptionWasOutput(ob_get_clean(), \Exception::class, 'Exception', 'ccc');
+ }
+
+ public function testHandleWithACustomHandlerThatFails()
{
- $exception = new OutOfMemoryException('foo', 0, E_ERROR, __FILE__, __LINE__);
+ $handler = new ExceptionHandler(true);
+ $handler->setHandler(function () {
+ throw new \RuntimeException();
+ });
- $handler = $this->getMockBuilder('Symfony\Component\Debug\ExceptionHandler')->setMethods(['sendPhpResponse'])->getMock();
- $handler
- ->expects($this->once())
- ->method('sendPhpResponse');
+ $handler->handle(new \Exception('ccc'));
- $handler->setHandler(function ($e) {
+ $this->assertThatTheExceptionWasOutput(ob_get_clean(), \Exception::class, 'Exception', 'ccc');
+ }
+
+ public function testHandleOutOfMemoryException()
+ {
+ $handler = new ExceptionHandler(true);
+ ob_start();
+ $handler->setHandler(function () {
$this->fail('OutOfMemoryException should bypass the handler');
});
- $handler->handle($exception);
+ $handler->handle(new OutOfMemoryException('foo', 0, E_ERROR, __FILE__, __LINE__));
+
+ $this->assertThatTheExceptionWasOutput(ob_get_clean(), OutOfMemoryException::class, 'OutOfMemoryException', 'foo');
+ }
+
+ private function assertThatTheExceptionWasOutput($content, $expectedClass, $expectedTitle, $expectedMessage)
+ {
+ $this->assertContains(sprintf('<span class="exception_title"><abbr title="%s">%s</abbr></span>', $expectedClass, $expectedTitle), $content);
+ $this->assertContains(sprintf('<p class="break-long-words trace-message">%s</p>', $expectedMessage), $content);
}
}