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.
 
 
 
 
 
 

85 rivejä
1.9 KiB

  1. <?php
  2. /**
  3. * PhpUnderControl_ApiUser_Test
  4. *
  5. * 针对 ../../Demo/Api/User.php Api_User 类的PHPUnit单元测试
  6. *
  7. * @author: dogstar 20150128
  8. */
  9. require_once dirname(__FILE__) . '/../test_env.php';
  10. if (!class_exists('Api_User')) {
  11. require dirname(__FILE__) . '/../../Demo/Api/User.php';
  12. }
  13. class PhpUnderControl_ApiUser_Test extends PHPUnit_Framework_TestCase
  14. {
  15. public $apiUser;
  16. protected function setUp()
  17. {
  18. parent::setUp();
  19. $this->apiUser = new Api_User();
  20. }
  21. protected function tearDown()
  22. {
  23. }
  24. /**
  25. * @group testGetRules
  26. */
  27. public function testGetRules()
  28. {
  29. $rs = $this->apiUser->getRules();
  30. }
  31. /**
  32. * @group testGetBaseInfo
  33. */
  34. public function testGetBaseInfo()
  35. {
  36. //Step 1. 构建请求URL
  37. $url = 'service=User.GetBaseInfo&user_id=1';
  38. //Step 2. 执行请求
  39. $rs = PhalApi_Helper_TestRunner::go($url);
  40. //Step 3. 验证
  41. $this->assertNotEmpty($rs);
  42. $this->assertArrayHasKey('code', $rs);
  43. $this->assertArrayHasKey('msg', $rs);
  44. $this->assertArrayHasKey('info', $rs);
  45. $this->assertEquals(0, $rs['code']);
  46. $this->assertEquals('dogstar', $rs['info']['name']);
  47. $this->assertEquals('oschina', $rs['info']['note']);
  48. }
  49. public function testGetMultiBaseInfo()
  50. {
  51. //Step 1. 构建请求URL
  52. $url = 'service=User.GetMultiBaseInfo&user_ids=1,2,3';
  53. //Step 2. 执行请求
  54. $rs = PhalApi_Helper_TestRunner::go($url);
  55. //Step 3. 验证
  56. $this->assertNotEmpty($rs);
  57. $this->assertArrayHasKey('code', $rs);
  58. $this->assertArrayHasKey('msg', $rs);
  59. $this->assertArrayHasKey('list', $rs);
  60. foreach ($rs['list'] as $item) {
  61. $this->assertArrayHasKey('id', $item);
  62. $this->assertArrayHasKey('name', $item);
  63. $this->assertArrayHasKey('note', $item);
  64. }
  65. }
  66. }