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.
 
 
 
 
 
 

108 lines
2.5 KiB

  1. <?php
  2. /**
  3. * PhpUnderControl_PhalApiApiFactory_Test
  4. *
  5. * 针对 ../../PhalApi/ApiFactory.php PhalApi_ApiFactory 类的PHPUnit单元测试
  6. *
  7. * @author: dogstar 20141002
  8. */
  9. require_once dirname(__FILE__) . '/test_env.php';
  10. if (!class_exists('PhalApi_ApiFactory')) {
  11. require dirname(__FILE__) . '/../PhalApi/ApiFactory.php';
  12. }
  13. class PhpUnderControl_PhalApiApiFactory_Test extends PHPUnit_Framework_TestCase
  14. {
  15. public $coreApiFactory;
  16. protected function setUp()
  17. {
  18. parent::setUp();
  19. }
  20. protected function tearDown()
  21. {
  22. }
  23. /**
  24. * @group testGenerateService
  25. */
  26. public function testGenerateService()
  27. {
  28. $rs = PhalApi_ApiFactory::generateService();
  29. $this->assertNotNull($rs);
  30. $this->assertInstanceOf('PhalApi_Api', $rs);
  31. }
  32. public function testGenerateNormalClientService()
  33. {
  34. $data['service'] = 'Default.Index';
  35. $data['sign'] = '1ec92737c7c287c7249e0adef566544a';
  36. DI()->request = new PhalApi_Request($data);
  37. $rs = PhalApi_ApiFactory::generateService();
  38. $this->assertNotNull($rs);
  39. $this->assertInstanceOf('PhalApi_Api', $rs);
  40. $this->assertInstanceOf('Api_Default', $rs);
  41. }
  42. /**
  43. * @expectedException PhalApi_Exception_BadRequest
  44. */
  45. public function testGenerateIllegalApiService()
  46. {
  47. $data['service'] = 'NoThisService.Index';
  48. DI()->request = new PhalApi_Request($data);
  49. $rs = PhalApi_ApiFactory::generateService();
  50. }
  51. /**
  52. * @expectedException PhalApi_Exception_BadRequest
  53. */
  54. public function testGenerateIllegalActionService()
  55. {
  56. $data['service'] = 'Default.noThisFunction';
  57. DI()->request = new PhalApi_Request($data);
  58. $rs = PhalApi_ApiFactory::generateService();
  59. }
  60. /**
  61. * @expectedException PhalApi_Exception_BadRequest
  62. */
  63. public function testIllegalServiceName()
  64. {
  65. $data['service'] = 'Default';
  66. DI()->request = new PhalApi_Request($data);
  67. $rs = PhalApi_ApiFactory::generateService();
  68. }
  69. /**
  70. * @expectedException PhalApi_Exception_InternalServerError
  71. */
  72. public function testNotPhalApiSubclass()
  73. {
  74. $data['service'] = 'Crazy.What';
  75. DI()->request = new PhalApi_Request($data);
  76. $rs = PhalApi_ApiFactory::generateService();
  77. }
  78. }
  79. class Api_Default extends PhalApi_Api
  80. {
  81. public function index()
  82. {
  83. }
  84. }
  85. class Api_Crazy
  86. {
  87. public function what()
  88. {
  89. }
  90. }