+ [misc] Add unit tests for commonModel::getSysURL() method

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
liugang
2025-09-15 15:06:12 +08:00
co-authored by Claude
parent b984d09db7
commit 04237bb91a
2 changed files with 72 additions and 0 deletions
@@ -360,4 +360,38 @@ class commonTest
return $result ? '1' : '0';
}
/**
* Test getSysURL method.
*
* @param int $testType
* @access public
* @return mixed
*/
public function getSysURLTest($testType = 1)
{
// 由于测试框架已经定义了RUN_MODE='test',getSysURL总是返回空字符串
// 这里我们验证方法的存在性和基本功能
switch($testType)
{
case 1: // 基本功能测试 - 测试模式下返回空字符串
$result = commonModel::getSysURL();
return $result;
case 2: // 方法存在性验证
return method_exists('commonModel', 'getSysURL') ? '1' : '0';
case 3: // 静态方法验证
$reflection = new ReflectionMethod('commonModel', 'getSysURL');
return $reflection->isStatic() ? '1' : '0';
case 4: // 返回类型验证
$reflection = new ReflectionMethod('commonModel', 'getSysURL');
$returnType = $reflection->getReturnType();
return ($returnType && $returnType->getName() === 'string') ? '1' : '0';
case 5: // 参数数量验证
$reflection = new ReflectionMethod('commonModel', 'getSysURL');
return $reflection->getNumberOfParameters() === 0 ? '1' : '0';
}
return '0';
}
}
+38
View File
@@ -0,0 +1,38 @@
#!/usr/bin/env php
<?php
/**
title=测试 commonModel::getSysURL();
timeout=0
cid=0
- 执行commonTest模块的getSysURLTest方法,参数是1 @
- 执行commonTest模块的getSysURLTest方法,参数是2 @1
- 执行commonTest模块的getSysURLTest方法,参数是3 @1
- 执行commonTest模块的getSysURLTest方法,参数是4 @1
- 执行commonTest模块的getSysURLTest方法,参数是5 @1
*/
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/common.unittest.class.php';
su('admin');
$commonTest = new commonTest();
// 测试步骤1:基本功能测试 - 测试模式下返回空字符串
r($commonTest->getSysURLTest(1)) && p() && e('');
// 测试步骤2:方法存在性验证
r($commonTest->getSysURLTest(2)) && p() && e('1');
// 测试步骤3:静态方法验证
r($commonTest->getSysURLTest(3)) && p() && e('1');
// 测试步骤4:返回类型验证
r($commonTest->getSysURLTest(4)) && p() && e('1');
// 测试步骤5:参数数量验证
r($commonTest->getSysURLTest(5)) && p() && e('1');