* @link http://netmonsters.ru * @package Majestic * @subpackage UnitTests * @since 2011-10-11 * * Unit tests for ErrorHandler class */ require_once dirname(__FILE__) . '/../../classes/Env.class.php'; require_once dirname(__FILE__) . '/../../session/Session.php'; require_once dirname(__FILE__) . '/../../exception/ErrorHandler.php'; class ErrorHandlerTest extends PHPUnit_Framework_TestCase { public $old_eh = array('PHPUnit_Util_ErrorHandler', 'handleError'); public function setUp() { set_error_handler(array('ErrorHandler', 'error_handler')); ob_start(); } public function testErrorHandlerInit() { $my_eh = array('ErrorHandler', 'error_handler'); ErrorHandler::init(); $eh = set_error_handler($my_eh); $this->assertInternalType('array', $eh); $this->assertEquals($eh, $my_eh); } public function testHandleError() { $this->setExpectedException('ErrorException', 'test error'); trigger_error("test error", E_USER_ERROR); } /** * @TODO: ErrorHandler->wrapTrace() not used */ public function testShowDebug() { try { throw new ErrorException("test error", E_USER_ERROR); } catch (ErrorException $e) { $_SESSION['some'] = 'value'; $result = ErrorHandler::showDebug($e); $this->assertNotEmpty($result); $this->assertStringStartsWith('', $result); $this->assertStringEndsWith('', $result); } } /** * @TODO: ErrorHandler::wrapTrace not used * @TODO: nl2br() adds html
but leaves original linebreak line \n */ public function testWrapTrace() { $class = new ReflectionClass('ErrorHandler'); $method = $class->getMethod('WrapTrace'); $method->setAccessible(true); $result = $method->invoke(null, "first line\nsecond line"); $this->assertEquals("first line
\nsecond line
", $result); $result = $method->invoke(null, "first line\r\nsecond line"); $this->assertEquals("first line
\r\nsecond line
", $result); $result = $method->invoke(null, "first line\r\n\r\nsecond line"); $this->assertEquals("first line
\r\n
\r\nsecond line
", $result); } public function tearDown() { set_error_handler($this->old_eh); } }