125 lines
3.0 KiB
PHP
125 lines
3.0 KiB
PHP
<?php
|
|
/**
|
|
* PhalApi_App\Api\User_Test
|
|
*
|
|
* 针对 ../src/app/Api/User.php App\Api\User 类的PHPUnit单元测试
|
|
*
|
|
* @author: dogstar 20191219
|
|
*/
|
|
|
|
namespace tests\App\Api;
|
|
use App\Api\User;
|
|
use PhalApi\Helper\TestRunner;
|
|
|
|
class PhpUnderControl_AppApiUser_Test extends \PHPUnit\Framework\TestCase
|
|
{
|
|
public $appApiUser;
|
|
|
|
protected function setUp()
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->appApiUser = new \App\Api\User();
|
|
}
|
|
|
|
protected function tearDown()
|
|
{
|
|
// 输出本次单元测试所执行的SQL语句
|
|
// var_dump(\PhalApi\DI()->tracer->getSqls());
|
|
|
|
// 输出本次单元测试所涉及的追踪埋点
|
|
// var_dump(\PhalApi\DI()->tracer->getStack());
|
|
}
|
|
|
|
|
|
/**
|
|
* @group testGetRules
|
|
*/
|
|
public function testGetRules()
|
|
{
|
|
$rs = $this->appApiUser->getRules();
|
|
$this->assertTrue(is_array($rs));
|
|
}
|
|
|
|
/**
|
|
* @group testRegister
|
|
*/
|
|
public function testRegister()
|
|
{
|
|
//Step 1. 构建请求URL
|
|
$url = 'service=App.User.Register&username=test_app&password=123456';
|
|
|
|
//Step 2. 执行请求
|
|
$rs = TestRunner::go($url);
|
|
|
|
//Step 3. 验证
|
|
$this->assertNotEmpty($rs);
|
|
$this->assertTrue($rs['is_register']);
|
|
$this->assertGreaterThan(0, $rs['uid']);
|
|
}
|
|
|
|
/**
|
|
* @group testAlterPass
|
|
*/
|
|
public function testAlterPass()
|
|
{
|
|
// \PhalApi\DI()->context->setUid(1);
|
|
|
|
//Step 1. 构建请求URL
|
|
$url = 'service=App.User.AlterPass&username=test_app&password=123456&new_password=654321&_uid=1&access_token=123';
|
|
|
|
//Step 2. 执行请求
|
|
$rs = TestRunner::go($url);
|
|
|
|
//Step 3. 验证
|
|
$this->assertNotEmpty($rs);
|
|
$this->assertTrue($rs['is_alter']);
|
|
|
|
//Step 1. 构建请求URL
|
|
$url = 'service=App.User.AlterPass&username=test_app&password=654321&new_password=123456&_uid=1&access_token=123';
|
|
|
|
//Step 2. 执行请求
|
|
$rs = TestRunner::go($url);
|
|
|
|
//Step 3. 验证
|
|
$this->assertNotEmpty($rs);
|
|
$this->assertTrue($rs['is_alter']);
|
|
}
|
|
|
|
/**
|
|
* @group testProfile
|
|
*/
|
|
public function testUserProfile()
|
|
{
|
|
//Step 1. 构建请求URL
|
|
$url = 'service=App.User.UserProfile&username=test_app&access_token=123';
|
|
|
|
//Step 2. 执行请求
|
|
$rs = TestRunner::go($url);
|
|
|
|
//Step 3. 验证
|
|
$this->assertNotEmpty($rs);
|
|
$this->assertNotEmpty($rs['profile']);
|
|
$this->assertNotEmpty($rs['profile']['id']);
|
|
}
|
|
|
|
/**
|
|
* @group testUpdateProfile
|
|
*/
|
|
public function testUpdateProfile()
|
|
{
|
|
// \PhalApi\DI()->context->setUid(1);
|
|
|
|
//Step 1. 构建请求URL
|
|
$url = 'service=App.User.UpdateProfile&access_token=123&username=test_app&_uid=1&mobile='.time();
|
|
|
|
//Step 2. 执行请求
|
|
$rs = TestRunner::go($url);
|
|
|
|
//Step 3. 验证
|
|
$this->assertNotEmpty($rs);
|
|
$this->assertTrue($rs['is_update']);
|
|
}
|
|
|
|
}
|