3.8.1
This commit is contained in:
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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user