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.
 
 
 
 
 
 

105 lines
2.3 KiB

  1. <?php
  2. /**
  3. * PhpUnderControl_PhalApiApi_Test
  4. *
  5. * 针对 ../PhalApi/Api.php PhalApi_Api 类的PHPUnit单元测试
  6. *
  7. * @author: dogstar 20141004
  8. */
  9. require_once dirname(__FILE__) . '/test_env.php';
  10. if (!class_exists('PhalApi_Api')) {
  11. require dirname(__FILE__) . '/../PhalApi/Api.php';
  12. }
  13. class PhpUnderControl_PhalApiApi_Test extends PHPUnit_Framework_TestCase
  14. {
  15. public $coreApi;
  16. protected function setUp()
  17. {
  18. parent::setUp();
  19. $this->coreApi = new PhalApi_Api();
  20. }
  21. protected function tearDown()
  22. {
  23. DI()->filter = NULL;
  24. }
  25. /**
  26. * @group testInitialize
  27. */
  28. public function testInitialize()
  29. {
  30. DI()->request = new PhalApi_Request(array('service' => 'Default.Index'));
  31. $rs = $this->coreApi->init();
  32. }
  33. public function testInitializeWithWrongSign()
  34. {
  35. $data = array();
  36. $data['service'] = 'Default.Index';
  37. DI()->request = new PhalApi_Request($data);
  38. $rs = $this->coreApi->init();
  39. }
  40. public function testInitializeWithRightSign()
  41. {
  42. $data = array();
  43. $data['service'] = 'Default.Index';
  44. DI()->request = new PhalApi_Request($data);
  45. $rs = $this->coreApi->init();
  46. }
  47. public function testSetterAndGetter()
  48. {
  49. $this->coreApi->username = 'phalapi';
  50. $this->assertEquals('phalapi', $this->coreApi->username);
  51. }
  52. /**
  53. * @expectedException PhalApi_Exception_InternalServerError
  54. */
  55. public function testGetUndefinedProperty()
  56. {
  57. $this->coreApi->name = 'PhalApi';
  58. $rs = $this->coreApi->noThisKey;
  59. }
  60. public function testApiImpl()
  61. {
  62. $data = array();
  63. $data['service'] = 'Impl.Add';
  64. $data['version'] = '1.1.0';
  65. $data['left'] = '6';
  66. $data['right'] = '1';
  67. DI()->request = new PhalApi_Request($data);
  68. DI()->filter = 'PhalApi_Filter_Impl';
  69. $impl = new PhalApi_Api_Impl();
  70. $impl->init();
  71. $rs = $impl->add();
  72. $this->assertEquals(7, $rs);
  73. }
  74. /**
  75. * @expectedException PhalApi_Exception_InternalServerError
  76. */
  77. public function testIllegalFilter()
  78. {
  79. DI()->filter = 'PhalApi_Filter_Impl_NotFound';
  80. $impl = new PhalApi_Api_Impl();
  81. $impl->init();
  82. }
  83. }