diff --git a/tests/thinkphp/library/think/exceptionTest.php b/tests/thinkphp/library/think/exceptionTest.php new file mode 100644 index 00000000..93a4cf51 --- /dev/null +++ b/tests/thinkphp/library/think/exceptionTest.php @@ -0,0 +1,51 @@ + +// +---------------------------------------------------------------------- + +/** + * app类测试 + * @author Haotong Lin + */ + +namespace tests\thinkphp\library\think; + +use ReflectionMethod; +use think\Exception as ThinkException; + +class MyException extends ThinkException +{ + +} + +class exceptionTest extends \PHPUnit_Framework_TestCase +{ + public function testGetHttpStatus() + { + try { + throw new ThinkException("Error Processing Request", 1); + } catch (ThinkException $e) { + $this->assertEquals(500, $e->getHttpStatus()); + } + } + + public function testDebugData() + { + $data = ['a' => 'b', 'c' => 'd']; + try { + $e = new MyException("Error Processing Request", 1); + $method = new ReflectionMethod($e, 'setData'); + $method->setAccessible(true); + $method->invokeArgs($e, ['test', $data]); + throw $e; + } catch (MyException $e) { + $this->assertEquals(['test' => $data], $e->getData()); + } + } +}