ErrorHandlerTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Tests\Component\HttpKernel\Debug;
  11. use Symfony\Component\HttpKernel\Debug\ErrorHandler;
  12. use Symfony\Component\HttpKernel\Debug\ErrorException;
  13. /**
  14. * ErrorHandlerTest
  15. *
  16. * @author Robert Schönthal <seroscho@googlemail.com>
  17. */
  18. class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
  19. {
  20. public function testConstruct()
  21. {
  22. $handler = ErrorHandler::register(3);
  23. $level = new \ReflectionProperty($handler, 'level');
  24. $level->setAccessible(true);
  25. $this->assertEquals(3, $level->getValue($handler));
  26. restore_error_handler();
  27. }
  28. public function testHandle()
  29. {
  30. $handler = ErrorHandler::register(0);
  31. $this->assertFalse($handler->handle(0, 'foo', 'foo.php', 12, 'foo'));
  32. restore_error_handler();
  33. $handler = ErrorHandler::register(3);
  34. $this->assertFalse($handler->handle(4, 'foo', 'foo.php', 12, 'foo'));
  35. restore_error_handler();
  36. $handler = ErrorHandler::register(3);
  37. try {
  38. $handler->handle(1, 'foo', 'foo.php', 12, 'foo');
  39. } catch (\ErrorException $e) {
  40. $this->assertSame('1: foo in foo.php line 12', $e->getMessage());
  41. }
  42. restore_error_handler();
  43. }
  44. }