From a5144ba7bdf2ae83dc259762249b5b3c8c485354 Mon Sep 17 00:00:00 2001 From: liugang Date: Fri, 12 Sep 2025 11:25:11 +0800 Subject: [PATCH] + [misc] Add unit tests for reportTao::getAnnualExecutionStat() 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 --- .../report/test/lib/report.unittest.class.php | 22 ++++++++++ .../test/tao/getannualexecutionstat.php | 43 +++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100755 module/report/test/tao/getannualexecutionstat.php diff --git a/module/report/test/lib/report.unittest.class.php b/module/report/test/lib/report.unittest.class.php index e88472e6ea..0035a22aab 100644 --- a/module/report/test/lib/report.unittest.class.php +++ b/module/report/test/lib/report.unittest.class.php @@ -532,4 +532,26 @@ class reportTest return $result; } + + /** + * Test getAnnualExecutionStat method. + * + * @param array $accounts + * @param string $year + * @access public + * @return mixed + */ + public function getAnnualExecutionStatTest(array $accounts, string $year): mixed + { + ob_start(); + $reflection = new ReflectionClass($this->objectTao); + $method = $reflection->getMethod('getAnnualExecutionStat'); + $method->setAccessible(true); + $result = $method->invoke($this->objectTao, $accounts, $year); + ob_end_clean(); + + if(dao::isError()) return dao::getError(); + + return count($result); + } } diff --git a/module/report/test/tao/getannualexecutionstat.php b/module/report/test/tao/getannualexecutionstat.php new file mode 100755 index 0000000000..5a3db7d931 --- /dev/null +++ b/module/report/test/tao/getannualexecutionstat.php @@ -0,0 +1,43 @@ +#!/usr/bin/env php +id->range('1-5'); +$action->objectType->range('execution{5}'); +$action->objectID->range('1-5'); +$action->actor->range('admin{5}'); +$action->action->range('opened{5}'); +$action->gen(5); + +// 3. 用户登录(选择合适角色) +su('admin'); + +// 4. 创建测试实例(变量名与模块名一致) +$reportTest = new reportTest(); + +// 5. 🔴 强制要求:必须包含至少5个测试步骤 +r($reportTest->getAnnualExecutionStatTest(array(), '2024')) && p() && e('4'); // 步骤1:空账户列表查询当前年份统计 +r($reportTest->getAnnualExecutionStatTest(array('admin', 'user1'), '2024')) && p() && e('4'); // 步骤2:有效账户列表查询 +r($reportTest->getAnnualExecutionStatTest(array(), '1999')) && p() && e('4'); // 步骤3:无效年份查询 +r($reportTest->getAnnualExecutionStatTest(array('nonexistuser'), '2024')) && p() && e('4'); // 步骤4:不存在账户查询 +r($reportTest->getAnnualExecutionStatTest(array('admin', 'user1', 'user2'), '2023')) && p() && e('4'); // 步骤5:多账户历史年份查询 \ No newline at end of file