User_Test.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace App;
  3. use App\Api\User;
  4. use PhalApi\Helper\TestRunner;
  5. /**
  6. * PhpUnderControl_App\Api\User_Test
  7. *
  8. * 针对 ./src/app/Api/User.php App\Api\User 类的PHPUnit单元测试
  9. *
  10. * @author: dogstar 20180818
  11. */
  12. class PhpUnderControl_AppApiUser_Test extends \PHPUnit_Framework_TestCase
  13. {
  14. public $appApiUser;
  15. protected function setUp()
  16. {
  17. parent::setUp();
  18. $this->appApiUser = new User();
  19. }
  20. protected function tearDown()
  21. {
  22. // 输出本次单元测试所执行的SQL语句
  23. // var_dump(\PhalApi\DI()->tracer->getSqls());
  24. // 输出本次单元测试所涉及的追踪埋点
  25. // var_dump(\PhalApi\DI()->tracer->getSqls());
  26. }
  27. /**
  28. * @group testGetRules
  29. */
  30. public function testGetRules()
  31. {
  32. $rs = $this->appApiUser->getRules();
  33. }
  34. /**
  35. * @group testLogin
  36. */
  37. public function testLogin()
  38. {
  39. //Step 1. 构建请求URL
  40. $url = 'service=App.User.Login&username=dogstar&password=123456';
  41. //Step 2. 执行请求
  42. $rs = TestRunner::go($url);
  43. //Step 3. 验证
  44. $this->assertTrue($rs['is_login']);
  45. $this->assertSame(8, $rs['user_id']);
  46. }
  47. }