* [misc] Enhance unit tests for programplanTao::getStageCount() method

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
liugang
2025-09-25 09:16:46 +08:00
co-authored by Claude
parent 793c4b75fb
commit acae67fa38
2 changed files with 51 additions and 17 deletions
@@ -987,4 +987,24 @@ class programplanTest
return $result;
}
/**
* Test getStageCount method.
*
* @param int $planID
* @param string $mode
* @access public
* @return int
*/
public function getStageCountTest(int $planID, string $mode = ''): int
{
$reflection = new ReflectionClass($this->objectTao);
$method = $reflection->getMethod('getStageCount');
$method->setAccessible(true);
$result = $method->invoke($this->objectTao, $planID, $mode);
if(dao::isError()) return dao::getError();
return $result;
}
}
+31 -17
View File
@@ -3,28 +3,42 @@
/**
title=测试 programplanTao->getStageCount();
title=测试 programplanTao::getStageCount();
timeout=0
cid=0
- 传入空的planID。 @0
- 传入不存在的planID。 @0
- 传入planID=1。 @4
- 传入planID=1, 并且是里程碑。 @2
- 步骤1:正常情况-planID=1有4个子阶段 @4
- 步骤2:边界值-planID为0 @5
- 步骤3:测试planID=999的子阶段数量 @5
- 步骤4:模式过滤-只统计里程碑阶段 @2
- 步骤5:测试planID=2的子阶段数量(不包含已删除) @3
- 步骤6:负数planID测试 @0
*/
// 1. 导入依赖
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/programplan.unittest.class.php';
// 2. zendata数据准备
$project = zenData('project');
$project->id->range('1-20');
$project->parent->range('0,1{4},2{3},999{5},0{7}');
$project->type->range('project,stage{19}');
$project->milestone->range('0,0{2},1{2},0{3},1{1},0{11}');
$project->deleted->range('0{18},1{2}');
$project->gen(20);
// 3. 用户登录
su('admin');
$project = zenData('project');
$project->parent->range('0,1{100}');
$project->type->range('project,stage{100}');
$project->milestone->range('0{3},1{100}');
$project->gen(5);
// 4. 创建测试实例
$programplanTest = new programplanTest();
global $tester;
$tester->loadModel('programplan');
r($tester->programplan->getStageCount(0)) && p() && e('0'); //传入空的planID。
r($tester->programplan->getStageCount(10)) && p() && e('0'); //传入不存在的planID。
r($tester->programplan->getStageCount(1)) && p() && e('4'); //传入planID=1。
r($tester->programplan->getStageCount(1, 'milestone')) && p() && e('2'); //传入planID=1, 并且是里程碑。
// 5. 测试步骤(至少5个)
r($programplanTest->getStageCountTest(1)) && p() && e('4'); // 步骤1:正常情况-planID=1有4个子阶段
r($programplanTest->getStageCountTest(0)) && p() && e('5'); // 步骤2:边界值-planID为0
r($programplanTest->getStageCountTest(999)) && p() && e('5'); // 步骤3:测试planID=999的子阶段数量
r($programplanTest->getStageCountTest(1, 'milestone')) && p() && e('2'); // 步骤4:模式过滤-只统计里程碑阶段
r($programplanTest->getStageCountTest(2)) && p() && e('3'); // 步骤5:测试planID=2的子阶段数量(不包含已删除)
r($programplanTest->getStageCountTest(-1)) && p() && e('0'); // 步骤6:负数planID测试