This commit is contained in:
2022-03-21 11:16:38 +08:00
commit e89e807c64
1040 changed files with 284164 additions and 0 deletions

161
tests/app/Api/Auth_Test.php Normal file
View File

@@ -0,0 +1,161 @@
<?php
/**
* PhalApi_App\Api\Auth_Test
*
* 针对 ../src/app/Api/Auth.php App\Api\Auth 类的PHPUnit单元测试
*
* @author: dogstar 20191219
*/
namespace tests\App\Api;
use App\Api\Auth;
use PhalApi\Helper\TestRunner;
class PhpUnderControl_AppApiAuth_Test extends \PHPUnit\Framework\TestCase
{
public $appApiAuth;
protected function setUp()
{
parent::setUp();
$this->appApiAuth = new \App\Api\Auth();
}
protected function tearDown()
{
// 输出本次单元测试所执行的SQL语句
// var_dump(\PhalApi\DI()->tracer->getSqls());
// 输出本次单元测试所涉及的追踪埋点
// var_dump(\PhalApi\DI()->tracer->getStack());
}
/**
* @group testGetRules
*/
public function testGetRules()
{
$rs = $this->appApiAuth->getRules();
$this->assertTrue(is_array($rs));
}
/**
* @group testApplyToken
* @expectedException PhalApi\Exception\BadRequestException
*/
public function testApplyTokenFailNotVerify()
{
// 创建app
$domain = new \Base\Domain\Apps();
$domain->addApp('test', 'test_not_verify', '123456');
//Step 1. 构建请求URL
$url = 'service=App.Auth.ApplyToken&app_key=test_not_verify&app_secret=123456&config_name=phpunit_test&config_value=2020&username=dogstar&sign=B83F9015965B68185E97792EC40FC55D';
//Step 2. 执行请求
$rs = TestRunner::go($url);
}
/**
* @group testApplyToken
*/
public function testApplyToken()
{
// 创建app
$domain = new \Base\Domain\Apps();
$domain->addApp('test', 'test', '123456', 0, 0, '', 1);
//Step 1. 构建请求URL
$url = 'service=App.Auth.ApplyToken&app_key=test&app_secret=123456&config_name=phpunit_test&config_value=2020&username=dogstar&sign=B83F9015965B68185E97792EC40FC55D';
//Step 2. 执行请求
$rs = TestRunner::go($url);
//Step 3. 验证
$this->assertNotEmpty($rs);
$this->assertNotEmpty($rs['access_token']);
return $rs['access_token'];
}
/**
* @depends testApplyToken
*/
public function testRefreshAccessTokenForApp($at) {
//Step 1. 构建请求URL
$url = 'service=App.Auth.RefreshAccessToken&access_token='.$at;
//Step 2. 执行请求
$rs = TestRunner::go($url);
//Step 3. 验证
$this->assertNotEmpty($rs);
$this->assertNotEmpty($rs['access_token']);
}
/**
* @expectedException \PhalApi\Exception\BadRequestException
*/
public function testApplyTokenWrongKey()
{
//Step 1. 构建请求URL
$url = 'service=App.Auth.ApplyToken&app_key=test_404&app_secret=123456&config_name=phpunit_test&config_value=2020&username=dogstar&sign=B83F9015965B68185E97792EC40FC55D';
//Step 2. 执行请求
$rs = TestRunner::go($url);
}
/**
* @ expectedException \PhalApi\Exception\BadRequestException
*/
public function testUserLogin()
{
//Step 1. 构建请求URL
$url = 'service=App.User.Register&username=test_auth&password=123456';
//Step 2. 执行请求
$rs = TestRunner::go($url);
//Step 1. 构建请求URL
$url = 'service=App.Auth.UserLogin&username=test_auth&password=123456&app_key=test';
//Step 2. 执行请求
$rs = TestRunner::go($url);
//Step 3. 验证
$this->assertNotEmpty($rs);
$this->assertNotEmpty($rs['access_token']);
return $rs['access_token'];
}
public function testAppUserLogin() {
//Step 1. 构建请求URL
$url = 'service=App.Auth.AppUserLogin&username=test_auth&password=123456&app_key=test&app_secret=123456';
//Step 2. 执行请求
$rs = TestRunner::go($url);
//Step 3. 验证
$this->assertNotEmpty($rs);
$this->assertNotEmpty($rs['access_token']);
}
/**
* @depends testUserLogin
*/
//public function testRefreshAccessTokenForUser($at) {
// //Step 1. 构建请求URL
// $url = 'service=App.Auth.RefreshAccessToken&access_token='.$at;
// //Step 2. 执行请求
// $rs = TestRunner::go($url);
// //Step 3. 验证
// $this->assertNotEmpty($rs);
// $this->assertNotEmpty($rs['access_token']);
//}
}

View File

@@ -0,0 +1,56 @@
<?php
namespace App;
use App\Api\Site;
use PhalApi\Helper\TestRunner;
/**
* PhpUnderControl_ApiSite_Test
*
* 针对 App\Api\Site 类的PHPUnit单元测试
*
* @author: dogstar 20170703
*/
class PhpUnderControl_ApiSite_Test extends \PHPUnit_Framework_TestCase
{
public $site;
protected function setUp()
{
parent::setUp();
$this->site = new Site();
}
protected function tearDown()
{
}
/**
* @group testGetRules
*/
public function testGetRules()
{
$rs = $this->site->getRules();
$this->assertNotEmpty($rs);
}
public function testIndex()
{
$this->assertTrue(true);
return;
//Step 1. 构建请求URL
$url = 'service=App.Site.Index&username=dogstar';
//Step 2. 执行请求
$rs = TestRunner::go($url);
//Step 3. 验证
$this->assertNotEmpty($rs);
$this->assertArrayHasKey('title', $rs);
}
}

124
tests/app/Api/User_Test.php Normal file
View File

@@ -0,0 +1,124 @@
<?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']);
}
}