3.8.1
This commit is contained in:
133
tests/admin/Api/Apps_Test.php
Normal file
133
tests/admin/Api/Apps_Test.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
/**
|
||||
* PhalApi_Admin\Api\Apps_Test
|
||||
*
|
||||
* 针对 ../src/admin/Api/Apps.php Admin\Api\Apps 类的PHPUnit单元测试
|
||||
*
|
||||
* @author: dogstar 20200112
|
||||
*/
|
||||
|
||||
namespace tests\Admin\Api;
|
||||
use Admin\Api\Apps;
|
||||
use Base\Domain\Apps as AppsDomain;
|
||||
use PhalApi\Helper\TestRunner;
|
||||
|
||||
class PhpUnderControl_AdminApiApps_Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public $adminApiApps;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->adminApiApps = new \Admin\Api\Apps();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
// 输出本次单元测试所执行的SQL语句
|
||||
// var_dump(\PhalApi\DI()->tracer->getSqls());
|
||||
|
||||
// 输出本次单元测试所涉及的追踪埋点
|
||||
// var_dump(\PhalApi\DI()->tracer->getStack());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @group testGetRules
|
||||
*/
|
||||
public function testGetRules()
|
||||
{
|
||||
$rs = $this->adminApiApps->getRules();
|
||||
$this->assertTrue(is_array($rs));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testGetAppList
|
||||
*/
|
||||
public function testGetAppList()
|
||||
{
|
||||
$domain = new AppsDomain();
|
||||
$domain->addApp('appName_testGetAppList', 'appKey_testGetAppList', 'appSecret_123');
|
||||
|
||||
$url = 's=Admin.Apps.GetAppList';
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertNotEmpty($rs['list']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testGetAppSecret
|
||||
*/
|
||||
public function testGetAppSecret()
|
||||
{
|
||||
$domain = new AppsDomain();
|
||||
$id = $domain->addApp('appName_testGetAppSecret', 'testGetAppSecret', '123');
|
||||
|
||||
$url = 's=Admin.Apps.GetAppSecret&id='.$id;
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertEquals('123', $rs['app_secret']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testAlterAppStat
|
||||
*/
|
||||
public function testAlterAppStat()
|
||||
{
|
||||
$domain = new AppsDomain();
|
||||
$id = $domain->addApp('appName_testAlterAppStat', 'testAlterAppStat', '888');
|
||||
|
||||
$url = 's=Admin.Apps.AlterAppStat&type=0&id=' . $id;
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertTrue($rs['is_success']);
|
||||
|
||||
$url = 's=Admin.Apps.AlterAppStat&type=1&id=' . $id;
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertTrue($rs['is_success']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testAddApp
|
||||
*/
|
||||
public function testAddApp()
|
||||
{
|
||||
$url = 's=Admin.Apps.AddApp&app_key=testAddApp&app_secret=xxx&appName=testAddApp';
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertTrue($rs['is_add']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testCreateAppSecret
|
||||
*/
|
||||
public function testCreateAppSecret()
|
||||
{
|
||||
$url = 's=Admin.Apps.CreateAppSecret';
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertNotEmpty($rs['appSecret']);
|
||||
$this->assertTrue(is_string($rs['appSecret']));
|
||||
$this->assertEquals(32, strlen($rs['appSecret']));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testEditApp
|
||||
*/
|
||||
public function testEditApp(){
|
||||
$domain = new AppsDomain();
|
||||
$id = $domain->addApp('phpunit', 'phpunit', 'phpunit');
|
||||
|
||||
$url = "s=Admin.Apps.EditApp&id={$id}&app_name=testEditApp&app_secret=testEditApp";
|
||||
$rs = TestRunner::go($url);
|
||||
$this->assertTrue($rs['is_update']);
|
||||
|
||||
$rs = $domain->getAppById($id);
|
||||
$this->assertEquals('testEditApp', $rs['app_name']);
|
||||
$this->assertEquals('testEditApp', $rs['app_secret']);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
119
tests/admin/Api/Config_Test.php
Normal file
119
tests/admin/Api/Config_Test.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
/**
|
||||
* PhalApi_App\Api\Config_Test
|
||||
*
|
||||
* 针对 ../src/app/Api/Config.php App\Api\Config 类的PHPUnit单元测试
|
||||
*
|
||||
* @author: dogstar 20191219
|
||||
*/
|
||||
|
||||
namespace tests\Admin\Api;
|
||||
use Admin\Api\Config;
|
||||
use PhalApi\Helper\TestRunner;
|
||||
|
||||
class PhpUnderControl_AppApiConfig_Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public $appApiConfig;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->appApiConfig = new \Admin\Api\Config();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
// 输出本次单元测试所执行的SQL语句
|
||||
// var_dump(\PhalApi\DI()->tracer->getSqls());
|
||||
|
||||
// 输出本次单元测试所涉及的追踪埋点
|
||||
// var_dump(\PhalApi\DI()->tracer->getStack());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @group testGetRules
|
||||
*/
|
||||
public function testGetRules()
|
||||
{
|
||||
$rs = $this->appApiConfig->getRules();
|
||||
$this->assertTrue(is_array($rs));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testAddConfig
|
||||
*/
|
||||
public function testAddConfig()
|
||||
{
|
||||
//Step 1. 构建请求URL
|
||||
$url = 'service=Admin.Config.AddConfig&config_name=phpunit_test&config_value=2019&username=dogstar&sign=B83F9015965B68185E97792EC40FC55D&app_key=CEE4B8A091578B252AC4C92FB4E893C3';
|
||||
|
||||
//Step 2. 执行请求
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
//Step 3. 验证
|
||||
$this->assertNotEmpty($rs);
|
||||
$this->assertEquals(true, $rs['is_add']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testGetConfig
|
||||
*/
|
||||
public function testGetConfig()
|
||||
{
|
||||
//Step 1. 构建请求URL
|
||||
$url = 'service=Admin.Config.GetConfig&config_name=phpunit_test&config_value=2019&username=dogstar&sign=B83F9015965B68185E97792EC40FC55D&app_key=CEE4B8A091578B252AC4C92FB4E893C3';
|
||||
|
||||
//Step 2. 执行请求
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
//Step 3. 验证
|
||||
$this->assertNotEmpty($rs);
|
||||
$this->assertEquals('2019', $rs['config_value']);
|
||||
}
|
||||
|
||||
public function testGetConfigNotExists()
|
||||
{
|
||||
//Step 1. 构建请求URL
|
||||
$url = 'service=Admin.Config.GetConfig&config_name=phpunit_test_404&config_value=2019&username=dogstar&sign=B83F9015965B68185E97792EC40FC55D&app_key=CEE4B8A091578B252AC4C92FB4E893C3';
|
||||
|
||||
//Step 2. 执行请求
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
//Step 3. 验证
|
||||
$this->assertNotEmpty($rs);
|
||||
$this->assertSame(null, $rs['config_value']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testEditConfig
|
||||
*/
|
||||
public function testEditConfig()
|
||||
{
|
||||
//Step 1. 构建请求URL
|
||||
$url = 'service=Admin.Config.EditConfig&config_name=phpunit_test&config_value=2020&username=dogstar&sign=B83F9015965B68185E97792EC40FC55D&app_key=CEE4B8A091578B252AC4C92FB4E893C3';
|
||||
|
||||
//Step 2. 执行请求
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
//Step 3. 验证
|
||||
$this->assertNotEmpty($rs);
|
||||
$this->assertEquals(true, $rs['is_edit']);
|
||||
|
||||
$url = 'service=Admin.Config.GetConfig&config_name=phpunit_test&config_value=2019&username=dogstar&sign=B83F9015965B68185E97792EC40FC55D&app_key=CEE4B8A091578B252AC4C92FB4E893C3';
|
||||
$rs = TestRunner::go($url);
|
||||
$this->assertEquals('2020', $rs['config_value']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testRemoveConfig
|
||||
*/
|
||||
public function testRemoveConfig()
|
||||
{
|
||||
$url = 'service=Admin.Config.RemoveConfig&config_name=phpunit_test&config_value=2019&username=dogstar&sign=B83F9015965B68185E97792EC40FC55D&app_key=CEE4B8A091578B252AC4C92FB4E893C3';
|
||||
$rs = TestRunner::go($url);
|
||||
$this->assertEquals(true, $rs['is_remove']);
|
||||
}
|
||||
|
||||
}
|
||||
80
tests/admin/Api/File_Test.php
Normal file
80
tests/admin/Api/File_Test.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* PhalApi_Admin\Api\File_Test
|
||||
*
|
||||
* 针对 ./src/admin/Api/File.php Admin\Api\File 类的PHPUnit单元测试
|
||||
*
|
||||
* @author: dogstar 20200113
|
||||
*/
|
||||
|
||||
namespace tests\Admin\Api;
|
||||
use Admin\Api\File;
|
||||
use PhalApi\Helper\TestRunner;
|
||||
|
||||
class PhpUnderControl_AdminApiFile_Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public $adminApiFile;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->adminApiFile = new \Admin\Api\File();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
// 输出本次单元测试所执行的SQL语句
|
||||
// var_dump(\PhalApi\DI()->tracer->getSqls());
|
||||
|
||||
// 输出本次单元测试所涉及的追踪埋点
|
||||
// var_dump(\PhalApi\DI()->tracer->getStack());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @group testGetRules
|
||||
*/
|
||||
public function testGetRules()
|
||||
{
|
||||
$rs = $this->adminApiFile->getRules();
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testGetList
|
||||
*/
|
||||
public function testGetList()
|
||||
{
|
||||
// 提供一些数据
|
||||
$domain = new \Base\Domain\File();
|
||||
$domain->addUploadFile('x.jpg', 'jpg', 10, '/uploads/haha.png', 'http://localhost/uploads/haha.png');
|
||||
|
||||
$url = "service=Admin.File.GetList";
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertNotEmpty($rs);
|
||||
|
||||
$this->assertNotEmpty($rs['total']);
|
||||
$this->assertNotEmpty($rs['files']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testDelFile
|
||||
*/
|
||||
public function testDelFile()
|
||||
{
|
||||
// 提供一些数据
|
||||
$domain = new \Base\Domain\File();
|
||||
$id = $domain->addUploadFile('x.jpg', 'jpg', 10, '/uploads/haha.png', 'http://localhost/uploads/haha.png');
|
||||
|
||||
$url = "service=Admin.File.DelFile&id=$id";
|
||||
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertTrue(is_bool($rs));
|
||||
|
||||
$this->assertTrue($rs);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
61
tests/admin/Api/IP_Test.php
Normal file
61
tests/admin/Api/IP_Test.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* PhalApi_App\Api\IP_Test
|
||||
*
|
||||
* 针对 ../src/app/Api/IP.php App\Api\IP 类的PHPUnit单元测试
|
||||
*
|
||||
* @author: dogstar 20200106
|
||||
*/
|
||||
|
||||
namespace tests\Admin\Api;
|
||||
use Admin\Api\IP;
|
||||
use PhalApi\Helper\TestRunner;
|
||||
|
||||
class PhpUnderControl_AppApiIP_Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public $appApiIP;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->appApiIP = new \Admin\Api\IP();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
// 输出本次单元测试所执行的SQL语句
|
||||
// var_dump(\PhalApi\DI()->tracer->getSqls());
|
||||
|
||||
// 输出本次单元测试所涉及的追踪埋点
|
||||
// var_dump(\PhalApi\DI()->tracer->getStack());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @group testGetRules
|
||||
*/
|
||||
public function testGetRules()
|
||||
{
|
||||
$rs = $this->appApiIP->getRules();
|
||||
$this->assertTrue(is_array($rs));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testGetInfo
|
||||
*/
|
||||
public function testGetInfo()
|
||||
{
|
||||
//Step 1. 构建请求URL
|
||||
$url = 'service=Admin.IP.GetInfo&ip=61.147.110.191';
|
||||
|
||||
//Step 2. 执行请求
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
//Step 3. 验证
|
||||
$this->assertNotEmpty($rs);
|
||||
$this->assertNotEmpty($rs['info']);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
77
tests/admin/Api/Index_Test.php
Normal file
77
tests/admin/Api/Index_Test.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* PhalApi_Admin\Api\Index_Test
|
||||
*
|
||||
* 针对 ./src/admin/Api/Index.php Admin\Api\Index 类的PHPUnit单元测试
|
||||
*
|
||||
* @author: dogstar 20200113
|
||||
*/
|
||||
|
||||
namespace tests\Admin\Api;
|
||||
use Admin\Api\Index;
|
||||
use App\Common\TimeUtil;
|
||||
use PhalApi\Helper\TestRunner;
|
||||
|
||||
class PhpUnderControl_AdminApiIndex_Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public $adminApiIndex;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->adminApiIndex = new \Admin\Api\Index();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
// 输出本次单元测试所执行的SQL语句
|
||||
// var_dump(\PhalApi\DI()->tracer->getSqls());
|
||||
|
||||
// 输出本次单元测试所涉及的追踪埋点
|
||||
// var_dump(\PhalApi\DI()->tracer->getStack());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @ runInSeparateProcess
|
||||
* @group testGetRules
|
||||
*/
|
||||
public function testGetRules()
|
||||
{
|
||||
$rs = $this->adminApiIndex->getRules();
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testGetIndexData
|
||||
*/
|
||||
public function testGetIndexData()
|
||||
{
|
||||
$url = 's=Admin.Index.GetIndexData';
|
||||
|
||||
@$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertNotEmpty($rs['systemInfo']);
|
||||
$this->assertGreaterThanOrEqual(0, $rs['requestTime']);
|
||||
$this->assertGreaterThanOrEqual(0, $rs['apiNum']);
|
||||
$this->assertGreaterThanOrEqual(0, $rs['users']);
|
||||
$this->assertGreaterThanOrEqual(0, $rs['files']);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testGetDataFlow
|
||||
*/
|
||||
public function testGetDataFlow()
|
||||
{
|
||||
|
||||
$url = "s=Admin.Index.GetDataFlow";
|
||||
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertNotEmpty($rs);
|
||||
|
||||
$this->assertGreaterThanOrEqual(0, $rs[0]['total']);
|
||||
}
|
||||
|
||||
}
|
||||
112
tests/admin/Api/Pinyin_Test.php
Normal file
112
tests/admin/Api/Pinyin_Test.php
Normal file
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
/**
|
||||
* PhalApi_App\Api\Pinyin_Test
|
||||
*
|
||||
* 针对 ./src/app/Api/Pinyin.php App\Api\Pinyin 类的PHPUnit单元测试
|
||||
*
|
||||
* @author: dogstar 20200107
|
||||
*/
|
||||
|
||||
namespace tests\Admin\Api;
|
||||
use Admin\Api\Pinyin;
|
||||
use PhalApi\Helper\TestRunner;
|
||||
|
||||
class PhpUnderControl_AppApiPinyin_Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public $appApiPinyin;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->appApiPinyin = new \Admin\Api\Pinyin();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
// 输出本次单元测试所执行的SQL语句
|
||||
// var_dump(\PhalApi\DI()->tracer->getSqls());
|
||||
|
||||
// 输出本次单元测试所涉及的追踪埋点
|
||||
// var_dump(\PhalApi\DI()->tracer->getStack());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @group testGetRules
|
||||
*/
|
||||
public function testGetRules()
|
||||
{
|
||||
$rs = $this->appApiPinyin->getRules();
|
||||
$this->assertTrue(is_array($rs));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testConvert
|
||||
*/
|
||||
public function testConvert()
|
||||
{
|
||||
//Step 1. 构建请求URL
|
||||
$url = 'service=Admin.Pinyin.Convert&text=你好';
|
||||
|
||||
//Step 2. 执行请求
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
//Step 3. 验证
|
||||
$this->assertNotEmpty($rs);
|
||||
$this->assertNotEmpty($rs['pinyin']);
|
||||
$this->assertEquals($rs['pinyin'], "ni hao");
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testAbbr
|
||||
*/
|
||||
public function testAbbr()
|
||||
{
|
||||
//Step 1. 构建请求URL
|
||||
$url = 'service=Admin.Pinyin.Abbr&text=你好';
|
||||
|
||||
//Step 2. 执行请求
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
//Step 3. 验证
|
||||
$this->assertNotEmpty($rs);
|
||||
$this->assertNotEmpty($rs['pinyin']);
|
||||
$this->assertEquals($rs['pinyin'], "n h");
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testSentence
|
||||
*/
|
||||
public function testSentence()
|
||||
{
|
||||
//Step 1. 构建请求URL
|
||||
$url = 'service=Admin.Pinyin.Sentence&text=你好!';
|
||||
|
||||
//Step 2. 执行请求
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
//Step 3. 验证
|
||||
$this->assertNotEmpty($rs);
|
||||
$this->assertNotEmpty($rs['pinyin']);
|
||||
$this->assertEquals($rs['pinyin'], "ni hao!");
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testName
|
||||
*/
|
||||
public function testName()
|
||||
{
|
||||
//Step 1. 构建请求URL
|
||||
$url = 'service=Admin.Pinyin.Name&text=单田芳!';
|
||||
|
||||
//Step 2. 执行请求
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
//Step 3. 验证
|
||||
$this->assertNotEmpty($rs);
|
||||
$this->assertNotEmpty($rs['pinyin']);
|
||||
$this->assertEquals($rs['pinyin'], "shan tian fang");
|
||||
}
|
||||
|
||||
}
|
||||
57
tests/admin/Api/Requests_Test.php
Normal file
57
tests/admin/Api/Requests_Test.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* PhalApi_Admin\Api\Requests_Test
|
||||
*
|
||||
* 针对 ../src/admin/Api/Requests.php Admin\Api\Requests 类的PHPUnit单元测试
|
||||
*
|
||||
* @author: dogstar 20200116
|
||||
*/
|
||||
|
||||
namespace tests\Admin\Api;
|
||||
use Admin\Api\Requests;
|
||||
use PhalApi\Helper\TestRunner;
|
||||
|
||||
class PhpUnderControl_AdminApiRequests_Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public $adminApiRequests;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->adminApiRequests = new \Admin\Api\Requests();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
// 输出本次单元测试所执行的SQL语句
|
||||
// var_dump(\PhalApi\DI()->tracer->getSqls());
|
||||
|
||||
// 输出本次单元测试所涉及的追踪埋点
|
||||
// var_dump(\PhalApi\DI()->tracer->getStack());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @group testGetRules
|
||||
*/
|
||||
public function testGetRules()
|
||||
{
|
||||
$rs = $this->adminApiRequests->getRules();
|
||||
$this->assertTrue(is_array($rs));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testGetLogList
|
||||
*/
|
||||
public function testGetLogList()
|
||||
{
|
||||
$url = 's=Admin.Requests.GetLogList';
|
||||
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertArrayHasKey('total', $rs);
|
||||
$this->assertArrayHasKey('items', $rs);
|
||||
}
|
||||
|
||||
}
|
||||
214
tests/admin/Api/Rights_Test.php
Normal file
214
tests/admin/Api/Rights_Test.php
Normal file
@@ -0,0 +1,214 @@
|
||||
<?php
|
||||
/**
|
||||
* PhalApi_Admin\Api\Rights_Test
|
||||
*
|
||||
* 针对 ./src/admin/Api/Rights.php Admin\Api\Rights 类的PHPUnit单元测试
|
||||
*
|
||||
* @author: dogstar 20200113
|
||||
*/
|
||||
|
||||
namespace tests\Admin\Api;
|
||||
use Admin\Api\Rights;
|
||||
use PhalApi\Helper\TestRunner;
|
||||
|
||||
class PhpUnderControl_AdminApiRights_Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public $adminApiRights;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->adminApiRights = new \Admin\Api\Rights();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
// 输出本次单元测试所执行的SQL语句
|
||||
// var_dump(\PhalApi\DI()->tracer->getSqls());
|
||||
|
||||
// 输出本次单元测试所涉及的追踪埋点
|
||||
// var_dump(\PhalApi\DI()->tracer->getStack());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @group testGetRules
|
||||
*/
|
||||
public function testGetRules()
|
||||
{
|
||||
$rs = $this->adminApiRights->getRules();
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testGetAllAppApis
|
||||
*/
|
||||
public function testGetAllAppApis()
|
||||
{
|
||||
|
||||
$url = "s=Admin.Rights.GetAllAppApis";
|
||||
|
||||
@$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertNotEmpty($rs);
|
||||
|
||||
$this->assertGreaterThanOrEqual(0, $rs['total']);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testAssignRights
|
||||
*/
|
||||
public function testAssignRights()
|
||||
{
|
||||
$url = "s=Admin.Rights.AssignRights&appKey=123&assign_service=App.Site.Index";
|
||||
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertEquals($rs, array('service' => array("App.Site.Index")));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testRemoveRights
|
||||
*/
|
||||
public function testRemoveRights()
|
||||
{
|
||||
|
||||
$domain = new \Base\Domain\Rights();
|
||||
$domain->assignRights('123', 'App.Site.Index');
|
||||
|
||||
$url = "s=Admin.Rights.RemoveRights&remove_service=App.Site.Index";
|
||||
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertEquals($rs, array('service' => array("App.Site.Index")));
|
||||
|
||||
}
|
||||
|
||||
public function testaddRightsService()
|
||||
{
|
||||
$url = "s=Admin.Rights.addRightsService&service_desc=xxx&rights_service=Mine.Site.Index";
|
||||
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertTrue($rs['is_add']);
|
||||
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertFalse($rs['is_add']);
|
||||
|
||||
}
|
||||
|
||||
public function testRemoveRightsService()
|
||||
{
|
||||
$url = "s=Admin.Rights.RemoveRightsService&service_desc=xxx&rights_service=Mine.Site.Index";
|
||||
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertTrue($rs['is_remove']);
|
||||
|
||||
}
|
||||
|
||||
public function testListAllRightsService()
|
||||
{
|
||||
$url = "s=Admin.Rights.addRightsService&service_desc=xxx&rights_service=Mine.Site.Index222";
|
||||
$rs = TestRunner::go($url);
|
||||
$url = "s=Admin.Rights.addRightsService&service_desc=xxx&rights_service=Mine.Site.Index333";
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$url = "s=Admin.Rights.ListAllRightsService";
|
||||
|
||||
$rs = TestRunner::go($url);
|
||||
// var_dump($rs);
|
||||
|
||||
$this->assertNotEmpty($rs['items']);
|
||||
|
||||
}
|
||||
|
||||
public function testassignRightsForDevTypeOrNot() {
|
||||
$url = "s=Admin.Rights.assignRightsForDevTypeOrNot&rights_service=Mine.Site.Index222&member_type=100";
|
||||
|
||||
$rs = TestRunner::go($url);
|
||||
// var_dump($rs);
|
||||
|
||||
$this->assertTrue($rs['is_allow']);
|
||||
|
||||
$url = "s=Admin.Rights.assignRightsForDevTypeOrNot&rights_service=Mine.Site.Index222&member_type=100";
|
||||
|
||||
$rs = TestRunner::go($url);
|
||||
// var_dump($rs);
|
||||
|
||||
$this->assertFalse($rs['is_allow']);
|
||||
}
|
||||
|
||||
public function testListAllRightsForDeveloperType()
|
||||
{
|
||||
$url = "s=Admin.Rights.ListAllRightsForDeveloperType";
|
||||
|
||||
$rs = TestRunner::go($url);
|
||||
// var_dump($rs);
|
||||
|
||||
$this->assertNotEmpty($rs['items']);
|
||||
$this->assertNotEmpty($rs['dev_types']);
|
||||
|
||||
}
|
||||
|
||||
public function testsearchRightsList()
|
||||
{
|
||||
$url = "s=Admin.Rights.searchRightsList&member_type=100&user_id=9";
|
||||
|
||||
$rs = TestRunner::go($url);
|
||||
// var_dump($rs);
|
||||
|
||||
//$this->assertNotEmpty($rs['items']);
|
||||
$this->assertNotEmpty($rs['dev_types']);
|
||||
|
||||
|
||||
$url = "s=Admin.Rights.searchRightsList";
|
||||
|
||||
$rs = TestRunner::go($url);
|
||||
// var_dump($rs);
|
||||
|
||||
$this->assertNotEmpty($rs['items']);
|
||||
$this->assertNotEmpty($rs['dev_types']);
|
||||
|
||||
}
|
||||
|
||||
public function testassignRightsOrNot()
|
||||
{
|
||||
$url = "s=Admin.Rights.assignRightsOrNot&id=1";
|
||||
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function testcreateNewRightsRuleRepeat() {
|
||||
$url = "s=Admin.Rights.createNewRightsRule&rights_service=App.xx.yy&member_type=100&is_allow=1";
|
||||
$rs = TestRunner::go($url);
|
||||
$this->assertTrue($rs['is_add']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PhalApi\Exception\BadRequestException
|
||||
*/
|
||||
public function testcreateNewRightsRule() {
|
||||
$url = "s=Admin.Rights.createNewRightsRule&rights_service=App.xx.yy&member_type=100&is_allow=1";
|
||||
|
||||
$rs = TestRunner::go($url);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PhalApi\Exception\BadRequestException
|
||||
*/
|
||||
public function testgetDevAppApis()
|
||||
{
|
||||
$url = "s=Admin.Rights.getDevAppApis&app_key=123";
|
||||
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
}
|
||||
51
tests/admin/Api/Task_Test.php
Normal file
51
tests/admin/Api/Task_Test.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* PhalApi_Admin\Api\Task_Test
|
||||
*
|
||||
* 针对 ./src/admin/Api/Task.php Admin\Api\Task 类的PHPUnit单元测试
|
||||
*
|
||||
* @author: dogstar 20200113
|
||||
*/
|
||||
|
||||
namespace tests\Admin\Api;
|
||||
use Admin\Api\Task;
|
||||
use PhalApi\Helper\TestRunner;
|
||||
|
||||
class PhpUnderControl_AdminApiTask_Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public $adminApiTask;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->adminApiTask = new \Admin\Api\Task();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
// 输出本次单元测试所执行的SQL语句
|
||||
// var_dump(\PhalApi\DI()->tracer->getSqls());
|
||||
|
||||
// 输出本次单元测试所涉及的追踪埋点
|
||||
// var_dump(\PhalApi\DI()->tracer->getStack());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testAddTaskConfig
|
||||
*/
|
||||
public function testAddTaskConfig()
|
||||
{
|
||||
|
||||
$url = "s=Admin.Task.AddTaskConfig&title=test&task_service=App.Site.Index";
|
||||
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertTrue(is_int($rs['id']));
|
||||
|
||||
$this->assertGreaterThanOrEqual(0, $rs['id']);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
199
tests/admin/Api/User_Test.php
Normal file
199
tests/admin/Api/User_Test.php
Normal file
@@ -0,0 +1,199 @@
|
||||
<?php
|
||||
/**
|
||||
* PhalApi_Admin\Api\User_Test
|
||||
*
|
||||
* 针对 ../src/admin/Api/User.php Admin\Api\User 类的PHPUnit单元测试
|
||||
*
|
||||
* @author: dogstar 20200112
|
||||
*/
|
||||
|
||||
namespace tests\Admin\Api;
|
||||
use Admin\Api\User;
|
||||
use PhalApi\Helper\TestRunner;
|
||||
|
||||
class PhpUnderControl_AdminApiUser_Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public $adminApiUser;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->adminApiUser = new \Admin\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->adminApiUser->getRules();
|
||||
$this->assertTrue(is_array($rs));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testGetAllMembers
|
||||
*/
|
||||
public function testGetAllMembers()
|
||||
{
|
||||
$url = 's=Admin.User.AddMember&username=testGetAllMembers&password=123456&member_type=0';
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$url = 's=Admin.User.GetAllMembers';
|
||||
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertNotEmpty($rs['list']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testDelMember
|
||||
*/
|
||||
public function testDelMemberOK()
|
||||
{
|
||||
$url = 's=Admin.User.AddMember&username=testDelMemberOK&password=123456&member_type=0';
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$url = 's=Admin.User.DelMember&id=2';
|
||||
|
||||
$rs = TestRunner::go($url);
|
||||
$this->assertTrue($rs['is_success']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testDelMember
|
||||
*/
|
||||
public function testDelMember()
|
||||
{
|
||||
$url = 's=Admin.User.DelMember&id=100';
|
||||
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertFalse($rs['is_success']);
|
||||
}
|
||||
|
||||
public function testGetMember()
|
||||
{
|
||||
$url = 's=Admin.User.GetMember&id=1';
|
||||
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertEquals(1, $rs['member']['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testDelMember
|
||||
*/
|
||||
public function testGetMemberNo()
|
||||
{
|
||||
$url = 's=Admin.User.GetMember&id=2';
|
||||
|
||||
$rs = TestRunner::go($url);
|
||||
// var_dump($rs);
|
||||
|
||||
$this->assertEmpty($rs['member']);
|
||||
}
|
||||
|
||||
public function testEditMember() {
|
||||
$url = 's=Admin.User.AddMember&username=testEditMember&password=123456&member_type=0';
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$uid = $rs['uid'];
|
||||
|
||||
// 修改信息和密码
|
||||
$url = 's=Admin.User.EditMember&sex=1&email=xx@api.com&password=654321&id=' . $uid;
|
||||
$rs = TestRunner::go($url);
|
||||
$this->assertTrue($rs['is_update']);
|
||||
$this->assertTrue($rs['is_alter_password']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PhalApi\Exception\BadRequestException
|
||||
*/
|
||||
public function testEditAdminMember() {
|
||||
$url = 's=Admin.User.AddMember&username=testEditAdminMember&password=123456&member_type=200';
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$uid = $rs['uid'];
|
||||
|
||||
// 修改信息和密码
|
||||
$url = 's=Admin.User.EditMember&sex=1&email=xx@api.com&password=654321&id=' . $uid;
|
||||
$rs = TestRunner::go($url);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testAddMember
|
||||
*/
|
||||
public function testAddMember()
|
||||
{
|
||||
$url = 's=Admin.User.AddMember&username=testAddMember&password=123456&member_type=0';
|
||||
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertTrue($rs['is_add']);
|
||||
$this->assertGreaterThan(0, $rs['uid']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testGetDataFlow
|
||||
*/
|
||||
public function testGetDataFlow()
|
||||
{
|
||||
$url = 's=Admin.User.GetDataFlow';
|
||||
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertArrayHasKey('list', $rs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testGetLoginStatistics
|
||||
*/
|
||||
public function testGetLoginStatistics()
|
||||
{
|
||||
$url = 's=Admin.User.GetLoginStatistics';
|
||||
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertArrayHasKey('list', $rs);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testAlterMemberStatus
|
||||
*/
|
||||
public function testAlterMemberStatus()
|
||||
{
|
||||
$url = 's=Admin.User.AddMember&username=testAlterMemberStatus&password=123456&member_type=0';
|
||||
$rs = TestRunner::go($url);
|
||||
$uid = $rs['uid'];
|
||||
|
||||
$url = 's=Admin.User.AlterMemberStatus&type=0&id=' . $uid;
|
||||
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertTrue($rs['is_success']);
|
||||
|
||||
}
|
||||
|
||||
public function testGetLastestLoginRecord()
|
||||
{
|
||||
$url = 's=Admin.User.GetLastestLoginRecord';
|
||||
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertArrayHasKey('records', $rs);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
161
tests/app/Api/Auth_Test.php
Normal file
161
tests/app/Api/Auth_Test.php
Normal 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']);
|
||||
//}
|
||||
}
|
||||
56
tests/app/Api/Site_Test.php
Normal file
56
tests/app/Api/Site_Test.php
Normal 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
124
tests/app/Api/User_Test.php
Normal 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']);
|
||||
}
|
||||
|
||||
}
|
||||
222
tests/app/Common/Filter_Test.php
Normal file
222
tests/app/Common/Filter_Test.php
Normal file
@@ -0,0 +1,222 @@
|
||||
<?php
|
||||
/**
|
||||
* PhalApi_App\Common\Filter_Test
|
||||
*
|
||||
* 针对 ../src/app/Common/Filter.php App\Common\Filter 类的PHPUnit单元测试
|
||||
*
|
||||
* @author: dogstar 20191231
|
||||
*/
|
||||
|
||||
namespace tests\App\Common;
|
||||
use App\Common\Filter;
|
||||
|
||||
class PhpUnderControl_AppCommonFilter_Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public $appCommonFilter;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->appCommonFilter = new \App\Common\Filter();
|
||||
|
||||
\PhalApi\DI()->debug = false;
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
\PhalApi\DI()->debug = true;
|
||||
|
||||
// 输出本次单元测试所执行的SQL语句
|
||||
// var_dump(\PhalApi\DI()->tracer->getSqls());
|
||||
|
||||
// 输出本次单元测试所涉及的追踪埋点
|
||||
// var_dump(\PhalApi\DI()->tracer->getStack());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @group testCheck
|
||||
* @expectedException PhalApi\Exception\BadRequestException
|
||||
*/
|
||||
public function testCheckMissAT()
|
||||
{
|
||||
$rs = $this->appCommonFilter->check();
|
||||
}
|
||||
|
||||
public function testCheckOK()
|
||||
{
|
||||
$time = time();
|
||||
$config = \PhalApi\DI()->config;
|
||||
|
||||
$token = array(
|
||||
"iss" => "phalapi_pro", // 该JWT的签发者
|
||||
"aud" => "app", // 接收该JWT的一方
|
||||
"sub" => 'test', // 该JWT所面向的用户
|
||||
"uid" => 1,
|
||||
"iat" => $time, // 在什么时候签发的
|
||||
"exp" => $time + $config->get('app.jwt.exp', 86400), // 什么时候过期,这里是一个Unix时间戳
|
||||
|
||||
);
|
||||
|
||||
$key = $config->get('app.jwt.key');
|
||||
$jwt = \lmxdawn\jwt\JWT::encode($token, $key, 'HS256');
|
||||
|
||||
$data = array(
|
||||
'access_token' => $jwt,
|
||||
's' => 'App.HelloWorld.Say',
|
||||
);
|
||||
|
||||
\PhalApi\DI()->request = new \PhalApi\Request($data);
|
||||
|
||||
$this->appCommonFilter->check();
|
||||
|
||||
$this->assertEquals('test', \PhalApi\DI()->context->getAppKey());
|
||||
$this->assertEquals(1, \PhalApi\DI()->context->getUid());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testCheck
|
||||
* @expectedException PhalApi\Exception\BadRequestException
|
||||
*/
|
||||
public function testCheckWrongAT()
|
||||
{
|
||||
$data = array(
|
||||
'access_token' => 'ghjkghjkghj',
|
||||
's' => 'App.HelloWorld.Say',
|
||||
);
|
||||
|
||||
\PhalApi\DI()->request = new \PhalApi\Request($data);
|
||||
|
||||
$this->appCommonFilter->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testCheck
|
||||
* @expectedException PhalApi\Exception\BadRequestException
|
||||
*/
|
||||
public function testCheckExpireOut()
|
||||
{
|
||||
$time = time() - 86400; // 过期
|
||||
$config = \PhalApi\DI()->config;
|
||||
|
||||
$token = array(
|
||||
"iss" => "phalapi_pro", // 该JWT的签发者
|
||||
"aud" => "app", // 接收该JWT的一方
|
||||
"sub" => 'test', // 该JWT所面向的用户
|
||||
"uid" => 1,
|
||||
"iat" => $time, // 在什么时候签发的
|
||||
"exp" => $time,
|
||||
);
|
||||
|
||||
$key = $config->get('app.jwt.key');
|
||||
$jwt = \lmxdawn\jwt\JWT::encode($token, $key, 'HS256');
|
||||
|
||||
$data = array(
|
||||
'access_token' => $jwt,
|
||||
's' => 'App.HelloWorld.Say',
|
||||
);
|
||||
|
||||
\PhalApi\DI()->request = new \PhalApi\Request($data);
|
||||
|
||||
$this->appCommonFilter->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testCheck
|
||||
* @expectedException PhalApi\Exception\BadRequestException
|
||||
*/
|
||||
public function testCheckAdmin()
|
||||
{
|
||||
$time = time();
|
||||
$config = \PhalApi\DI()->config;
|
||||
|
||||
$token = array(
|
||||
"iss" => "phalapi_pro", // 该JWT的签发者
|
||||
"aud" => "app", // 接收该JWT的一方
|
||||
"sub" => 'test', // 该JWT所面向的用户
|
||||
"uid" => 1,
|
||||
"iat" => $time, // 在什么时候签发的
|
||||
"exp" => $time + $config->get('app.jwt.exp', 86400), // 什么时候过期,这里是一个Unix时间戳
|
||||
|
||||
);
|
||||
|
||||
$key = $config->get('app.jwt.key');
|
||||
$jwt = \lmxdawn\jwt\JWT::encode($token, $key, 'HS256');
|
||||
|
||||
$data = array(
|
||||
'access_token' => $jwt,
|
||||
's' => 'Admin.HelloWorld.Say', // 管理员接口
|
||||
);
|
||||
|
||||
\PhalApi\DI()->request = new \PhalApi\Request($data);
|
||||
|
||||
$this->appCommonFilter->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testCheck
|
||||
* @ expectedException PhalApi\Exception\BadRequestException
|
||||
*/
|
||||
public function testCheckNoAppRights()
|
||||
{
|
||||
$domain = new \Base\Domain\Rights();
|
||||
$domain->removeRights('test', 'App.HelloWorld.SayNo', 1);
|
||||
|
||||
$time = time();
|
||||
$config = \PhalApi\DI()->config;
|
||||
|
||||
$token = array(
|
||||
"iss" => "phalapi_pro", // 该JWT的签发者
|
||||
"aud" => "app", // 接收该JWT的一方
|
||||
"sub" => 'test', // 该JWT所面向的用户
|
||||
"uid" => 1,
|
||||
"iat" => $time, // 在什么时候签发的
|
||||
"exp" => $time + 100,
|
||||
);
|
||||
|
||||
$key = $config->get('app.jwt.key');
|
||||
$jwt = \lmxdawn\jwt\JWT::encode($token, $key, 'HS256');
|
||||
|
||||
$data = array(
|
||||
'access_token' => $jwt,
|
||||
's' => 'App.HelloWorld.SayNo', // 此接口无权限
|
||||
);
|
||||
|
||||
\PhalApi\DI()->request = new \PhalApi\Request($data);
|
||||
|
||||
$this->appCommonFilter->check();
|
||||
}
|
||||
|
||||
public function testCheckYesAppRights()
|
||||
{
|
||||
$domain = new \Base\Domain\Rights();
|
||||
$domain->assignRights('test', 'App.HelloWorld.SayNo', 1);
|
||||
|
||||
$time = time();
|
||||
$config = \PhalApi\DI()->config;
|
||||
|
||||
$token = array(
|
||||
"iss" => "phalapi_pro", // 该JWT的签发者
|
||||
"aud" => "app", // 接收该JWT的一方
|
||||
"sub" => 'test', // 该JWT所面向的用户
|
||||
"uid" => 1,
|
||||
"iat" => $time, // 在什么时候签发的
|
||||
"exp" => $time + 100,
|
||||
);
|
||||
|
||||
$key = $config->get('app.jwt.key');
|
||||
$jwt = \lmxdawn\jwt\JWT::encode($token, $key, 'HS256');
|
||||
|
||||
$data = array(
|
||||
'access_token' => $jwt,
|
||||
's' => 'App.HelloWorld.SayNo', // 此接口重新又有权限
|
||||
);
|
||||
|
||||
\PhalApi\DI()->request = new \PhalApi\Request($data);
|
||||
|
||||
$this->appCommonFilter->check();
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
77
tests/base/Common/ApiInfoUtil_Test.php
Normal file
77
tests/base/Common/ApiInfoUtil_Test.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* PhalApi_App\Common\ApiInfoUtil_Test
|
||||
*
|
||||
* 针对 ./src/app/Common/ApiInfoUtil.php App\Common\ApiInfoUtil 类的PHPUnit单元测试
|
||||
*
|
||||
* @author: dogstar 20200104
|
||||
*/
|
||||
|
||||
namespace tests\Base\Common;
|
||||
use Base\Common\ApiInfoUtil;
|
||||
|
||||
class PhpUnderControl_BaseCommonApiInfoUtil_Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public $appCommonApiInfoUtil;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->appCommonApiInfoUtil = new \Base\Common\ApiInfoUtil();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
// 输出本次单元测试所执行的SQL语句
|
||||
// var_dump(\PhalApi\DI()->tracer->getSqls());
|
||||
|
||||
// 输出本次单元测试所涉及的追踪埋点
|
||||
// var_dump(\PhalApi\DI()->tracer->getStack());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @ runInSeparateProcess
|
||||
* @group testGetApiNum
|
||||
*/
|
||||
public function testGetApiNum()
|
||||
{
|
||||
$rs = @$this->appCommonApiInfoUtil::getApiNum();
|
||||
|
||||
$this->assertTrue(is_int($rs));
|
||||
$this->assertGreaterThan(1, $rs);
|
||||
return $rs;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetApiNum
|
||||
* @ runInSeparateProcess
|
||||
* @group testGetApiInfo
|
||||
*/
|
||||
public function testGetApiInfo($total)
|
||||
{
|
||||
$namespace1 = 'Admin';
|
||||
$namespace2 = 'App';
|
||||
|
||||
$rs1 = $this->appCommonApiInfoUtil::getApiInfo($namespace1);
|
||||
$rs2 = $this->appCommonApiInfoUtil::getApiInfo($namespace2);
|
||||
$this->assertTrue(is_array($rs1));
|
||||
$this->assertNotEmpty($rs1);
|
||||
|
||||
$this->assertTrue(is_array($rs2));
|
||||
$this->assertNotEmpty($rs2);
|
||||
$this->assertGreaterThan(1, $rs1['total']);
|
||||
$this->assertGreaterThan(1, $rs2['total']);
|
||||
|
||||
}
|
||||
|
||||
public function testCheckApiIsExist()
|
||||
{
|
||||
$this->assertTrue(\Base\Common\ApiInfoUtil::checkApiIsExist('App.Auth.ApplyToken'));
|
||||
|
||||
$this->assertFalse(\Base\Common\ApiInfoUtil::checkApiIsExist('App.Auth'));
|
||||
$this->assertFalse(\Base\Common\ApiInfoUtil::checkApiIsExist('App.Auth.ApplyTokenXXXXX'));
|
||||
}
|
||||
}
|
||||
49
tests/base/Common/ArrayUtil_Test.php
Normal file
49
tests/base/Common/ArrayUtil_Test.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* PhalApi_App\Common\ArrayUtil_Test
|
||||
*
|
||||
* 针对 ../src/app/Common/ArrayUtil.php App\Common\ArrayUtil 类的PHPUnit单元测试
|
||||
*
|
||||
* @author: dogstar 20191231
|
||||
*/
|
||||
|
||||
namespace tests\Base\Common;
|
||||
use Base\Common\ArrayUtil;
|
||||
|
||||
class PhpUnderControl_BaseCommonArrayUtil_Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public $appCommonArrayUtil;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->appCommonArrayUtil = new \Base\Common\ArrayUtil();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
// 输出本次单元测试所执行的SQL语句
|
||||
// var_dump(\PhalApi\DI()->tracer->getSqls());
|
||||
|
||||
// 输出本次单元测试所涉及的追踪埋点
|
||||
// var_dump(\PhalApi\DI()->tracer->getStack());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @group testTakeKey
|
||||
*/
|
||||
public function testTakeKey()
|
||||
{
|
||||
|
||||
$array = array('name' => 'phpunit', 'age' => 1);
|
||||
$keys = array('name');
|
||||
$rs = $this->appCommonArrayUtil::takeKey($array, $keys);
|
||||
$expect = array('name' => 'phpunit');
|
||||
$this->assertEquals($rs, $expect);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
83
tests/base/Common/Context_Test.php
Normal file
83
tests/base/Common/Context_Test.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* PhalApi_App\Common\Context_Test
|
||||
*
|
||||
* 针对 ../src/app/Common/Context.php App\Common\Context 类的PHPUnit单元测试
|
||||
*
|
||||
* @author: dogstar 20191231
|
||||
*/
|
||||
|
||||
namespace tests\Base\Common;
|
||||
use Base\Common\Context;
|
||||
|
||||
class PhpUnderControl_BaseCommonContext_Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public $appCommonContext;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->appCommonContext = new \Base\Common\Context('phpunit', 888);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
// 输出本次单元测试所执行的SQL语句
|
||||
// var_dump(\PhalApi\DI()->tracer->getSqls());
|
||||
|
||||
// 输出本次单元测试所涉及的追踪埋点
|
||||
// var_dump(\PhalApi\DI()->tracer->getStack());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @group testSetAppKey
|
||||
*/
|
||||
public function testSetAppKey()
|
||||
{
|
||||
$this->assertEquals('phpunit', $this->appCommonContext->getAppKey());
|
||||
|
||||
$appKey = 'phpunit2';
|
||||
|
||||
$rs = $this->appCommonContext->setAppKey($appKey);
|
||||
|
||||
$this->assertEquals($appKey, $this->appCommonContext->getAppKey());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testGetAppKey
|
||||
*/
|
||||
public function testGetAppKey()
|
||||
{
|
||||
$rs = $this->appCommonContext->getAppKey();
|
||||
|
||||
$this->assertEquals('phpunit', $rs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testSetUid
|
||||
*/
|
||||
public function testSetUid()
|
||||
{
|
||||
$this->assertEquals(888, $this->appCommonContext->getUid());
|
||||
|
||||
$uid = '999';
|
||||
|
||||
$rs = $this->appCommonContext->setUid($uid);
|
||||
|
||||
$this->assertSame(999, $rs->getUid());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testGetUid
|
||||
*/
|
||||
public function testGetUid()
|
||||
{
|
||||
$rs = $this->appCommonContext->getUid();
|
||||
|
||||
$this->assertEquals(888, $rs);
|
||||
}
|
||||
|
||||
}
|
||||
118
tests/base/Common/TimeUtil_Test.php
Normal file
118
tests/base/Common/TimeUtil_Test.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
/**
|
||||
* PhalApi_App\Common\TimeUtil_Test
|
||||
*
|
||||
* 针对 ../src/app/Common/TimeUtil.php App\Common\TimeUtil 类的PHPUnit单元测试
|
||||
*
|
||||
* @author: dogstar 20191231
|
||||
*/
|
||||
|
||||
namespace tests\Base\Common;
|
||||
use Base\Common\TimeUtil;
|
||||
|
||||
class PhpUnderControl_BaseCommonTimeUtil_Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public $appCommonTimeUtil;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->appCommonTimeUtil = new \Base\Common\TimeUtil();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
// 输出本次单元测试所执行的SQL语句
|
||||
// var_dump(\PhalApi\DI()->tracer->getSqls());
|
||||
|
||||
// 输出本次单元测试所涉及的追踪埋点
|
||||
// var_dump(\PhalApi\DI()->tracer->getStack());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @group testCreateDefaultTimeLine
|
||||
*/
|
||||
public function testCreateDefaultTimeLine()
|
||||
{
|
||||
$start = $end = date("Y-m-d");
|
||||
// day
|
||||
$rs = $this->appCommonTimeUtil::createDefaultTimeLine($start, $end, 'day');
|
||||
$expect = array(
|
||||
$start => array(
|
||||
'time' => $start,
|
||||
'total' => 0,
|
||||
)
|
||||
);
|
||||
$this->assertEquals($rs, $expect);
|
||||
|
||||
// month
|
||||
$month = date("Y-m-00");
|
||||
$rs2 = $this->appCommonTimeUtil::createDefaultTimeLine($start, $end, 'month');
|
||||
$expect2 = array(
|
||||
$month => array(
|
||||
'time' => $month,
|
||||
'total' => 0,
|
||||
)
|
||||
);
|
||||
$this->assertEquals($rs2, $expect2);
|
||||
|
||||
// hour
|
||||
$rs3 = $this->appCommonTimeUtil::createDefaultTimeLine($start, $end, 'hour');
|
||||
$expect3 = array();
|
||||
for ($i = 0; $i <= 23; $i++){
|
||||
if($i < 10){
|
||||
$i = '0'.$i;
|
||||
}
|
||||
$time = $start.' '.$i.':00:00';
|
||||
$expect3[$time] = array(
|
||||
'time' => $time,
|
||||
'total' => 0,
|
||||
);
|
||||
}
|
||||
$this->assertEquals($rs3, $expect3);
|
||||
|
||||
// minutes
|
||||
$rs4 = $this->appCommonTimeUtil::createDefaultTimeLine($start, $end, 'minutes');
|
||||
$expect4 = array();
|
||||
for ($i = 0; $i <= 23; $i++){
|
||||
if($i < 10){
|
||||
$i = '0'.$i;
|
||||
}
|
||||
for ($j = 0; $j <= 59; $j++){
|
||||
if($j < 10){
|
||||
$j = '0'.$j;
|
||||
}
|
||||
$time = $start.' '.$i.':'.$j.':00';
|
||||
$expect4[$time] = array(
|
||||
'time' => $time,
|
||||
'total' => 0,
|
||||
);
|
||||
}
|
||||
}
|
||||
$this->assertEquals($rs4, $expect4);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @group testFormatStartTime
|
||||
*/
|
||||
public function testFormatStartTime()
|
||||
{
|
||||
$date1 = date("Y-m-d");
|
||||
$format1 = '00:00:00';
|
||||
$expect1 = date("Y-m-d 00:00:00");
|
||||
$rs1 = $this->appCommonTimeUtil::formatStartTime($date1, $format1);
|
||||
$this->assertEquals($rs1, $expect1);
|
||||
|
||||
|
||||
$format2 = 'H-i';
|
||||
$expect2 = date("Y-m-d 00-00");
|
||||
$rs2 = $this->appCommonTimeUtil::formatStartTime($date1, $format2);
|
||||
$this->assertEquals($rs2, $expect2);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
66
tests/base/Domain/RSA_Test.php
Normal file
66
tests/base/Domain/RSA_Test.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* PhalApi_Base\Domain\RSA_Test
|
||||
*
|
||||
* 针对 ../src/base/Domain/RSA.php Base\Domain\RSA 类的PHPUnit单元测试
|
||||
*
|
||||
* @author: dogstar 20200414
|
||||
*/
|
||||
|
||||
namespace tests\Base\Domain;
|
||||
use Base\Domain\RSA;
|
||||
|
||||
class PhpUnderControl_BaseDomainRSA_Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public $baseDomainRSA;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$domain = new \Base\Domain\Apps();
|
||||
$domain->addApp('name_rsa', 'app_key_rsa', 'xxx');
|
||||
|
||||
$this->baseDomainRSA = new \Base\Domain\RSA('app_key_rsa');
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
// 输出本次单元测试所执行的SQL语句
|
||||
// var_dump(\PhalApi\DI()->tracer->getSqls());
|
||||
|
||||
// 输出本次单元测试所涉及的追踪埋点
|
||||
// var_dump(\PhalApi\DI()->tracer->getStack());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @group testEncrypt
|
||||
*/
|
||||
public function testEncrypt()
|
||||
{
|
||||
$data = 'pro';
|
||||
|
||||
$rs = $this->baseDomainRSA->encrypt($data);
|
||||
|
||||
$this->assertTrue(is_string($rs));
|
||||
$this->assertNotEmpty($rs);
|
||||
|
||||
$deRs = $this->baseDomainRSA->decrypt($rs);
|
||||
$this->assertEquals('pro', $deRs);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testDecrypt
|
||||
*/
|
||||
public function testDecrypt()
|
||||
{
|
||||
$data = 'mmmmm';
|
||||
|
||||
$rs = $this->baseDomainRSA->decrypt($data);
|
||||
|
||||
$this->assertNull($rs);
|
||||
}
|
||||
|
||||
}
|
||||
143
tests/base/Domain/Redis_Test.php
Normal file
143
tests/base/Domain/Redis_Test.php
Normal file
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
/**
|
||||
* PhalApi_Base\Domain\Redis_Test
|
||||
*
|
||||
* 针对 ../src/base/Domain/Redis.php Base\Domain\Redis 类的PHPUnit单元测试
|
||||
*
|
||||
* @author: dogstar 20200717
|
||||
*/
|
||||
|
||||
namespace tests\Base\Domain;
|
||||
use Base\Domain\Redis;
|
||||
|
||||
class PhpUnderControl_BaseDomainRedis_Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public $baseDomainRedis;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->baseDomainRedis = new \Base\Domain\Redis();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
// 输出本次单元测试所执行的SQL语句
|
||||
// var_dump(\PhalApi\DI()->tracer->getSqls());
|
||||
|
||||
// 输出本次单元测试所涉及的追踪埋点
|
||||
// var_dump(\PhalApi\DI()->tracer->getStack());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @group testGet
|
||||
*/
|
||||
public function testGet()
|
||||
{
|
||||
$key = 'unittest';
|
||||
|
||||
$this->baseDomainRedis->set($key, '2020');
|
||||
|
||||
$rs = $this->baseDomainRedis->get($key);
|
||||
|
||||
$this->assertEquals('2020', $rs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testSet
|
||||
*/
|
||||
public function testSet()
|
||||
{
|
||||
$key = 'testSet_pro';
|
||||
$value = 'pro';
|
||||
$expire = null;
|
||||
|
||||
$rs = $this->baseDomainRedis->set($key, $value, $expire);
|
||||
|
||||
$key = 'testSet_pro_1';
|
||||
$value = 'pro';
|
||||
$expire = 0;
|
||||
|
||||
$rs = $this->baseDomainRedis->set($key, $value, $expire);
|
||||
|
||||
$key = 'testSet_pro_2';
|
||||
$value = 'pro';
|
||||
$expire = 10;
|
||||
|
||||
$rs = $this->baseDomainRedis->set($key, $value, $expire);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testIncr
|
||||
*/
|
||||
public function testIncr()
|
||||
{
|
||||
$key = 'testIncr_pro';
|
||||
|
||||
$rs = $this->baseDomainRedis->incr($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testIncrBy
|
||||
*/
|
||||
public function testIncrBy()
|
||||
{
|
||||
$key = 'testIncr_pro';
|
||||
$value = 10;
|
||||
|
||||
$rs = $this->baseDomainRedis->incrBy($key, $value);
|
||||
|
||||
$this->assertGreaterThan($value, $this->baseDomainRedis->get($key));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testDecr
|
||||
*/
|
||||
public function testDecr()
|
||||
{
|
||||
$key = 'testDecr_pro';
|
||||
|
||||
$rs = $this->baseDomainRedis->decr($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testDecrBy
|
||||
*/
|
||||
public function testDecrBy()
|
||||
{
|
||||
$key = 'testDecr';
|
||||
$value = '10';
|
||||
|
||||
$rs = $this->baseDomainRedis->decrBy($key, $value);
|
||||
|
||||
$this->assertLessThan(0, $this->baseDomainRedis->get($key));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testDel
|
||||
*/
|
||||
public function testDel()
|
||||
{
|
||||
$key = 'xxxxx_pro';
|
||||
|
||||
$rs = $this->baseDomainRedis->del($key);
|
||||
|
||||
$this->assertTrue(is_int($rs));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testExists
|
||||
*/
|
||||
public function testExists()
|
||||
{
|
||||
$key = 'hhhhhh';
|
||||
|
||||
$rs = $this->baseDomainRedis->exists($key);
|
||||
|
||||
$this->assertEquals(0, $rs);
|
||||
}
|
||||
|
||||
}
|
||||
210
tests/base/Domain/Rights_Test.php
Normal file
210
tests/base/Domain/Rights_Test.php
Normal file
@@ -0,0 +1,210 @@
|
||||
<?php
|
||||
/**
|
||||
* PhalApi_Base\Domain\Rights_Test
|
||||
*
|
||||
* 针对 ../src/app/Domain/Rights.php Base\Domain\Rights 类的PHPUnit单元测试
|
||||
*
|
||||
* @author: dogstar 20200408
|
||||
*/
|
||||
|
||||
namespace tests\Base\Domain;
|
||||
use Base\Domain\Rights;
|
||||
|
||||
class PhpUnderControl_AppDomainRights_Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public $appDomainRights;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->appDomainRights = new \Base\Domain\Rights();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
// 输出本次单元测试所执行的SQL语句
|
||||
// var_dump(\PhalApi\DI()->tracer->getSqls());
|
||||
|
||||
// 输出本次单元测试所涉及的追踪埋点
|
||||
// var_dump(\PhalApi\DI()->tracer->getStack());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @group testCheckAppRights
|
||||
*/
|
||||
public function testCheckAppRights()
|
||||
{
|
||||
$appKey = 'xxxx';
|
||||
$service = 'App.HH.YY';
|
||||
|
||||
$rs = $this->appDomainRights->checkAppRights($appKey, $service);
|
||||
|
||||
$this->assertTrue($rs);
|
||||
}
|
||||
|
||||
// 整个流程的测试,从创建开发者账号、创建应用,到分配接口权限,检测权限,步步为营
|
||||
public function testCheckAppRightsAllInOne()
|
||||
{
|
||||
$appKey = 'rights_app_key';
|
||||
$service = 'App.AAA.BBBRights';
|
||||
|
||||
// 往回走,最终是true,测试配置
|
||||
$rs = $this->appDomainRights->checkAppRights($appKey, $service);
|
||||
$this->assertTrue($rs);
|
||||
|
||||
// 账号
|
||||
$userDomain = new \Base\Domain\User();
|
||||
$uid = $userDomain->register('rights_user', '123456', '', '', '', 0, '', 100);
|
||||
// 应用
|
||||
$appDomain = new \Base\Domain\Apps();
|
||||
$appDomain->addApp('test', $appKey, 'hjkghjhj', 0, $uid, '', 1);
|
||||
|
||||
// 账号类型权限-开
|
||||
$this->appDomainRights->assignRightsForDevTypeOrNot($service, 100);
|
||||
$rs = $this->appDomainRights->checkAppRights($appKey, $service);
|
||||
$this->assertTrue($rs);
|
||||
// 账号类型权限-关
|
||||
$this->appDomainRights->assignRightsForDevTypeOrNot($service, 100);
|
||||
$rs = $this->appDomainRights->checkAppRights($appKey, $service);
|
||||
$this->assertFalse($rs);
|
||||
|
||||
// 开发者账号权限-开
|
||||
$this->appDomainRights->createNewRightsRule($service, 0, $uid, '', true);
|
||||
$rs = $this->appDomainRights->checkAppRights($appKey, $service);
|
||||
$this->assertTrue($rs);
|
||||
// 开发者-关
|
||||
|
||||
// 最后,app_key-关
|
||||
$this->appDomainRights->createNewRightsRule($service, 0, 0, $appKey, false);
|
||||
$rs = $this->appDomainRights->checkAppRights($appKey, $service);
|
||||
$this->assertFalse($rs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testAssignRights
|
||||
*/
|
||||
//public function testAssignRights()
|
||||
//{
|
||||
// $appKey = '';
|
||||
// $service = '';
|
||||
|
||||
// $rs = $this->appDomainRights->assignRights($appKey, $service);
|
||||
//}
|
||||
|
||||
///**
|
||||
// * @group testRemoveRights
|
||||
// */
|
||||
//public function testRemoveRights()
|
||||
//{
|
||||
// $appKey = '';
|
||||
// $service = '';
|
||||
// $adminUid = null;
|
||||
|
||||
// $rs = $this->appDomainRights->removeRights($appKey, $service, $adminUid);
|
||||
//}
|
||||
|
||||
/**
|
||||
* @group testGetRightsForApp
|
||||
*/
|
||||
//public function testGetRightsForApp()
|
||||
//{
|
||||
// $appKey = 'xxxx';
|
||||
|
||||
// $rs = $this->appDomainRights->getRightsForApp($appKey);
|
||||
//}
|
||||
|
||||
/**
|
||||
* @group testListAllRightsForDeveloperType
|
||||
*/
|
||||
public function testListAllRightsForDeveloperType()
|
||||
{
|
||||
$rs = $this->appDomainRights->listAllRightsForDeveloperType();
|
||||
|
||||
$this->assertNotEmpty($rs['items']);
|
||||
$this->assertNotEmpty($rs['dev_types']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testGetRightsForDevApp
|
||||
*/
|
||||
public function testGetRightsForDevApp()
|
||||
{
|
||||
$uid = '1';
|
||||
$appKey = 'xxx';
|
||||
|
||||
$rs = $this->appDomainRights->getRightsForDevApp($uid, $appKey);
|
||||
|
||||
$this->assertTrue(is_array($rs));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testAssignRightsForDevTypeOrNot
|
||||
*/
|
||||
public function testAssignRightsForDevTypeOrNot()
|
||||
{
|
||||
$rightsService = 'App.KK.LL';
|
||||
$memberType = 100;
|
||||
|
||||
$rs = $this->appDomainRights->assignRightsForDevTypeOrNot($rightsService, $memberType);
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testSearchRightsList
|
||||
*/
|
||||
public function testSearchRightsList()
|
||||
{
|
||||
$rightsService = 'App';
|
||||
$memberType = 100;
|
||||
$userId = 1;
|
||||
$appKey = 'abc';
|
||||
$page = 1;
|
||||
$perpage = 5;
|
||||
|
||||
$rs = $this->appDomainRights->searchRightsList($rightsService, $memberType, $userId, $appKey, $page, $perpage);
|
||||
|
||||
$this->assertNotEmpty($rs['dev_types']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testAssignRightsOrNot
|
||||
*/
|
||||
public function testAssignRightsOrNot()
|
||||
{
|
||||
$id = '1';
|
||||
|
||||
$rs = $this->appDomainRights->assignRightsOrNot($id);
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testDelelteRightsRule
|
||||
*/
|
||||
public function testDelelteRightsRule()
|
||||
{
|
||||
$id = '9999';
|
||||
|
||||
$rs = $this->appDomainRights->delelteRightsRule($id);
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testCreateNewRightsRule
|
||||
*/
|
||||
public function testCreateNewRightsRule()
|
||||
{
|
||||
$rightsService = 'App.xxxxx.yyyyyy';
|
||||
$memberType = 100;
|
||||
$userId = 0;
|
||||
$appKey = '';
|
||||
$isAllow = true;
|
||||
|
||||
$rs = $this->appDomainRights->createNewRightsRule($rightsService, $memberType, $userId, $appKey, $isAllow);
|
||||
}
|
||||
|
||||
}
|
||||
112
tests/bootstrap.php
Normal file
112
tests/bootstrap.php
Normal file
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
// ---------------------------------------------------------------------------------
|
||||
// _____ _ _ _ _____
|
||||
// | __ \ | | | | /\ (_) | __ \
|
||||
// | |__) || |__ __ _ | | / \ _ __ _ | |__) |_ __ ___
|
||||
// | ___/ | '_ \ / _` || | / /\ \ | '_ \ | | | ___/| '__|/ _ \
|
||||
// | | | | | || (_| || | / ____ \ | |_) || | | | | | | (_) |
|
||||
// |_| |_| |_| \__,_||_|/_/ \_\| .__/ |_| |_| |_| \___/
|
||||
// | |
|
||||
// |_|
|
||||
// PhalApi Pro 专业版
|
||||
// 广州果创网络科技有限公司
|
||||
//
|
||||
// ---------------------------------------------------------------------------------
|
||||
//
|
||||
// 一、协议的许可和权利
|
||||
// 1. 您可以在完全遵守本协议的基础上,将本软件应用于商业用途;
|
||||
// 2. 您可以在协议规定的约束和限制范围内修改本产品源代码或界面风格以适应您的要求;
|
||||
// 3. 您拥有使用本产品中的全部内容资料、商品信息及其他信息的所有权,并独立承担与其内容相关的
|
||||
// 法律义务;
|
||||
// 4. 获得商业授权之后,您可以将本软件应用于商业用途,自授权时刻起,在技术支持期限内拥有通过
|
||||
// 指定的方式获得指定范围内的技术支持服务;
|
||||
//
|
||||
// 二、协议的约束和限制
|
||||
// 1. 未获商业授权之前,禁止将本软件用于商业用途(包括但不限于企业法人经营的产品、经营性产品
|
||||
// 以及以盈利为目的或实现盈利产品);
|
||||
// 2. 未获商业授权之前,禁止在本产品的整体或在任何部分基础上发展任何派生版本、修改版本或第三
|
||||
// 方版本用于重新开发;
|
||||
// 3. 如果您未能遵守本协议的条款,您的授权将被终止,所被许可的权利将被收回并承担相应法律责任;
|
||||
//
|
||||
// 三、有限担保和免责声明
|
||||
// 1. 本软件及所附带的文件是作为不提供任何明确的或隐含的赔偿或担保的形式提供的;
|
||||
// 2. 用户出于自愿而使用本软件,您必须了解使用本软件的风险,在尚未获得商业授权之前,我们不承
|
||||
// 诺提供任何形式的技术支持、使用担保,也不承担任何因使用本软件而产生问题的相关责任;
|
||||
// 3. 广州果创网络科技有限公司不对使用本产品构建的商城中的内容信息承担责任,但在不侵犯用户隐
|
||||
// 私信息的前提下,保留以任何方式获取用户信息及商品信息的权利;
|
||||
//
|
||||
// 有关本产品最终用户授权协议、商业授权与技术服务的详细内容,均由广州果创网络科技有限公司独家
|
||||
// 提供。广州果创网络科技有限公司拥有在不事先通知的情况下,修改授权协议的权力,修改后的协议对
|
||||
// 改变之日起的新授权用户生效。电子文本形式的授权协议如同双方书面签署的协议一样,具有完全的和
|
||||
// 等同的法律效力。您一旦开始修改、安装或使用本产品,即被视为完全理解并接受本协议的各项条款,
|
||||
// 在享有上述条款授予的权力的同时,受到相关的约束和限制。协议许可范围以外的行为,将直接违反本
|
||||
// 授权协议并构成侵权,我们有权随时终止授权,责令停止损害,并保留追究相关责任的权力。
|
||||
//
|
||||
// ---------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 单元测试启动文件
|
||||
* @author dogstar 20170703
|
||||
*/
|
||||
|
||||
use PhalApi\Logger;
|
||||
use PhalApi\Logger\ExplorerLogger;
|
||||
use PhalApi\Config\FileConfig;
|
||||
use PhalApi\Database\NotORMDatabase;
|
||||
|
||||
/** ---------------- 根目录定义,自动加载 ---------------- **/
|
||||
|
||||
require_once dirname(__FILE__) . '/../public/init.php';
|
||||
|
||||
$debug = true;
|
||||
$isRelease = false;
|
||||
// 发布时隐藏不必要的输出
|
||||
if (!empty($_ENV['test_mode']) && $_ENV['test_mode'] == 'release') {
|
||||
$isRelease = true;
|
||||
}
|
||||
|
||||
// 开启调试模式,不进行签名验证
|
||||
$di->debug = $debug;
|
||||
|
||||
// 兼容高版本的PHPUnit
|
||||
if (!class_exists('PHPUnit_Framework_TestCase')) {
|
||||
class PHPUnit_Framework_TestCase extends \PHPUnit\Framework\TestCase { }
|
||||
}
|
||||
|
||||
//日记纪录 - Explorer
|
||||
if (!$isRelease) {
|
||||
\PhalApi\DI()->logger = new ExplorerLogger(
|
||||
Logger::LOG_LEVEL_DEBUG | Logger::LOG_LEVEL_INFO | Logger::LOG_LEVEL_ERROR);
|
||||
}
|
||||
|
||||
$di->config = new FileConfig(dirname(__FILE__) . '/config');
|
||||
|
||||
// 数据操作 - 基于NotORM
|
||||
$di->notorm = new NotORMDatabase($di->config->get('dbs'), $di->debug);
|
||||
|
||||
$di->cache = new \PhalApi\Cache\FileCache(array('path' => dirname(__FILE__) . '/runtime'));
|
||||
|
||||
class TestFilter extends \Base\Common\Filter {
|
||||
protected function checkNamespace() {
|
||||
// 管理员允许调用Admin服务
|
||||
}
|
||||
}
|
||||
$di->filter = new TestFilter();
|
||||
|
||||
// 导入数据库
|
||||
if (empty($_ENV['not_sql'])) {
|
||||
echo "正在重建数据库……\n";
|
||||
$sqlFile = API_ROOT . '/data/phalapi_pro.sql';
|
||||
$sqlContent = file_get_contents($sqlFile);
|
||||
$sqlArr = explode(";\n", $sqlContent);
|
||||
foreach ($sqlArr as $sql) {
|
||||
$sql = trim($sql);
|
||||
if (empty($sqlArr)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// echo $sql, PHP_EOL;
|
||||
|
||||
\PhalApi\DI()->notorm->demo->executeSql($sql);
|
||||
}
|
||||
}
|
||||
108
tests/config/app.php
Normal file
108
tests/config/app.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
/**
|
||||
* 请在下面放置任何您需要的应用配置
|
||||
*
|
||||
* @license http://www.phalapi.net/license GPL 协议
|
||||
* @link http://www.phalapi.net/
|
||||
* @author dogstar <chanzonghuang@gmail.com> 2017-07-13
|
||||
*/
|
||||
|
||||
return array(
|
||||
|
||||
/**
|
||||
* 应用接口层的统一参数
|
||||
*/
|
||||
'apiCommonRules' => array(
|
||||
// 'appKey' => array('name' => 'app_key', 'default' => '', 'desc' => 'app_key,用于区分客户端应用'),
|
||||
'accessToken' => array('name' => 'access_token', 'default' => '', 'desc' => '访问令牌,仅当开启签名验证时需要传递,生成令牌可使用<a href="/docs.php?service=App.Auth.ApplyToken&detail=1&type=fold">App.Auth.ApplyToken接口</a>'),
|
||||
//'sign' => array('name' => 'sign', 'require' => true),
|
||||
),
|
||||
|
||||
/**
|
||||
* 接口服务白名单,格式:接口服务类名.接口服务方法名
|
||||
*
|
||||
* 示例:
|
||||
* - *.* 通配,全部接口服务,慎用!
|
||||
* - Site.* Api_Default接口类的全部方法
|
||||
* - *.Index 全部接口类的Index方法
|
||||
* - Site.Index 指定某个接口服务,即Api_Default::Index()
|
||||
*/
|
||||
'service_whitelist' => array(
|
||||
'Site.Index',
|
||||
'Auth.*', // 授权时不需要验证
|
||||
'User.Register', // 注册时不需要验证
|
||||
'QrCode.Png',
|
||||
'File.Upload',
|
||||
'Search.GetByKeyWord',
|
||||
),
|
||||
|
||||
/**
|
||||
* JWT令牌
|
||||
*/
|
||||
'jwt' => array(
|
||||
'key' => '*#FD2F9DM~E*', // 用于加密的key(安装时自动生成,不能修改!)
|
||||
'exp' => 30 * 86400, // 令牌生成后多少秒内有效,可自行修改
|
||||
),
|
||||
|
||||
/**
|
||||
* 用户
|
||||
*/
|
||||
'member' => array(
|
||||
'salt' => '9DfnseJ%sD#', // 用于增强用户密码(安装时自动生成,不能修改!)
|
||||
),
|
||||
|
||||
/**
|
||||
* 项目配置
|
||||
*/
|
||||
'project' => array(
|
||||
// 项目名称
|
||||
'name' => 'PhalApi专业版',
|
||||
// logo链接
|
||||
'logo' => '/logo.png',
|
||||
// 顶端图标
|
||||
'ico' => '/favicon.ico',
|
||||
// 查看文档的密码,为空时不需要密码
|
||||
'doc_view_code' => '',
|
||||
// 总开关,是否允许会员注册,true允许,false不允许
|
||||
'is_member_register' => true,
|
||||
// 是否允许开发者注册,true允许,false不允许
|
||||
'is_dev_register' => true,
|
||||
// 0,100,101,200,201为系统自带等级,不宜更改。可扩展追加
|
||||
'member_level_map' => array(
|
||||
// 0~99区间表示会员
|
||||
0 => array(
|
||||
'name' => '普通会员',
|
||||
'is_register' => true, // 是否允许注册
|
||||
),
|
||||
|
||||
// 100~199区间表示开发者
|
||||
100 => array(
|
||||
'name' => '个人开发者',
|
||||
'is_register' => true, // 是否允许开放平台注册
|
||||
),
|
||||
101 => array(
|
||||
'name' => '企业开发者',
|
||||
'is_register' => true, // 是否允许开放平台注册
|
||||
),
|
||||
|
||||
// 200~255区间表示内部管理员
|
||||
200 => array(
|
||||
'name' => '管理员',
|
||||
'is_register' => false, // 是否允许注册
|
||||
),
|
||||
255 => array(
|
||||
'name' => '超级管理员',
|
||||
'is_register' => false, // 是否允许注册
|
||||
),
|
||||
),
|
||||
// 每个开发者最多可以创建的应用数量上限
|
||||
'dev_max_app_num' => 10,
|
||||
// 默认应用接口每日接口次数上限,0表示没有限制
|
||||
'default_daily_app_limit' => 100000,
|
||||
// 默认接口权限,没有任何配置时应用对于接口调用的默认权限,推荐设置为false【测试专用】
|
||||
'default_app_api_rigths_is_allow' => true,
|
||||
// 开放接口的命名空间,配置后可提供接口权限分配,可配置多个
|
||||
'open_api_namespaces' => array('App'),
|
||||
),
|
||||
|
||||
);
|
||||
53
tests/config/dbs.php
Normal file
53
tests/config/dbs.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* 分库分表的自定义数据库路由配置
|
||||
*
|
||||
* @license http://www.phalapi.net/license GPL 协议
|
||||
* @link http://www.phalapi.net/
|
||||
* @author: dogstar <chanzonghuang@gmail.com> 2015-02-09
|
||||
*/
|
||||
|
||||
return array(
|
||||
/**
|
||||
* DB数据库服务器集群
|
||||
*/
|
||||
'servers' => array(
|
||||
'db_master' => array( //服务器标记
|
||||
'host' => '127.0.0.1', //数据库域名
|
||||
'name' => 'phalapi_pro_test', //数据库名字
|
||||
'user' => 'dogstar', //数据库用户名
|
||||
'password' => '123', //数据库密码
|
||||
'port' => '3306', //数据库端口
|
||||
'charset' => 'utf8mb4', //数据库字符集
|
||||
'pdo_attr_string' => false, // 数据库查询结果统一使用字符串,true是,false否
|
||||
'driver_options' => array( // PDO初始化时的连接选项配置
|
||||
// 若需要更多配置,请参考官方文档:https://www.php.net/manual/zh/pdo.constants.php
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
/**
|
||||
* 自定义路由表
|
||||
*/
|
||||
'tables' => array(
|
||||
//通用路由
|
||||
'__default__' => array(
|
||||
'prefix' => 'pp_',
|
||||
'key' => 'id',
|
||||
'map' => array(
|
||||
array('db' => 'db_master'),
|
||||
),
|
||||
),
|
||||
|
||||
/**
|
||||
'demo' => array( //表名
|
||||
'prefix' => '', //表名前缀
|
||||
'key' => 'id', //表主键名
|
||||
'map' => array( //表路由配置
|
||||
array('db' => 'db_master'), //单表配置:array('db' => 服务器标记)
|
||||
array('start' => 0, 'end' => 2, 'db' => 'db_master'), //分表配置:array('start' => 开始下标, 'end' => 结束下标, 'db' => 服务器标记)
|
||||
),
|
||||
),
|
||||
*/
|
||||
),
|
||||
);
|
||||
53
tests/config/dbs.php.sample
Normal file
53
tests/config/dbs.php.sample
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* 分库分表的自定义数据库路由配置
|
||||
*
|
||||
* @license http://www.phalapi.net/license GPL 协议
|
||||
* @link http://www.phalapi.net/
|
||||
* @author: dogstar <chanzonghuang@gmail.com> 2015-02-09
|
||||
*/
|
||||
|
||||
return array(
|
||||
/**
|
||||
* DB数据库服务器集群
|
||||
*/
|
||||
'servers' => array(
|
||||
'db_master' => array( //服务器标记
|
||||
'host' => '127.0.0.1', //数据库域名
|
||||
'name' => 'phalapi_pro_test', //数据库名字
|
||||
'user' => 'dogstar', //数据库用户名
|
||||
'password' => '123', //数据库密码
|
||||
'port' => '3306', //数据库端口
|
||||
'charset' => 'utf8mb4', //数据库字符集
|
||||
'pdo_attr_string' => false, // 数据库查询结果统一使用字符串,true是,false否
|
||||
'driver_options' => array( // PDO初始化时的连接选项配置
|
||||
// 若需要更多配置,请参考官方文档:https://www.php.net/manual/zh/pdo.constants.php
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
/**
|
||||
* 自定义路由表
|
||||
*/
|
||||
'tables' => array(
|
||||
//通用路由
|
||||
'__default__' => array(
|
||||
'prefix' => 'pp_',
|
||||
'key' => 'id',
|
||||
'map' => array(
|
||||
array('db' => 'db_master'),
|
||||
),
|
||||
),
|
||||
|
||||
/**
|
||||
'demo' => array( //表名
|
||||
'prefix' => '', //表名前缀
|
||||
'key' => 'id', //表主键名
|
||||
'map' => array( //表路由配置
|
||||
array('db' => 'db_master'), //单表配置:array('db' => 服务器标记)
|
||||
array('start' => 0, 'end' => 2, 'db' => 'db_master'), //分表配置:array('start' => 开始下标, 'end' => 结束下标, 'db' => 服务器标记)
|
||||
),
|
||||
),
|
||||
*/
|
||||
),
|
||||
);
|
||||
61
tests/config/mall.php
Normal file
61
tests/config/mall.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
// 商城相关的配置
|
||||
return array(
|
||||
// 商品套餐的有效时间列表
|
||||
'product_expire_time_list' => array(
|
||||
2592000 => '1个月',
|
||||
5184000 => '2个月',
|
||||
7776000 => '3个月',
|
||||
15552000 => '6个月',
|
||||
946080000 => '1年',
|
||||
1892160000 => '2年',
|
||||
18921600000 => '不限',
|
||||
),
|
||||
// 下单时购买数量列表
|
||||
'order_amount_list' => array(
|
||||
1 => 1,
|
||||
2 => 2,
|
||||
3 => 3,
|
||||
4 => 4,
|
||||
5 => 5,
|
||||
6 => 6,
|
||||
7 => 7,
|
||||
8 => 8,
|
||||
9 => 9,
|
||||
10 => 10,
|
||||
),
|
||||
// 默认支付配置
|
||||
'default_pay_type_list' => array(
|
||||
'alipay' => array(
|
||||
'switch' => 1,
|
||||
'mode' => 'production', // sandbox | production
|
||||
'name' => '支付宝',
|
||||
'app_id' => '2021001143654222',
|
||||
'seller_id' => '',
|
||||
'rsa_private_key' => "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCNK1j7s5ZdnwNyyb4kO6d9MhQrnl2FL8E1HGUCHlBHoFFKOS5Sd7UxW9CTByfvEL4xcle6v9ggQ5/njKI6aM3ZOvfmBKJKD3WVszvg+4eNU7O/FrVzbUGdt1QZvw17gLZh7qF2448y4mu1H5dWeTaLxBxBd5Uz1TshL8zt0usw789I2+REZa0zN2wzBZJN+cHl6oXIaUHG8cCTiLw8JBCLhbC3O7NJ9soWQluA0iaHgeQBDzhe9z2++lmQHvShzrrvpr33KQ3v8Pd6CntZOJewpOuE/ptFpQQM5gT2Xgj9ZvkP+072zq
|
||||
eSmh/z16OOycFDNORUGuPamqgvkUeTls9/AgMBAAECggEAdKo7OqBbBvoP7oBdfDI0o9mMI9QX86bYpFzX+R02OUt7gryo1IyLmMQJJkkGrqKGm/SkHfjH0zov3zsxItZUME90aYqw2EXYZiQeuzsD9j8TUDujL0Y+sOm+PhzPNp7TmzGMD
|
||||
OXZBTNr0d7Owi8gbfdfZpc+Hfz9hdqsIGtr5R8+FsRR7ikfKhD74E1jEF+zlksmsZLcaY+fiD1KGdFKt6LucBp9C+pB4py2agbAcfz158oAW1qsEVLFFTGUmg/KfBZ/0U74SJwICtKAV3W3fAWQu96J1SBPu4g8iDZVJcD1LBp+KJok/cYo
|
||||
ahxKGfshP/JBmbqe6amXFEYmZAt8cQKBgQDWQ8Zt/f2WwrUWvwxCigwhAGBWcQlW5wq0wAE6iU31+8in+WXYAhkZ169zsyOw7iq2fTOChvNmJvzdtYDHVqXEsGPmi2jnqYfZYOHfyUeiUqrY8czeSBKIrYgaEUB3UcBNWeojckTtWEiUbq8
|
||||
IBOQACuUUuEtGzV+8O36T+AmnaQKBgQCoqrLtUDpzSL49V041vKBtp7KS/pnS3uZ6gse1A+pYcDkIXjOSNHAhYwcU5tEnzLGTUGeGHf4ur9xKlppeQ2uuQZAkPAzdbNnYVWlPWs3SIZRZ/OPrjLHF441t9UWWfcTcNgdKQTIte5fElqOghi
|
||||
S3pLcNdPdinC0B9hmGEyyKpwKBgDGGQNszleW+43R6fC71EZCfMaVJQ0te486bgq0xB2AP7nVE5BFlir+6ZsdrZJiEtEKx9bH511CJOnFUfouUr4Qi8TRcjMbfHJNWHV9IetI+IVc7rIrEReRpl8fOrQPnVXeLjN7cjqn9eek1HCfSWZDY8
|
||||
9IyNtQKrFIpvjwdXL3hAoGBAJK2GHlQZedNiRz2SjN35dw8GJrAF7FS7gv2ohwUUc2noBRlTFqKflasOsa1l40VAglv0PzaLfUSR34hzhjccFfc87JxAYfBXSRN9xJtm8aCKvazgNWtRh0puCXDSUqED6602FaAq1LgxLzdg2roBBwxjICK
|
||||
E32U95lTJhR3rTDVAoGBAIZABIIX0bGm4htapAe+k5ylSV0jsnstwB5Ml0smJ78qlbbZbnJZLhi2erLqF93Qp+ts62zLF8NwO3ngppHMImjIs5n4yhsZPUK2VFOT19mTxEWy2JflAfIA0ifZCe4WqiW7Ui+m0Jl9sBloO1cIc01e5h2bl8B
|
||||
yMSNp7ZTRETUd", // 应用密钥
|
||||
'rsa_public_key' => '',
|
||||
'alipay_public_key' => 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAncBlnhc7nvHsuteKeSPbVAHGr4Tq35uAs52Sc/uNvHywAVW3T0/JuZhwLzfFbqHlnk9E3PeQeZHOHJ6Y9R1H1vPbeKLx0q7saEYDQjkT72rMtI/7lBhMSM0VvWZRAWZcrZ40HM8l6Ds6g9orTs2yPfCSdov0L1v5DUEdYGphJQ98fHWMXiT/3A8rCBWiAqWKYpgYwPE0sgBg+/r0zxuo/i+Yw6dyoC9fJdyy0YCHYW87VDdUZTbN+MwNDsnFKHShRM4ICe3VhPmU9su2NsoWc4aiUzQAwn/ror9hH/kai8dg+MrrQfMtTg2jfBPgi/eXWu01PVBVDuRmZ0eisF7CewIDAQAB', // 支付宝公钥
|
||||
),
|
||||
'paypal' => array(
|
||||
'switch' => 1,
|
||||
'mode' => 'sandbox',
|
||||
'name' => 'PayPal',
|
||||
'client_id' => 'AYRifj8mhRHYv163Szknac9SVLgP2eZ4Wnau-8vlnZX7rOEOm60t3EZIrIS7GvtwJz9lW4zubor6UYVD',
|
||||
'secret_key' => 'EE7LsZM46FroFLf4YxCNXfBI0ZtVCH_8NxhPSrYGovDPAr6YzSAAysB-SWLwJjuILTfe0d_GUNUOvu9t',
|
||||
'currency' => 'USD',
|
||||
),
|
||||
'cash' => array(
|
||||
'switch' => 0,
|
||||
'desc' => '请进行线下付款',
|
||||
'name' => '现金支付',
|
||||
),
|
||||
),
|
||||
);
|
||||
60
tests/config/sys.php
Normal file
60
tests/config/sys.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* 以下配置为系统级的配置,通常放置不同环境下的不同配置
|
||||
*
|
||||
* @license http://www.phalapi.net/license GPL 协议
|
||||
* @link http://www.phalapi.net/
|
||||
* @author dogstar <chanzonghuang@gmail.com> 2017-07-13
|
||||
*/
|
||||
|
||||
return array(
|
||||
/**
|
||||
* @var boolean 是否开启接口调试模式,开启后在客户端可以直接看到更多调试信息
|
||||
*/
|
||||
'debug' => false,
|
||||
|
||||
/**
|
||||
* @var boolean 是否开启NotORM调试模式,开启后仅针对NotORM服务开启调试模式
|
||||
*/
|
||||
'notorm_debug' => true,
|
||||
|
||||
/**
|
||||
* @var boolean 是否纪录SQL到日志,需要同时开启notorm_debug方可写入日志
|
||||
*/
|
||||
'enable_sql_log' => true,
|
||||
|
||||
/**
|
||||
* @var boolean 是否开启URI匹配,若未提供service(或s)参数且开启enable_uri_match才尝试进行URI路由匹配。例如:/App/User/Login映射到s=App.Usre.Login
|
||||
*/
|
||||
'enable_uri_match' => false,
|
||||
|
||||
/**
|
||||
* MC缓存服务器参考配置
|
||||
*/
|
||||
'mc' => array(
|
||||
'host' => '127.0.0.1',
|
||||
'port' => 11211,
|
||||
),
|
||||
|
||||
/**
|
||||
* Redis缓存服务器参考配置
|
||||
*/
|
||||
'redis' => array(
|
||||
'host' => '127.0.0.1',
|
||||
'port' => 6379,
|
||||
),
|
||||
|
||||
/**
|
||||
* 加密
|
||||
*/
|
||||
'crypt' => array(
|
||||
'mcrypt_iv' => '12345678', //8位
|
||||
),
|
||||
|
||||
/**
|
||||
* es配置
|
||||
*/
|
||||
'es' => array(
|
||||
'host' => '127.0.0.1:9200',
|
||||
),
|
||||
);
|
||||
94
tests/mall/Domain/Config_Test.php
Normal file
94
tests/mall/Domain/Config_Test.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/**
|
||||
* PhalApi_Mall\Domain\Config_Test
|
||||
*
|
||||
* 针对 ../src/mall/Domain/Config.php Mall\Domain\Config 类的PHPUnit单元测试
|
||||
*
|
||||
* @author: dogstar 20200925
|
||||
*/
|
||||
|
||||
namespace tests\Mall\Domain;
|
||||
use Mall\Domain\Config;
|
||||
|
||||
class PhpUnderControl_MallDomainConfig_Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public $mallDomainConfig;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->mallDomainConfig = new \Mall\Domain\Config();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
// 输出本次单元测试所执行的SQL语句
|
||||
// var_dump(\PhalApi\DI()->tracer->getSqls());
|
||||
|
||||
// 输出本次单元测试所涉及的追踪埋点
|
||||
// var_dump(\PhalApi\DI()->tracer->getStack());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @group testGetPayList
|
||||
*/
|
||||
public function testGetPayList()
|
||||
{
|
||||
$checkSwitch = true;
|
||||
|
||||
$rs = $this->mallDomainConfig->getPayList($checkSwitch);
|
||||
|
||||
$this->assertTrue(is_array($rs));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testGetDefaultPayType
|
||||
*/
|
||||
public function testGetDefaultPayType()
|
||||
{
|
||||
$rs = $this->mallDomainConfig->getDefaultPayType();
|
||||
|
||||
$this->assertNotEmpty($rs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testGetPayConfigDetail
|
||||
*/
|
||||
public function testGetPayConfigDetail()
|
||||
{
|
||||
$pay_type = 'cash';
|
||||
|
||||
$rs = $this->mallDomainConfig->getPayConfigDetail($pay_type);
|
||||
|
||||
$this->assertNotEmpty($rs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testGetPayConfig
|
||||
*/
|
||||
public function testGetPayConfig()
|
||||
{
|
||||
$rs = $this->mallDomainConfig->getPayConfig();
|
||||
|
||||
$this->assertNotEmpty($rs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testUpdatePayConfig
|
||||
*/
|
||||
public function testUpdatePayConfig()
|
||||
{
|
||||
$config = array('cash' => array('switch' => 0));
|
||||
|
||||
$rs = $this->mallDomainConfig->updatePayConfig($config);
|
||||
|
||||
$rs = $this->mallDomainConfig->getPayConfig();
|
||||
// var_dump($rs);
|
||||
|
||||
$this->assertEquals(0, $rs['cash']['switch']);
|
||||
$this->assertEquals(1, $rs['alipay']['switch']);
|
||||
}
|
||||
|
||||
}
|
||||
210
tests/mall/Domain/Flow_Test.php
Normal file
210
tests/mall/Domain/Flow_Test.php
Normal file
@@ -0,0 +1,210 @@
|
||||
<?php
|
||||
/**
|
||||
* PhalApi_Mall\Domain\Flow_Test
|
||||
*
|
||||
* 针对 ../src/mall/Domain/Flow.php Mall\Domain\Flow 类的PHPUnit单元测试
|
||||
*
|
||||
* @author: dogstar 20200915
|
||||
*/
|
||||
|
||||
namespace tests\Mall\Domain;
|
||||
use Mall\Domain\Flow;
|
||||
|
||||
class PhpUnderControl_MallDomainFlow_Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public $mallDomainFlow;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->mallDomainFlow = new \Mall\Domain\Flow();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
// 输出本次单元测试所执行的SQL语句
|
||||
// var_dump(\PhalApi\DI()->tracer->getSqls());
|
||||
|
||||
// 输出本次单元测试所涉及的追踪埋点
|
||||
// var_dump(\PhalApi\DI()->tracer->getStack());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @group testAddNewFlow
|
||||
*/
|
||||
public function testAddNewFlow()
|
||||
{
|
||||
$flow = array(
|
||||
'username' => 'rights_user',
|
||||
'product_key' => 'App.Config.GetConfig',
|
||||
'product_name' => 'test',
|
||||
'total_amount' => 10,
|
||||
'expire_time' => time() + 86400,
|
||||
);
|
||||
|
||||
$rs = $this->mallDomainFlow->addNewFlow($flow);
|
||||
}
|
||||
|
||||
public function testAddNewFlowExpireOut()
|
||||
{
|
||||
$flow = array(
|
||||
'username' => 'rights_user',
|
||||
'product_key' => 'App.Config.GetConfig',
|
||||
'product_name' => 'test',
|
||||
'total_amount' => 10,
|
||||
'expire_time' => time() - 86400, // 注意这里
|
||||
);
|
||||
|
||||
$rs = $this->mallDomainFlow->addNewFlow($flow);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testUpdateFlow
|
||||
*/
|
||||
public function testUpdateFlow()
|
||||
{
|
||||
$id = 1;
|
||||
$flow = array('total_amount' => 200);
|
||||
|
||||
$rs = $this->mallDomainFlow->updateFlow($id, $flow);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testGetFlow
|
||||
*/
|
||||
public function testGetFlow()
|
||||
{
|
||||
$id = 1;
|
||||
|
||||
$rs = $this->mallDomainFlow->getFlow($id);
|
||||
|
||||
$this->assertNotEmpty($rs);
|
||||
$this->assertEquals(200, $rs['total_amount']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testDeleteFlow
|
||||
*/
|
||||
public function testDeleteFlow()
|
||||
{
|
||||
$id = 404;
|
||||
|
||||
$rs = $this->mallDomainFlow->deleteFlow($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testGetFlowList
|
||||
*/
|
||||
public function testGetFlowList()
|
||||
{
|
||||
$page = 1;
|
||||
$perpage = 2;
|
||||
|
||||
$rs = $this->mallDomainFlow->getFlowList($page, $perpage);
|
||||
|
||||
$this->assertNotEmpty($rs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testGetFlowStatusList
|
||||
*/
|
||||
public function testGetFlowStatusList()
|
||||
{
|
||||
$isMap = true;
|
||||
|
||||
$rs = $this->mallDomainFlow->getFlowStatusList($isMap);
|
||||
|
||||
$this->assertNotEmpty($rs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testCutdown
|
||||
* 什么套餐都没有时,不需要扣费
|
||||
*/
|
||||
public function testCutdown()
|
||||
{
|
||||
$service = 'App.Config.GetConfig';
|
||||
$appKey = 'test_flow';
|
||||
|
||||
$rs = $this->mallDomainFlow->cutdown($service, $appKey);
|
||||
|
||||
$this->assertEquals(0, $rs);
|
||||
}
|
||||
|
||||
// 有付费套餐时,扣费失败
|
||||
public function testCutdownFail()
|
||||
{
|
||||
$sql = "insert into `pp_mall_product` ( `id`, `add_time`, `product_type`, `product_name`, `product_key_lower`, `amount`, `expire_time_desc`, `price`, `product_key`, `product_desc`, `original_price`, `product_status`, `expire_time`) values ( '6', '2020-09-15 10:42:19', 'api_buy', '配置接口流量套餐', 'app.config.getconfig', '220', '', '2.00', 'App.Config.GetConfig', null, '0.00', '1', '2020');";
|
||||
\PhalApi\DI()->notorm->demo->executeSql($sql);
|
||||
|
||||
$service = 'App.Config.GetConfig';
|
||||
$appKey = 'test_flow';
|
||||
|
||||
$rs = $this->mallDomainFlow->cutdown($service, $appKey);
|
||||
|
||||
$this->assertEquals(-1, $rs);
|
||||
}
|
||||
|
||||
// 有付费套餐时,增加了免费套餐,因此通过
|
||||
public function testCutdownFree()
|
||||
{
|
||||
$sql = "insert into `pp_mall_product` ( `id`, `add_time`, `product_type`, `product_name`, `product_key_lower`, `amount`, `expire_time_desc`, `price`, `product_key`, `product_desc`, `original_price`, `product_status`, `expire_time`) values ( '7', '2020-09-15 10:42:24', 'api_free', '配置接口流量套餐', 'app.config.getconfig', '2', '', '0.00', 'App.Config.GetConfig', null, '0.00', '1', '2020');";
|
||||
\PhalApi\DI()->notorm->demo->executeSql($sql);
|
||||
|
||||
$service = 'App.Config.GetConfig';
|
||||
$appKey = 'test_flow';
|
||||
|
||||
// 准备一个新的app
|
||||
$domain = new \Base\Domain\Apps();
|
||||
$domain->addApp('测试流量', $appKey, '123', 0, 10, '', 1);
|
||||
|
||||
$rs = $this->mallDomainFlow->cutdown($service, $appKey);
|
||||
$this->assertGreaterThan(0, $rs);
|
||||
|
||||
// 第2次免费
|
||||
$rs = $this->mallDomainFlow->cutdown($service, $appKey);
|
||||
$this->assertGreaterThan(0, $rs);
|
||||
|
||||
// 失败了
|
||||
$rs = $this->mallDomainFlow->cutdown($service, $appKey);
|
||||
$this->assertEquals(-1, $rs);
|
||||
}
|
||||
|
||||
public function testCutdownBuy()
|
||||
{
|
||||
// 添加流量
|
||||
$flow = array(
|
||||
'username' => 'test_dev',
|
||||
'product_key' => 'App.Config.GetConfig',
|
||||
'product_name' => 'test_flow',
|
||||
'total_amount' => 3,
|
||||
'expire_time' => time() + 86400,
|
||||
);
|
||||
|
||||
$rs = $this->mallDomainFlow->addNewFlow($flow);
|
||||
|
||||
$service = 'App.Config.GetConfig';
|
||||
$appKey = 'test_flow';
|
||||
|
||||
$rs = $this->mallDomainFlow->cutdown($service, $appKey);
|
||||
$this->assertGreaterThan(0, $rs);
|
||||
|
||||
$rs3 = $this->mallDomainFlow->cutdown($service, $appKey);
|
||||
$this->assertGreaterThan(0, $rs3);
|
||||
|
||||
$flow3 = $this->mallDomainFlow->getFlow($rs3);
|
||||
$this->assertEquals(\Mall\Model\Mall\Flow::FLOW_STATUS_USING, $flow3['flow_status']);
|
||||
|
||||
$rs4 = $this->mallDomainFlow->cutdown($service, $appKey);
|
||||
$this->assertGreaterThan(0, $rs4);
|
||||
|
||||
$flow4 = $this->mallDomainFlow->getFlow($rs4);
|
||||
$this->assertEquals(\Mall\Model\Mall\Flow::FLOW_STATUS_OUT, $flow4['flow_status']);
|
||||
|
||||
// 第4次,用光
|
||||
$rs = $this->mallDomainFlow->cutdown($service, $appKey);
|
||||
$this->assertEquals(-1, $rs);
|
||||
}
|
||||
}
|
||||
187
tests/mall/Domain/Order_Test.php
Normal file
187
tests/mall/Domain/Order_Test.php
Normal file
@@ -0,0 +1,187 @@
|
||||
<?php
|
||||
/**
|
||||
* PhalApi_Mall\Domain\Order_Test
|
||||
*
|
||||
* 针对 ../src/mall/Domain/Order.php Mall\Domain\Order 类的PHPUnit单元测试
|
||||
*
|
||||
* @author: dogstar 20200924
|
||||
*/
|
||||
|
||||
namespace tests\Mall\Domain;
|
||||
use Mall\Domain\Order;
|
||||
|
||||
class PhpUnderControl_MallDomainOrder_Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public $mallDomainOrder;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->mallDomainOrder = new \Mall\Domain\Order();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
// 输出本次单元测试所执行的SQL语句
|
||||
// var_dump(\PhalApi\DI()->tracer->getSqls());
|
||||
|
||||
// 输出本次单元测试所涉及的追踪埋点
|
||||
// var_dump(\PhalApi\DI()->tracer->getStack());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @group testGetOrderInfo
|
||||
*/
|
||||
public function testGetOrderInfo()
|
||||
{
|
||||
$sql = "insert into `pp_mall_order` ( `is_deliver`, `username`, `pay_time`, `product_type`, `product_key`, `member_id`, `order_status`, `pay_type`, `third_payment_id`, `product_expire_time`, `order_id`, `id`, `product_id`, `add_time`, `num`, `product_expire_time_desc`, `note`, `product_amount`, `price`, `order_name`) values ( '0', 'admin', '2020-09-21 21:58:55', 'api_buy', 'App.BarCode.Gen', '1', '0', 'cash', '', '86400', '2020098816064072753', '140', '4', '2020-09-15 16:06:40', '4', '1个月', 'test', '9', '2.00', '条形码流量套餐');";
|
||||
\PhalApi\DI()->notorm->demo->executeSql($sql);
|
||||
|
||||
$order_id = '2020098816064072753';
|
||||
|
||||
$rs = $this->mallDomainOrder->getOrderInfo($order_id);
|
||||
|
||||
$this->assertNotEmpty($rs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testCheckOrderPay
|
||||
*/
|
||||
public function testCheckOrderPay()
|
||||
{
|
||||
$order_id = '2020098816064072753';
|
||||
|
||||
$rs = $this->mallDomainOrder->checkOrderPay($order_id);
|
||||
|
||||
$this->assertFalse($rs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testCreateOrder
|
||||
*/
|
||||
public function testCreateOrder()
|
||||
{
|
||||
$sql = "insert into `pp_mall_product` ( `id`, `add_time`, `product_type`, `product_name`, `product_key_lower`, `amount`, `expire_time_desc`, `price`, `product_key`, `product_desc`, `original_price`, `product_status`, `expire_time`) values ( '600', '2020-09-15 10:42:19', 'api_buy', '配置接口流量套餐', 'app.config.getconfig', '220', '', '2.00', 'App.Config.GetConfig', null, '0.00', '1', '2020');";
|
||||
\PhalApi\DI()->notorm->demo->executeSql($sql);
|
||||
|
||||
$product_id = '600';
|
||||
$num = '2';
|
||||
$note = 'testtest';
|
||||
|
||||
$rs = $this->mallDomainOrder->createOrder($product_id, $num, $note);
|
||||
|
||||
$this->assertGreaterThan(0, $rs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testUpdatePayType
|
||||
*/
|
||||
public function testUpdatePayType()
|
||||
{
|
||||
$sql = "insert into `pp_mall_order` ( `is_deliver`, `username`, `pay_time`, `product_type`, `product_key`, `member_id`, `order_status`, `pay_type`, `third_payment_id`, `product_expire_time`, `order_id`, `id`, `product_id`, `add_time`, `num`, `product_expire_time_desc`, `note`, `product_amount`, `price`, `order_name`) values ( '0', 'admin', '2020-09-21 21:58:55', 'api_buy', 'App.BarCode.Gen', '1', '0', 'paypal', '', '86400', '2020091516064072153', '15', '4', '2020-09-15 16:06:40', '4', '1个月', 'test', '9', '2.00', '条形码流量套餐');";
|
||||
\PhalApi\DI()->notorm->demo->executeSql($sql);
|
||||
$id = '15';
|
||||
$pay_type = 'cash';
|
||||
|
||||
$rs = $this->mallDomainOrder->updatePayType($id, $pay_type);
|
||||
|
||||
$this->assertEquals(1, $rs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testGetMyOrderList
|
||||
*/
|
||||
public function testGetMyOrderList()
|
||||
{
|
||||
$page = '1';
|
||||
$perpage = '2';
|
||||
$uid = 1;
|
||||
|
||||
$rs = $this->mallDomainOrder->getMyOrderList($page, $perpage, $uid);
|
||||
|
||||
$this->assertNotEmpty($rs['items']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testUpdateOrder
|
||||
*/
|
||||
public function testUpdateOrder()
|
||||
{
|
||||
$sql = "insert into `pp_mall_order` ( `is_deliver`, `username`, `pay_time`, `product_type`, `product_key`, `member_id`, `order_status`, `pay_type`, `third_payment_id`, `product_expire_time`, `order_id`, `id`, `product_id`, `add_time`, `num`, `product_expire_time_desc`, `note`, `product_amount`, `price`, `order_name`) values ( '0', 'admin', '2020-09-21 21:58:55', 'api_buy', 'App.BarCode.Gen', '1', '0', 'paypal', '', '86400', '2020091516064072888', '1600', '4', '2020-09-15 16:06:40', '4', '1个月', 'test', '9', '2.00', '条形码流量套餐');";
|
||||
\PhalApi\DI()->notorm->demo->executeSql($sql);
|
||||
|
||||
$id = '1600';
|
||||
$order = array('order_status' => 10);
|
||||
$op = '';
|
||||
|
||||
$rs = $this->mallDomainOrder->updateOrder($id, $order, $op);
|
||||
|
||||
// 工人审核,发流量
|
||||
$order = array('order_status' => 20);
|
||||
$op = 'send';
|
||||
|
||||
$rs = $this->mallDomainOrder->updateOrder($id, $order, $op);
|
||||
|
||||
$count = \PhalApi\DI()->notorm->mall_flow->where('order_id', '2020091516064072888')->where('flow_status', 10)->count();
|
||||
$this->assertGreaterThan(0, $count);
|
||||
|
||||
// 退款,回收流量
|
||||
$order = array('order_status' => 30);
|
||||
$op = 'back';
|
||||
|
||||
$rs = $this->mallDomainOrder->updateOrder($id, $order, $op);
|
||||
|
||||
$count = \PhalApi\DI()->notorm->mall_flow->where('order_id', '2020091516064072888')->where('flow_status', 0)->count();
|
||||
$this->assertGreaterThan(0, $count);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testGetOrder
|
||||
*/
|
||||
public function testGetOrder()
|
||||
{
|
||||
$id = '140';
|
||||
|
||||
$rs = $this->mallDomainOrder->getOrder($id);
|
||||
|
||||
$this->assertNotEmpty($rs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testDeleteOrder
|
||||
*/
|
||||
public function testDeleteOrder()
|
||||
{
|
||||
$id = '400';
|
||||
|
||||
$rs = $this->mallDomainOrder->deleteOrder($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testGetOrderList
|
||||
*/
|
||||
public function testGetOrderList()
|
||||
{
|
||||
$page = '1';
|
||||
$perpage = '10';
|
||||
|
||||
$rs = $this->mallDomainOrder->getOrderList($page, $perpage);
|
||||
|
||||
$this->assertNotEmpty($rs['items']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testGetOrderStatusList
|
||||
*/
|
||||
public function testGetOrderStatusList()
|
||||
{
|
||||
$isMap = true;
|
||||
|
||||
$rs = $this->mallDomainOrder->getOrderStatusList($isMap);
|
||||
|
||||
$this->assertNotEmpty($rs);
|
||||
}
|
||||
|
||||
}
|
||||
90
tests/mall/Domain/Pay_Test.php
Normal file
90
tests/mall/Domain/Pay_Test.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* PhalApi_Mall\Domain\Pay_Test
|
||||
*
|
||||
* 针对 ../src/mall/Domain/Pay.php Mall\Domain\Pay 类的PHPUnit单元测试
|
||||
*
|
||||
* @author: dogstar 20200924
|
||||
*/
|
||||
|
||||
namespace tests\Mall\Domain;
|
||||
use Mall\Domain\Pay;
|
||||
|
||||
class PhpUnderControl_MallDomainPay_Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public $mallDomainPay;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->mallDomainPay = new \Mall\Domain\Pay();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
// 输出本次单元测试所执行的SQL语句
|
||||
// var_dump(\PhalApi\DI()->tracer->getSqls());
|
||||
|
||||
// 输出本次单元测试所涉及的追踪埋点
|
||||
// var_dump(\PhalApi\DI()->tracer->getStack());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @group testStartPay
|
||||
*/
|
||||
public function testStartPay()
|
||||
{
|
||||
$sql = "insert into `pp_mall_order` ( `is_deliver`, `username`, `pay_time`, `product_type`, `product_key`, `member_id`, `order_status`, `pay_type`, `third_payment_id`, `product_expire_time`, `order_id`, `id`, `product_id`, `add_time`, `num`, `product_expire_time_desc`, `note`, `product_amount`, `price`, `order_name`) values ( '0', 'admin', '2020-09-21 21:58:55', 'api_buy', 'App.BarCode.Gen', '1', '0', 'cash', '', '86400', '2020091516064079999', '159', '4', '2020-09-15 16:06:40', '4', '1个月', 'test', '9', '2.00', '条形码流量套餐');";
|
||||
\PhalApi\DI()->notorm->demo->executeSql($sql);
|
||||
|
||||
$order_id = '2020091516064079999';
|
||||
$pay_type = null;
|
||||
|
||||
$rs = $this->mallDomainPay->startPay($order_id, $pay_type);
|
||||
|
||||
$this->assertEquals('cash', $rs['pay_type']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testCheckPay
|
||||
*/
|
||||
public function testCheckPay()
|
||||
{
|
||||
$orderInfo = array('order_id' => '2020091516064079999', 'pay_type' => 'cash');;
|
||||
|
||||
$rs = $this->mallDomainPay->checkPay($orderInfo);
|
||||
|
||||
$this->assertFalse($rs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testAlipayNotify
|
||||
*/
|
||||
//public function testAlipayNotify()
|
||||
//{
|
||||
// $rs = $this->mallDomainPay->alipayNotify();
|
||||
//}
|
||||
|
||||
/**
|
||||
* @group testCapturePaypalOrder
|
||||
*/
|
||||
public function testCapturePaypalOrder()
|
||||
{
|
||||
$sql = "insert into `pp_mall_order` ( `is_deliver`, `username`, `pay_time`, `product_type`, `product_key`, `member_id`, `order_status`, `pay_type`, `third_payment_id`, `product_expire_time`, `order_id`, `id`, `product_id`, `add_time`, `num`, `product_expire_time_desc`, `note`, `product_amount`, `price`, `order_name`) values ( '1', 'admin', '2020-09-22 16:11:02', 'api_buy', 'App.BarCode.Gen', '1', '20', 'paypal', '2D387077TH8550000', '86400', '2020091516064072543', '4', '4', '2020-09-15 16:06:40', '4', '1个月', 'test', '9', '2.00', '条形码流量套餐');";
|
||||
\PhalApi\DI()->notorm->demo->executeSql($sql);
|
||||
|
||||
$orderInfo = \PhalApi\DI()->notorm->mall_order->where('order_id', '2D387077TH8550000')->fetchOne();
|
||||
|
||||
$rs = $this->mallDomainPay->checkPay($orderInfo);
|
||||
|
||||
$this->assertFalse($rs);
|
||||
|
||||
//$payConfig = '';
|
||||
//$orderInfo = '';
|
||||
|
||||
//$rs = $this->mallDomainPay->capturePaypalOrder($payConfig, $orderInfo);
|
||||
}
|
||||
|
||||
}
|
||||
92
tests/map.php
Normal file
92
tests/map.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/**
|
||||
* PhalApi 2.x 与 PhalApi 1.x 的映射关系
|
||||
*
|
||||
* 如果需要进行兼容,可以加载此文件
|
||||
*
|
||||
* @author dogstar<chanzonghuang@gmail.com> 2017-07-16
|
||||
*/
|
||||
|
||||
class PhalApi extends PhalApi\PhalApi {};
|
||||
class PhalApi_Api extends PhalApi\Api {};
|
||||
class PhalApi_ApiFactory extends PhalApi\ApiFactory {};
|
||||
interface PhalApi_Cache extends PhalApi\Cache {};
|
||||
class PhalApi_Cache_APCU extends PhalApi\Cache\APCUCache {};
|
||||
class PhalApi_Cache_File extends PhalApi\Cache\FileCache {};
|
||||
class PhalApi_Cache_Memcache extends PhalApi\Cache\MemcacheCache {};
|
||||
class PhalApi_Cache_Memcached extends PhalApi\Cache\MemcachedCache {};
|
||||
class PhalApi_Cache_Multi extends PhalApi\Cache\MultiCache {};
|
||||
class PhalApi_Cache_None extends PhalApi\Cache\NoneCache {};
|
||||
class PhalApi_Cache_Redis extends PhalApi\Cache\RedisCache {};
|
||||
interface PhalApi_Config extends PhalApi\Config {};
|
||||
class PhalApi_Config_File extends PhalApi\Config\FileConfig {};
|
||||
class PhalApi_Config_Yaconf extends PhalApi\Config\YaconfConfig {};
|
||||
class PhalApi_Cookie extends PhalApi\Cookie {};
|
||||
class PhalApi_Cookie_Multi extends PhalApi\Cookie\MultiCookie {};
|
||||
interface PhalApi_Crypt extends PhalApi\Crypt {};
|
||||
class PhalApi_Crypt_Mcrypt extends PhalApi\Crypt\McryptCrypt {};
|
||||
class PhalApi_Crypt_MultiMcrypt extends PhalApi\Crypt\MultiMcryptCrypt {};
|
||||
class PhalApi_Crypt_RSA_KeyGenerator extends PhalApi\Crypt\RSA\KeyGenerator {};
|
||||
abstract class PhalApi_Crypt_RSA_MultiBase extends PhalApi\Crypt\RSA\MultiBase {};
|
||||
class PhalApi_Crypt_RSA_MultiPri2Pub extends PhalApi\Crypt\RSA\MultiPri2PubCrypt {};
|
||||
class PhalApi_Crypt_RSA_MultiPub2Pri extends PhalApi\Crypt\RSA\MultiPub2PriCrypt {};
|
||||
class PhalApi_Crypt_RSA_Pri2Pub extends PhalApi\Crypt\RSA\Pri2PubCrypt {};
|
||||
class PhalApi_Crypt_RSA_Pub2Pri extends PhalApi\Crypt\RSA\Pub2PriCrypt {};
|
||||
class PhalApi_CUrl extends PhalApi\CUrl {};
|
||||
interface PhalApi_DB extends PhalApi\Database {};
|
||||
class PhalApi_DB_NotORM extends PhalApi\Database\NotORMDatabase {};
|
||||
class PhalApi_DI extends PhalApi\DependenceInjection {};
|
||||
class PhalApi_Exception extends PhalApi\Exception {};
|
||||
class PhalApi_Exception_BadRequest extends PhalApi\Exception\BadRequestException {};
|
||||
class PhalApi_Exception_InternalServerError extends PhalApi\Exception\InternalServerErrorException {};
|
||||
class PhalApi_Exception_Redirect extends PhalApi\Exception\RedirectException {};
|
||||
interface PhalApi_Filter extends PhalApi\Filter {};
|
||||
class PhalApi_Filter_None extends PhalApi\Filter\NoneFilter {};
|
||||
class PhalApi_Filter_SimpleMD5 extends PhalApi\Filter\SimpleMD5Filter {};
|
||||
class PhalApi_Helper_ApiDesc extends PhalApi\Helper\ApiDesc {};
|
||||
class PhalApi_Helper_ApiList extends PhalApi\Helper\ApiList {};
|
||||
class PhalApi_Helper_ApiOnline extends PhalApi\Helper\ApiOnline {};
|
||||
class PhalApi_Helper_TestRunner extends PhalApi\Helper\TestRunner {};
|
||||
class PhalApi_Helper_Tracer extends PhalApi\Helper\Tracer {};
|
||||
class PhalApi_Loader extends PhalApi\Loader {};
|
||||
abstract class PhalApi_Logger extends PhalApi\Logger {};
|
||||
class PhalApi_Logger_Explorer extends PhalApi\Logger\ExplorerLogger {};
|
||||
class PhalApi_Logger_File extends PhalApi\Logger\FileLogger {};
|
||||
interface PhalApi_Model extends PhalApi\Model {};
|
||||
class PhalApi_Model_NotORM extends PhalApi\Model\NotORMModel {};
|
||||
abstract class PhalApi_ModelProxy extends PhalApi\Model\Proxy {};
|
||||
class PhalApi_ModelQuery extends PhalApi\Model\Query {};
|
||||
class PhalApi_Request extends PhalApi\Request {};
|
||||
interface PhalApi_Request_Formatter extends PhalApi\Request\Formatter {};
|
||||
class PhalApi_Request_Formatter_Array extends PhalApi\Request\Formatter\ArrayFormatter {};
|
||||
class PhalApi_Request_Formatter_Base extends PhalApi\Request\Formatter\BaseFormatter {};
|
||||
class PhalApi_Request_Formatter_Boolean extends PhalApi\Request\Formatter\BooleanFormatter {};
|
||||
class PhalApi_Request_Formatter_Callable extends PhalApi\Request\Formatter\CallableFormatter {};
|
||||
class PhalApi_Request_Formatter_Callback extends PhalApi\Request\Formatter\CallbackFormatter {};
|
||||
class PhalApi_Request_Formatter_Date extends PhalApi\Request\Formatter\DateFormatter {};
|
||||
class PhalApi_Request_Formatter_Enum extends PhalApi\Request\Formatter\EnumFormatter {};
|
||||
class PhalApi_Request_Formatter_File extends PhalApi\Request\Formatter\FileFormatter {};
|
||||
class PhalApi_Request_Formatter_Float extends PhalApi\Request\Formatter\FloatFormatter {};
|
||||
class PhalApi_Request_Formatter_Int extends PhalApi\Request\Formatter\IntFormatter {};
|
||||
class PhalApi_Request_Formatter_String extends PhalApi\Request\Formatter\StringFormatter {};
|
||||
class PhalApi_Request_Var extends PhalApi\Request\Parser {};
|
||||
abstract class PhalApi_Response extends PhalApi\Response {};
|
||||
class PhalApi_Response_Explorer extends PhalApi\Response\ExplorerResponse {};
|
||||
class PhalApi_Response_Json extends PhalApi\Response\JsonResponse {};
|
||||
class PhalApi_Response_JsonP extends PhalApi\Response\JsonpResponse {};
|
||||
class PhalApi_Response_Xml extends PhalApi\Response\XmlResponse {};
|
||||
class PhalApi_Tool extends PhalApi\Tool {};
|
||||
class PhalApi_Translator extends PhalApi\Translator {};
|
||||
|
||||
function DI() {
|
||||
return PhalApi\DI();
|
||||
}
|
||||
|
||||
function SL($language) {
|
||||
return PhalApi\SL($language);
|
||||
}
|
||||
|
||||
function T($msg, $params = array()) {
|
||||
return PhalApi\T($msg, $params);
|
||||
}
|
||||
|
||||
37
tests/phpunit.xml
Normal file
37
tests/phpunit.xml
Normal file
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
colors="true"
|
||||
bootstrap="./bootstrap.php"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false"
|
||||
>
|
||||
<php>
|
||||
<ini name="intl.default_locale" value="en"/>
|
||||
<ini name="intl.error_level" value="0"/>
|
||||
<ini name="memory_limit" value="-1"/>
|
||||
<env name="test_mode" value="phpunit"/>
|
||||
</php>
|
||||
|
||||
<testsuites>
|
||||
<testsuite name="Test Suite">
|
||||
<directory suffix="Test.php">./app</directory>
|
||||
<directory suffix="Test.php">./admin</directory>
|
||||
<directory suffix="Test.php">./base</directory>
|
||||
<directory suffix="Test.php">./platform</directory>
|
||||
<directory suffix="Test.php">./mall</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||
<directory suffix=".php">../src</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
|
||||
38
tests/phpunit_not_sql.xml
Normal file
38
tests/phpunit_not_sql.xml
Normal file
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
colors="true"
|
||||
bootstrap="./bootstrap.php"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false"
|
||||
>
|
||||
<php>
|
||||
<ini name="intl.default_locale" value="en"/>
|
||||
<ini name="intl.error_level" value="0"/>
|
||||
<ini name="memory_limit" value="-1"/>
|
||||
<env name="test_mode" value="phpunit"/>
|
||||
<env name="not_sql" value="true"/>
|
||||
</php>
|
||||
|
||||
<testsuites>
|
||||
<testsuite name="Test Suite">
|
||||
<directory suffix="Test.php">./app</directory>
|
||||
<directory suffix="Test.php">./admin</directory>
|
||||
<directory suffix="Test.php">./base</directory>
|
||||
<directory suffix="Test.php">./platform</directory>
|
||||
<directory suffix="Test.php">./mall</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||
<directory suffix=".php">../src</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
|
||||
37
tests/phpunit_release.xml
Normal file
37
tests/phpunit_release.xml
Normal file
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
colors="true"
|
||||
bootstrap="./bootstrap.php"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false"
|
||||
>
|
||||
<php>
|
||||
<ini name="intl.default_locale" value="en"/>
|
||||
<ini name="intl.error_level" value="0"/>
|
||||
<ini name="memory_limit" value="-1"/>
|
||||
<env name="test_mode" value="release"/>
|
||||
</php>
|
||||
|
||||
<testsuites>
|
||||
<testsuite name="Test Suite">
|
||||
<directory suffix="Test.php">./app</directory>
|
||||
<directory suffix="Test.php">./admin</directory>
|
||||
<directory suffix="Test.php">./base</directory>
|
||||
<directory suffix="Test.php">./platform</directory>
|
||||
<directory suffix="Test.php">./mall</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||
<directory suffix=".php">../src</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
|
||||
109
tests/platform/Api/Apps_Test.php
Normal file
109
tests/platform/Api/Apps_Test.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/**
|
||||
* PhalApi_Platform\Api\Apps_Test
|
||||
*
|
||||
* 针对 ../src/admin/Api/Apps.php Platform\Api\Apps 类的PHPUnit单元测试
|
||||
*
|
||||
* @author: dogstar 20200112
|
||||
*/
|
||||
|
||||
namespace tests\Platform\Api;
|
||||
use Platform\Api\Apps;
|
||||
use Base\Domain\Apps as AppsDomain;
|
||||
use PhalApi\Helper\TestRunner;
|
||||
|
||||
class PhpUnderControl_PlatformApiApps_Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public $adminApiApps;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
\PhalApi\DI()->context->setUid(888);
|
||||
|
||||
$this->adminApiApps = new \Platform\Api\Apps();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
// 输出本次单元测试所执行的SQL语句
|
||||
// var_dump(\PhalApi\DI()->tracer->getSqls());
|
||||
|
||||
// 输出本次单元测试所涉及的追踪埋点
|
||||
// var_dump(\PhalApi\DI()->tracer->getStack());
|
||||
|
||||
\PhalApi\DI()->context->setUid(0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @group testGetRules
|
||||
*/
|
||||
public function testGetRules()
|
||||
{
|
||||
$rs = $this->adminApiApps->getRules();
|
||||
$this->assertTrue(is_array($rs));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testGetAppList
|
||||
*/
|
||||
public function testGetAppList()
|
||||
{
|
||||
$domain = new AppsDomain();
|
||||
$domain->addApp('appName_testGetAppList', 'appKey_testGetAppListplatform', 'appSecret_123_platform', 0, 888);
|
||||
$domain->addApp('appName_testGetAppList', 'appKey_testGetAppListplatform22', 'appSecret_123_platform', 0, 888);
|
||||
|
||||
$url = 's=Platform.Apps.GetAppList';
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertNotEmpty($rs['list']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testAddApp
|
||||
*/
|
||||
public function testAddApp()
|
||||
{
|
||||
|
||||
$url = 's=Platform.Apps.AddApp&app_key=testAddApp&app_secret=xxx&appName=testAddApp&app_owner=hhhhhhhh&apply_reason=test';
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertTrue($rs['is_add']);
|
||||
|
||||
return $rs['app_key'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testAddApp
|
||||
* @depends testAddApp
|
||||
*/
|
||||
public function testGetMyApp($appkey)
|
||||
{
|
||||
|
||||
$url = 's=Platform.Apps.GetMyAppInfo&app_key='.$appkey.'&app_secret=xxx&appName=testAddApp&app_owner=hhhhhhhh';
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertNotEmpty($rs['info']);
|
||||
$this->assertEquals('testAddApp', $rs['info']['app_name']);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testEditApp()
|
||||
{
|
||||
|
||||
$url = 's=Platform.Apps.AddApp&app_key=testAddApp&app_secret=xxx&appName=testAddApp&app_owner=hhhhhhhh&apply_reason=test';
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertTrue($rs['is_add']);
|
||||
|
||||
$url = 's=Platform.Apps.EditMyApp&&app_secret=xxx&appName=testAddApp&app_owner=hhhhhhhh22&app_icon=1234567&apply_reason=99999&app_key='.$rs['app_key'];
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
$this->assertTrue($rs['is_updated']);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
69
tests/platform/Api/Rigths_Test.php
Normal file
69
tests/platform/Api/Rigths_Test.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* PhalApi_Platform\Api\Rights_Test
|
||||
*
|
||||
* 针对 ../src/platform/Api/Rights.php Platform\Api\Rights 类的PHPUnit单元测试
|
||||
*
|
||||
* @author: dogstar 20200408
|
||||
*/
|
||||
|
||||
namespace tests\Platform\Api;
|
||||
use Platform\Api\Rights;
|
||||
use PhalApi\Helper\TestRunner;
|
||||
use Base\Domain\Apps as AppsDomain;
|
||||
|
||||
class PhpUnderControl_PlatformApiRights_Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public $platformApiRights;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
\PhalApi\DI()->context->setUid(8889);
|
||||
|
||||
$this->platformApiRights = new \Platform\Api\Rights();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
// 输出本次单元测试所执行的SQL语句
|
||||
// var_dump(\PhalApi\DI()->tracer->getSqls());
|
||||
|
||||
// 输出本次单元测试所涉及的追踪埋点
|
||||
// var_dump(\PhalApi\DI()->tracer->getStack());
|
||||
|
||||
\PhalApi\DI()->context->setUid(0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @group testGetRules
|
||||
*/
|
||||
public function testGetRules()
|
||||
{
|
||||
$rs = $this->platformApiRights->getRules();
|
||||
$this->assertTrue(is_array($rs));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testGetAllAppApis
|
||||
*/
|
||||
public function testGetAllAppApis()
|
||||
{
|
||||
$domain = new AppsDomain();
|
||||
$domain->addApp('appName_testGetAppList', 'appKey_testGetAppListplatform8889', 'appSecret_123_platform', 0, 8889);
|
||||
|
||||
$url = 's=Platform.Rights.GetAllAppApis&app_key=appKey_testGetAppListplatform8889';
|
||||
$rs = TestRunner::go($url);
|
||||
// var_dump($rs);
|
||||
|
||||
$this->assertNotEmpty($rs['apis']);
|
||||
foreach ($rs['apis'] as $it) {
|
||||
$this->assertArrayHasKey('service', $it);
|
||||
$this->assertArrayHasKey('title', $it);
|
||||
$this->assertArrayHasKey('is_allow', $it);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
137
tests/platform/Api/User_Test.php
Normal file
137
tests/platform/Api/User_Test.php
Normal file
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
/**
|
||||
* PhalApi_App\Api\User_Test
|
||||
*
|
||||
* 针对 ../src/app/Api/User.php App\Api\User 类的PHPUnit单元测试
|
||||
*
|
||||
* @author: dogstar 20191219
|
||||
*/
|
||||
|
||||
namespace tests\Platform\Api;
|
||||
use Platform\Api\User;
|
||||
use PhalApi\Helper\TestRunner;
|
||||
|
||||
class PhpUnderControl_PlatformApiUser_Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public $appApiUser;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->appApiUser = new \Platform\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=Platform.User.Register&username=test_dev&password=123456&member_type=100';
|
||||
|
||||
//Step 2. 执行请求
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
//Step 3. 验证
|
||||
$this->assertNotEmpty($rs);
|
||||
$this->assertTrue($rs['is_register']);
|
||||
$this->assertGreaterThan(0, $rs['uid']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testRegister
|
||||
* @expectedException PhalApi\Exception\BadRequestException
|
||||
*/
|
||||
public function testRegisterFailType()
|
||||
{
|
||||
//Step 1. 构建请求URL
|
||||
$url = 'service=Platform.User.Register&username=test_dev&password=123456&member_type=98';
|
||||
|
||||
//Step 2. 执行请求
|
||||
$rs = TestRunner::go($url);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group testAlterPass
|
||||
*/
|
||||
public function testAlterPass()
|
||||
{
|
||||
// \PhalApi\DI()->context->setUid(1);
|
||||
|
||||
//Step 1. 构建请求URL
|
||||
$url = 'service=Platform.User.AlterPass&username=test_dev&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=Platform.User.AlterPass&username=test_dev&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=Platform.User.UserProfile&username=test_dev&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=Platform.User.UpdateProfile&access_token=123&username=test_dev&_uid=1&mobile='.time();
|
||||
|
||||
//Step 2. 执行请求
|
||||
$rs = TestRunner::go($url);
|
||||
|
||||
//Step 3. 验证
|
||||
$this->assertNotEmpty($rs);
|
||||
$this->assertTrue($rs['is_update']);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user