exceptionTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: liu21st <liu21st@gmail.com>
  10. // +----------------------------------------------------------------------
  11. /**
  12. * exception类测试
  13. * @author Haotong Lin <lofanmi@gmail.com>
  14. */
  15. namespace tests\thinkphp\library\think;
  16. use ReflectionMethod;
  17. use think\Exception as ThinkException;
  18. use think\exception\HttpException;
  19. class MyException extends ThinkException
  20. {
  21. }
  22. class exceptionTest extends \PHPUnit_Framework_TestCase
  23. {
  24. public function testGetHttpStatus()
  25. {
  26. try {
  27. throw new HttpException(404, "Error Processing Request");
  28. } catch (HttpException $e) {
  29. $this->assertEquals(404, $e->getStatusCode());
  30. }
  31. }
  32. public function testDebugData()
  33. {
  34. $data = ['a' => 'b', 'c' => 'd'];
  35. try {
  36. $e = new MyException("Error Processing Request", 1);
  37. $method = new ReflectionMethod($e, 'setData');
  38. $method->setAccessible(true);
  39. $method->invokeArgs($e, ['test', $data]);
  40. throw $e;
  41. } catch (MyException $e) {
  42. $this->assertEquals(['test' => $data], $e->getData());
  43. }
  44. }
  45. }