78 lines
2.0 KiB
PHP
78 lines
2.0 KiB
PHP
<?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'));
|
|
}
|
|
}
|