Anton Grebnev
13 years ago
3 changed files with 125 additions and 0 deletions
-
37tests/exception/Error404ExceptionTest.php
-
52tests/exception/ErrorHandlerTest.php
-
36tests/exception/GeneralExceptionTest.php
@ -0,0 +1,37 @@ |
|||||
|
<?php |
||||
|
|
||||
|
/* |
||||
|
* @copyright NetMonsters <team@netmonsters.ru> |
||||
|
* @link http://netmonsters.ru |
||||
|
* @package Majestic |
||||
|
* @subpackage UnitTests |
||||
|
* @since 2011-10-11 |
||||
|
* |
||||
|
* Unit tests for Error404Exception class |
||||
|
*/ |
||||
|
|
||||
|
require_once dirname(__FILE__) . '/../../exception/GeneralException.php'; |
||||
|
require_once dirname(__FILE__) . '/../../exception/Error404Exception.php'; |
||||
|
|
||||
|
class Error404ExceptionTest extends PHPUnit_Framework_TestCase |
||||
|
{ |
||||
|
|
||||
|
/** |
||||
|
* @expectedException Error404Exception |
||||
|
*/ |
||||
|
public function testError404Exception() |
||||
|
{ |
||||
|
throw new Error404Exception(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @expectedException Error404Exception |
||||
|
* @expectedExceptionMessage Error404Exception message |
||||
|
* @excpectedExceptionCode 1 |
||||
|
*/ |
||||
|
public function testError404ExceptionMessage() |
||||
|
{ |
||||
|
throw new Error404Exception('Error404Exception message', 10); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,52 @@ |
|||||
|
<?php |
||||
|
|
||||
|
/* |
||||
|
* @copyright NetMonsters <team@netmonsters.ru> |
||||
|
* @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 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); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @expectedException ErrorException |
||||
|
* @expectedExceptionMessage test error |
||||
|
*/ |
||||
|
public function testHandleError() |
||||
|
{ |
||||
|
trigger_error("test error", E_USER_ERROR); |
||||
|
} |
||||
|
|
||||
|
public function testShowDebug() |
||||
|
{ |
||||
|
ob_start(); |
||||
|
echo PHP_EOL . 'some string' . PHP_EOL . PHP_EOL; |
||||
|
try { |
||||
|
throw new ErrorException("test error", E_USER_ERROR); |
||||
|
} catch (ErrorException $e) { |
||||
|
$result = ErrorHandler::showDebug($e); |
||||
|
$this->assertNotEmpty($result); |
||||
|
$this->assertStringStartsWith('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">', $result); |
||||
|
$this->assertStringEndsWith('</html>', $result); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,36 @@ |
|||||
|
<?php |
||||
|
|
||||
|
/* |
||||
|
* @copyright NetMonsters <team@netmonsters.ru> |
||||
|
* @link http://netmonsters.ru |
||||
|
* @package Majestic |
||||
|
* @subpackage UnitTests |
||||
|
* @since 2011-10-11 |
||||
|
* |
||||
|
* Unit tests for GeneralException class |
||||
|
*/ |
||||
|
|
||||
|
require_once dirname(__FILE__) . '/../../exception/GeneralException.php'; |
||||
|
|
||||
|
class GeneralExceptionTest extends PHPUnit_Framework_TestCase |
||||
|
{ |
||||
|
|
||||
|
/** |
||||
|
* @expectedException GeneralException |
||||
|
*/ |
||||
|
public function testGeneralException() |
||||
|
{ |
||||
|
throw new GeneralException(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @expectedException GeneralException |
||||
|
* @expectedExceptionMessage GeneralException message |
||||
|
* @excpectedExceptionCode 1 |
||||
|
*/ |
||||
|
public function testGeneralExceptionMessage() |
||||
|
{ |
||||
|
throw new GeneralException('GeneralException message', 1); |
||||
|
} |
||||
|
|
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue