* * 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:----hgeIdfGnonyW4uJdFD1m52sGW8eIcgr0V2QwI5R92HRO6n06Z40i47QzCNL4AM7zWphxPmsmPWOw0+DawXqKXt0PN3kCvDBI8Q0IdRlPVFgz6PLapPT+U6JyWE949kkkitPyXGEht8p08UeE5A5034Rdlxg3RK3YhQfB72W0IHJOUPJ5PEMvtzZmCv37y9jzqqnWACsuKBvxW2bvnTVqfUV/nikMYbdazUTBN5Hz0XUeDKD2tVhPd1IWjrBj/MSEBI2ydU9CNVMnZ+802dazTZZV0yo/A8J7i/vkIwS0CynsprnPM3LNc8+hJMYQ0MINbBmYSapuk38CJufPGAKCKyHQh7xQnYtub3zHoH0arPPSF1ddrugp6hPKk6xRKgPQK/mtsiZw9xgR/E84YQZhqeYfj8EJgM8pSjFUDbniftSLEk71TOQvNXJhiKGd1KUsJ3Jt4k3soSLfbWPmcjP35gPjVSge8QoWZV88ZqgiUCEFS0Oa0LJbuLAL2mhkELkSS7ZJBga6deqCT72rQx32XSgFOZrhodPbVnJadiQWU2udQzFtnZ+XuOL8qMJ7fUlxztsqyKayQOYGwIE7zrctwbkyB0XygzM3SymnaO1cQpoqUbOGdzKg860Wj4s+BSkM0UzR18zygUG5sVgOoI2NzLG3s3F8rfJGcd8u31+Lbjc=----ATTACHMENT:----NzEzNzAyMzQxNjQzNTk1MSA2NzkyMDc2NTY5NjU5NzQwIDQxNDM4MjY4NzUxMTUxNzA=