You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.5 KiB

  1. <?php
  2. /*
  3. * @copyright NetMonsters <team@netmonsters.ru>
  4. * @link http://netmonsters.ru
  5. * @package Majestic
  6. * @subpackage UnitTests
  7. * @since 2011-10-11
  8. *
  9. * Unit tests for ErrorHandler class
  10. */
  11. require_once dirname(__FILE__) . '/../../classes/Env.class.php';
  12. require_once dirname(__FILE__) . '/../../session/Session.php';
  13. require_once dirname(__FILE__) . '/../../exception/ErrorHandler.php';
  14. class ErrorHandlerTest extends PHPUnit_Framework_TestCase
  15. {
  16. public function testErrorHandlerInit()
  17. {
  18. $my_eh = array('ErrorHandler', 'error_handler');
  19. ErrorHandler::init();
  20. $eh = set_error_handler($my_eh);
  21. $this->assertInternalType('array', $eh);
  22. $this->assertEquals($eh, $my_eh);
  23. }
  24. /**
  25. * @expectedException ErrorException
  26. * @expectedExceptionMessage test error
  27. */
  28. public function testHandleError()
  29. {
  30. trigger_error("test error", E_USER_ERROR);
  31. }
  32. public function testShowDebug()
  33. {
  34. ob_start();
  35. echo PHP_EOL . 'some string' . PHP_EOL . PHP_EOL;
  36. try {
  37. throw new ErrorException("test error", E_USER_ERROR);
  38. } catch (ErrorException $e) {
  39. $result = ErrorHandler::showDebug($e);
  40. $this->assertNotEmpty($result);
  41. $this->assertStringStartsWith('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">', $result);
  42. $this->assertStringEndsWith('</html>', $result);
  43. }
  44. }
  45. }