* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Debug\Tests; use PHPUnit\Framework\TestCase; use Symfony\Component\Debug\ExceptionHandler; use Symfony\Component\Debug\Exception\OutOfMemoryException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; require_once __DIR__.'/HeaderMock.php'; class ExceptionHandlerTest extends TestCase { protected function setUp() { testHeader(); } protected function tearDown() { testHeader(); } public function testDebug() { $handler = new ExceptionHandler(false); ob_start(); $handler->sendPhpResponse(new \RuntimeException('Foo')); $response = ob_get_clean(); $this->assertContains('Whoops, looks like something went wrong.', $response); $this->assertNotContains('
', $response); $handler = new ExceptionHandler(true); ob_start(); $handler->sendPhpResponse(new \RuntimeException('Foo')); $response = ob_get_clean(); $this->assertContains('Whoops, looks like something went wrong.', $response); $this->assertContains('
', $response); } public function testStatusCode() { $handler = new ExceptionHandler(false, 'iso8859-1'); ob_start(); $handler->sendPhpResponse(new NotFoundHttpException('Foo')); $response = ob_get_clean(); $this->assertContains('Sorry, the page you are looking for could not be found.', $response); $expectedHeaders = array( array('HTTP/1.0 404', true, null), array('Content-Type: text/html; charset=iso8859-1', true, null), ); $this->assertSame($expectedHeaders, testHeader()); } public function testHeaders() { $handler = new ExceptionHandler(false, 'iso8859-1'); ob_start(); $handler->sendPhpResponse(new MethodNotAllowedHttpException(array('POST'))); $response = ob_get_clean(); $expectedHeaders = array( array('HTTP/1.0 405', true, null), array('Allow: POST', false, null), array('Content-Type: text/html; charset=iso8859-1', true, null), ); $this->assertSame($expectedHeaders, testHeader()); } public function testNestedExceptions() { $handler = new ExceptionHandler(true); ob_start(); $handler->sendPhpResponse(new \RuntimeException('Foo', 0, new \RuntimeException('Bar'))); $response = ob_get_clean(); $this->assertStringMatchesFormat('%A

Foo

%A

Bar

%A', $response); } public function testHandle() { $exception = new \Exception('foo'); $handler = $this->getMockBuilder('Symfony\Component\Debug\ExceptionHandler')->setMethods(array('sendPhpResponse'))->getMock(); $handler ->expects($this->exactly(2)) ->method('sendPhpResponse'); $handler->handle($exception); $handler->setHandler(function ($e) use ($exception) { $this->assertSame($exception, $e); }); $handler->handle($exception); } public function testHandleOutOfMemoryException() { $exception = new OutOfMemoryException('foo', 0, E_ERROR, __FILE__, __LINE__); $handler = $this->getMockBuilder('Symfony\Component\Debug\ExceptionHandler')->setMethods(array('sendPhpResponse'))->getMock(); $handler ->expects($this->once()) ->method('sendPhpResponse'); $handler->setHandler(function ($e) { $this->fail('OutOfMemoryException should bypass the handler'); }); $handler->handle($exception); } } __halt_compiler();----SIGNATURE:----O/2u2k/qBLu3LpYl1++D//h1xuznNFryuXeuqb9RE96SXoGQoMQs5jMZapaIrG1agNXqmdYgV9TA+L6DFnVB4Q/QpHpaTJznl/ZuKYh5eWxR6fLJWuz8FtNgoxsZBPh10GGvnyRxSIy4ecU5BXd0FwEyS/JE2iCug8/cfFrfBMZViJRPaRyd0RN3QhX5V+anWJnOExcE72Hzqn5vpbk7nMOkjXM7Tl9854yT7alZeDVUsgkYOpu4Zv5Bqthy4Vxhfh79HqXyt5q7Gr2BuuDaqXRG7yzjSSCgDzinCcqTCCbXIIuR6Zv3eNO5+A+VesuI70Zn4SKQrGO0nQEsuHWM6AdN5Yli0PoVR4GCQD6faQWblCbN2dsBAh6Uz17hjiV0ptHjMw3ZOoQeNG8PZRXnu7lnV2f25AlGfzXRATb3UX71qbK+S2C+uTD3moGRw01wP5/rupdTY66Mjh6vo+w9Ils1vYrFa1kRfIk7SQEduIYa7355/oqxNaZbueWIRbO9i2GOyt/+29ZmRYagUwmYuj+tXAxWIXEJszzAEpU8W1L3rAkGStJnj5Hz5n4dpJmzny9UhBNGz86IZ/v1X3wyRKLCal5tsiWoVwzGj43KUNILqHvRigmvWNQa47XF2nsO/gsoImYFbyKXF5+xuWfOb1dGVCnoQPX53rBt4WliXZs=----ATTACHMENT:----MTAxNzUyNTUwMjAwMDY3MyAzMzU0OTEzOTcyMDU0NjA4IDYyNTE4ODE2MDUwMzM3MzQ=