From ccc7658b21bb969f823ef8a30e21b9102d9f2b80 Mon Sep 17 00:00:00 2001 From: liugang Date: Wed, 24 Sep 2025 03:31:11 +0800 Subject: [PATCH] * [misc] Enhance unit tests for programplanTao::getParentStages() 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 --- .../test/lib/programplan.unittest.class.php | 30 ++++++ .../programplan/test/tao/getparentstages.php | 37 +++++--- .../tao/yaml/project_getparentstages.yaml | 95 +++++++++++++++++++ .../yaml/projectproduct_getparentstages.yaml | 14 +++ 4 files changed, 164 insertions(+), 12 deletions(-) mode change 100644 => 100755 module/programplan/test/tao/getparentstages.php create mode 100644 module/programplan/test/tao/yaml/project_getparentstages.yaml create mode 100644 module/programplan/test/tao/yaml/projectproduct_getparentstages.yaml diff --git a/module/programplan/test/lib/programplan.unittest.class.php b/module/programplan/test/lib/programplan.unittest.class.php index 0786794865..929fb5365f 100644 --- a/module/programplan/test/lib/programplan.unittest.class.php +++ b/module/programplan/test/lib/programplan.unittest.class.php @@ -940,4 +940,34 @@ class programplanTest return array('error' => $e->getMessage()); } } + + /** + * Test getParentStages method. + * + * @param int $executionID + * @param int $planID + * @param int $productID + * @param string $param + * @access public + * @return array|false + */ + public function getParentStagesTest(int $executionID, int $planID, int $productID, string $param = ''): array|false + { + try + { + $reflection = new ReflectionClass($this->objectTao); + $method = $reflection->getMethod('getParentStages'); + $method->setAccessible(true); + + $result = $method->invoke($this->objectTao, $executionID, $planID, $productID, $param); + + if(dao::isError()) return dao::getError(); + + return $result; + } + catch(Throwable $e) + { + return false; + } + } } diff --git a/module/programplan/test/tao/getparentstages.php b/module/programplan/test/tao/getparentstages.php old mode 100644 new mode 100755 index 10a12ed145..c1ee36f775 --- a/module/programplan/test/tao/getparentstages.php +++ b/module/programplan/test/tao/getparentstages.php @@ -3,24 +3,37 @@ /** -title=测试 programplanTao->getParentStages(); +title=测试 programplanTao::getParentStages(); +timeout=0 cid=0 -- 测试查询项目1产品2阶段10父阶段信息 @执行1-1 -- 测试查询项目1产品3阶段10父阶段信息 @执行1-1-1 -- 测试查询项目4产品6阶段10父阶段信息 @执行2-1-1 +- 测试步骤1:正常情况查询属性2 @执行1-1 +- 测试步骤2:不存在的项目ID @0 +- 测试步骤3:产品ID为0属性2 @执行1-1 +- 测试步骤4:使用noclosed参数属性3 @执行1-1-1 +- 测试步骤5:其他项目查询 @0 +- 测试步骤6:边界值executionID为0 @0 +- 测试步骤7:异常值executionID为负数 @0 */ -include dirname(__FILE__, 5) . '/test/lib/init.php'; -su('admin'); +include dirname(__FILE__, 5) . '/test/lib/init.php'; +include dirname(__FILE__, 2) . '/lib/programplan.unittest.class.php'; + +// 准备测试数据 zenData('project')->loadYaml('project')->gen(10); zenData('projectproduct')->loadYaml('projectproduct')->gen(10); -global $tester; -$tester->loadModel('programplan'); -$tester->programplan->app->user->admin = true; +// 登录admin用户 +su('admin'); -r($tester->programplan->getParentStages(1, 10, 2)[2]) && p() && e('执行1-1'); // 测试查询项目1产品2阶段10父阶段信息 -r($tester->programplan->getParentStages(1, 10, 3)[3]) && p() && e('执行1-1-1'); // 测试查询项目1产品3阶段10父阶段信息 -r($tester->programplan->getParentStages(4, 10, 6)[6]) && p() && e('执行2-1-1'); // 测试查询项目4产品6阶段10父阶段信息 +// 创建测试实例 +$programplanTest = new programplanTest(); + +r($programplanTest->getParentStagesTest(1, 10, 2)) && p('2') && e('执行1-1'); // 测试步骤1:正常情况查询 +r($programplanTest->getParentStagesTest(999, 10, 2)) && p() && e('0'); // 测试步骤2:不存在的项目ID +r($programplanTest->getParentStagesTest(1, 5, 0)) && p('2') && e('执行1-1'); // 测试步骤3:产品ID为0 +r($programplanTest->getParentStagesTest(1, 8, 3, 'noclosed')) && p('3') && e('执行1-1-1'); // 测试步骤4:使用noclosed参数 +r($programplanTest->getParentStagesTest(2, 12, 4)) && p() && e('0'); // 测试步骤5:其他项目查询 +r($programplanTest->getParentStagesTest(0, 1, 1)) && p() && e('0'); // 测试步骤6:边界值executionID为0 +r($programplanTest->getParentStagesTest(-1, 1, 1)) && p() && e('0'); // 测试步骤7:异常值executionID为负数 \ No newline at end of file diff --git a/module/programplan/test/tao/yaml/project_getparentstages.yaml b/module/programplan/test/tao/yaml/project_getparentstages.yaml new file mode 100644 index 0000000000..0b066bb9b1 --- /dev/null +++ b/module/programplan/test/tao/yaml/project_getparentstages.yaml @@ -0,0 +1,95 @@ +title: project data for getParentStages test +author: Claude Code +version: 1.0 +desc: 为getParentStages方法测试准备的项目数据 + +fields: + - field: id + range: 1-20 + - field: project + range: 1{8},2{6},3{6} + - field: model + range: scrum{15},waterfall{5} + - field: name + fields: + - field: name1 + range: 执行{15},阶段{5} + - field: name2 + range: 1-20 + - field: type + range: stage{15},project{3},sprint{2} + - field: status + range: wait{3},doing{8},suspended{2},closed{4},finished{3} + - field: lifetime + range: "" + - field: budget + range: 100000-500000:10000 + - field: budgetUnit + range: CNY{18},USD{2} + - field: attribute + range: request{8},design{4},develop{3},test{3},release{2} + - field: percent + range: 0-100:10 + - field: milestone + range: 0{18},1{2} + - field: output + range: "" + - field: auth + range: extend + - field: parent + range: 0{3},1{5},2{4},3{3},4{2},5{2},6{1} + - field: path + fields: + - field: path1 + prefix: "," + range: 1-10 + - field: path2 + prefix: "," + range: 11-20 + postfix: "," + - field: grade + range: 1{3},2{8},3{6},4{3} + - field: code + fields: + - field: code1 + range: stage{15},project{5} + - field: code2 + range: 1-20 + - field: begin + range: "(-1M)-(+1M):1D" + type: timestamp + format: "YY-MM-DD hh:mm:ss" + - field: end + range: "(+1M)-(+3M):1D" + type: timestamp + format: "YY-MM-DD hh:mm:ss" + - field: PO + range: "" + - field: PM + range: admin{10},user1{5},user2{3},user3{2} + - field: QD + range: "" + - field: RD + range: "" + - field: team + range: "" + - field: acl + range: open{10},private{6},program{4} + - field: order + range: 5-200:5 + - field: openedVersion + range: "16.5" + - field: openedDate + range: "(-1M)-(+1M):1D" + type: timestamp + format: "YY-MM-DD hh:mm:ss" + - field: multiple + range: 1 + - field: category + range: "" + - field: hasProduct + range: 1{18},0{2} + - field: progress + range: "0.00" + - field: deleted + range: 0{18},1{2} \ No newline at end of file diff --git a/module/programplan/test/tao/yaml/projectproduct_getparentstages.yaml b/module/programplan/test/tao/yaml/projectproduct_getparentstages.yaml new file mode 100644 index 0000000000..b3f3c9b61b --- /dev/null +++ b/module/programplan/test/tao/yaml/projectproduct_getparentstages.yaml @@ -0,0 +1,14 @@ +title: projectproduct data for getParentStages test +author: Claude Code +version: 1.0 +desc: 为getParentStages方法测试准备的项目产品关联数据 + +fields: + - field: project + range: 1-20 + - field: product + range: 1{5},2{5},3{4},4{3},5{2},6{1} + - field: branch + range: 0{18},1{2} + - field: plan + range: 0{5},1-15{15} \ No newline at end of file