From 04237bb91aa22caaf62138fb8a2582c062c02f60 Mon Sep 17 00:00:00 2001 From: liugang Date: Sun, 7 Sep 2025 16:56:45 +0800 Subject: [PATCH] + [misc] Add unit tests for commonModel::getSysURL() method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../common/test/lib/common.unittest.class.php | 34 +++++++++++++++++ module/common/test/model/getsysurl.php | 38 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100755 module/common/test/model/getsysurl.php diff --git a/module/common/test/lib/common.unittest.class.php b/module/common/test/lib/common.unittest.class.php index 104816966d..26b20f53f8 100644 --- a/module/common/test/lib/common.unittest.class.php +++ b/module/common/test/lib/common.unittest.class.php @@ -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'; + } } diff --git a/module/common/test/model/getsysurl.php b/module/common/test/model/getsysurl.php new file mode 100755 index 0000000000..93024f8ed6 --- /dev/null +++ b/module/common/test/model/getsysurl.php @@ -0,0 +1,38 @@ +#!/usr/bin/env php +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'); \ No newline at end of file