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.

62 lines
1.7 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 $old_eh = array('PHPUnit_Util_ErrorHandler', 'handleError');
  17. public function setUp()
  18. {
  19. set_error_handler(array('ErrorHandler', 'error_handler'));
  20. ob_start();
  21. }
  22. public function testErrorHandlerInit()
  23. {
  24. $my_eh = array('ErrorHandler', 'error_handler');
  25. ErrorHandler::init();
  26. $eh = set_error_handler($my_eh);
  27. $this->assertInternalType('array', $eh);
  28. $this->assertEquals($eh, $my_eh);
  29. }
  30. /**
  31. * @expectedException ErrorException
  32. * @expectedExceptionMessage test error
  33. */
  34. public function testHandleError()
  35. {
  36. trigger_error("test error", E_USER_ERROR);
  37. }
  38. public function testShowDebug()
  39. {
  40. try {
  41. throw new ErrorException("test error", E_USER_ERROR);
  42. } catch (ErrorException $e) {
  43. $result = ErrorHandler::showDebug($e);
  44. $this->assertNotEmpty($result);
  45. $this->assertStringStartsWith('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">', $result);
  46. $this->assertStringEndsWith('</html>', $result);
  47. }
  48. }
  49. public function tearDown()
  50. {
  51. set_error_handler($this->old_eh);
  52. }
  53. }