ErrorHandlerTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. $e = new ErrorHandler(3);
  23. $this->assertInstanceOf('Symfony\Component\HttpKernel\Debug\ErrorHandler',$e);
  24. $level = new \ReflectionProperty(get_class($e),'level');
  25. $level->setAccessible(true);
  26. $this->assertEquals(3,$level->getValue($e));
  27. }
  28. public function testRegister()
  29. {
  30. $e = new ErrorHandler(3);
  31. $e = $this->getMock(get_class($e), array('handle'));
  32. $e->expects($this->once())->method('handle');
  33. $e->register();
  34. try{
  35. trigger_error('foo');
  36. }catch(\Exception $e){
  37. }
  38. }
  39. public function testHandle()
  40. {
  41. $e = new ErrorHandler(0);
  42. $this->assertFalse($e->handle(0,'foo','foo.php',12,'foo'));
  43. $e = new ErrorHandler(3);
  44. $this->assertFalse($e->handle(4,'foo','foo.php',12,'foo'));
  45. $e = new ErrorHandler(3);
  46. try{
  47. $e->handle(1, 'foo', 'foo.php', 12,'foo');
  48. }catch(\ErrorException $e){
  49. $this->assertSame('1: foo in foo.php line 12',$e->getMessage());
  50. }
  51. }
  52. }