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.
 
 
 
 
 
 

98 lines
2.0 KiB

  1. <?php
  2. /**
  3. * PhpUnderControl_PhalApiResponse_Test
  4. *
  5. * 针对 ../PhalApi/Response.php PhalApi_Response 类的PHPUnit单元测试
  6. *
  7. * @author: dogstar 20141004
  8. */
  9. require_once dirname(__FILE__) . '/test_env.php';
  10. if (!class_exists('PhalApi_Response')) {
  11. require dirname(__FILE__) . '/../PhalApi/Response.php';
  12. }
  13. class PhpUnderControl_PhalApiResponse_Test extends PHPUnit_Framework_TestCase
  14. {
  15. public $coreResponse;
  16. protected function setUp()
  17. {
  18. parent::setUp();
  19. $this->coreResponse = new PhalApi_Response_Json_Mock();
  20. }
  21. protected function tearDown()
  22. {
  23. }
  24. /**
  25. * @group testSetRet
  26. */
  27. public function testSetRet()
  28. {
  29. $ret = '0';
  30. $rs = $this->coreResponse->setRet($ret);
  31. }
  32. /**
  33. * @group testSetData
  34. */
  35. public function testSetData()
  36. {
  37. $data = array('sth' => 'hi~');
  38. $rs = $this->coreResponse->setData($data);
  39. }
  40. /**
  41. * @group testSetMsg
  42. */
  43. public function testSetMsg()
  44. {
  45. $msg = 'this will shoul as a wrong msg';
  46. $rs = $this->coreResponse->setMsg($msg);
  47. }
  48. /**
  49. * @group testAddHeaders
  50. */
  51. public function testAddHeaders()
  52. {
  53. $key = 'Content-Type';
  54. $content = 'text/html;charset=utf-8';
  55. $rs = $this->coreResponse->addHeaders($key, $content);
  56. }
  57. public function testGetHeaders()
  58. {
  59. $key = 'Version';
  60. $content = '1.1.2';
  61. $rs = $this->coreResponse->addHeaders($key, $content);
  62. $this->assertEquals($content, $this->coreResponse->getHeaders($key));
  63. $this->assertTrue(is_array($this->coreResponse->getHeaders()));
  64. }
  65. /**
  66. * @group testOutput
  67. */
  68. public function testOutput()
  69. {
  70. $this->coreResponse->setRet(404);
  71. $this->coreResponse->setMsg('not found');
  72. $this->coreResponse->setData(array('name' => 'PhalApi'));
  73. $rs = $this->coreResponse->output();
  74. $this->expectOutputString('{"ret":404,"data":{"name":"PhalApi"},"msg":"not found"}');
  75. }
  76. }