* [misc] Enhance unit tests for storyModel::getStoriesCountByProductID() 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:39 +08:00
co-authored by Claude
parent e287d3e2f7
commit da664e66e1
3 changed files with 117 additions and 16 deletions
@@ -22,6 +22,22 @@ class storyTest
su('admin');
}
/**
* Test getReviewerPairs method.
*
* @param int $storyID
* @param int $version
* @access public
* @return array
*/
public function getReviewerPairsTest(int $storyID, int $version)
{
$result = $this->objectModel->getReviewerPairs($storyID, $version);
if(dao::isError()) return dao::getError();
return $result;
}
/**
* Test getLastReviewer method.
*
@@ -4087,4 +4103,20 @@ class storyTest
return $result;
}
/**
* Test getStoriesCountByProductID method.
*
* @param int $productID
* @param string $storyType
* @access public
* @return array
*/
public function getStoriesCountByProductIDTest(int $productID, string $storyType = 'requirement'): array
{
$result = $this->objectModel->getStoriesCountByProductID($productID, $storyType);
if(dao::isError()) return dao::getError();
return $result;
}
}
+33 -16
View File
@@ -3,27 +3,44 @@
/**
title=测试 storyModel->getStoriesCountByProductID();
title=测试 storyModel::getStoriesCountByProductID();
timeout=0
cid=0
- 检查用户需求草稿状态统计数属性count @1
- 检查用户需求关闭状态统计数属性count @1
- 检查软件需求激活状态统计数属性count @1
- 检查软件需求变更状态统计数属性count @1
- 步骤1:正常产品1需求draft状态统计第draft条的count属性 @3
- 步骤2:正常产品1故事changing状态统计第changing条的count属性 @1
- 步骤3:不存在产品统计 @0
- 步骤4:边界值产品ID为0 @0
- 步骤5:产品2需求active状态统计第active条的count属性 @2
*/
// 1. 导入依赖
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/story.unittest.class.php';
// 2. zendata数据准备
$story = zenData('story');
$story->id->range('1-15');
$story->product->range('1{5},2{3},3{2},999{1}');
$story->type->range('requirement{8},story{7}');
$story->status->range('draft{3},active{4},closed{3},changing{2},reviewing{2},launched{1}');
$story->deleted->range('0{14},1{1}');
$story->title->range('需求标题{15}');
$story->openedBy->range('admin{8},user1{4},user2{3}');
$story->assignedTo->range('admin{5},user1{5},user2{5}');
$story->version->range('1{12},2{2},3{1}');
$story->gen(15);
// 3. 用户登录
su('admin');
zenData('story')->gen(10);
// 4. 创建测试实例
$storyTest = new storyTest();
global $tester;
$tester->loadModel('story');
$requirementCount = $tester->story->getStoriesCountByProductID(1, 'requirement');
$storyCount = $tester->story->getStoriesCountByProductID(1, 'story');
r($requirementCount['draft']) && p('count') && e('1'); //检查用户需求草稿状态统计数
r($requirementCount['closed']) && p('count') && e('1'); //检查用户需求关闭状态统计数
r($storyCount['active']) && p('count') && e('1'); //检查软件需求激活状态统计数
r($storyCount['changing']) && p('count') && e('1'); //检查软件需求变更状态统计数
// 5. 执行5个测试步骤
r($storyTest->getStoriesCountByProductIDTest(1, 'requirement')) && p('draft:count') && e('3'); // 步骤1:正常产品1需求draft状态统计
r($storyTest->getStoriesCountByProductIDTest(1, 'story')) && p('changing:count') && e('1'); // 步骤2:正常产品1故事changing状态统计
r($storyTest->getStoriesCountByProductIDTest(999, 'requirement')) && p() && e('0'); // 步骤3:不存在产品统计
r($storyTest->getStoriesCountByProductIDTest(0, 'story')) && p() && e('0'); // 步骤4:边界值产品ID为0
r($storyTest->getStoriesCountByProductIDTest(2, 'requirement')) && p('active:count') && e('2'); // 步骤5:产品2需求active状态统计
@@ -0,0 +1,52 @@
---
title: story数据
desc: 产品需求统计测试数据
author: zentao
version: 1
fields:
- field: id
range: 1-20
note: 需求ID
- field: product
range: 1{8},2{6},3{4},999{2}
note: 产品ID - 产品1有8条,产品2有6条,产品3有4条,不存在产品999有2条
- field: type
range: requirement{10},story{10}
note: 需求类型 - requirement和story各10条
- field: status
range: draft{4},active{6},closed{4},changing{3},reviewing{2},launched{1}
note: 需求状态 - 覆盖各种状态
- field: deleted
range: 0{18},1{2}
note: 删除状态 - 18条正常,2条已删除
- field: title
range: 需求标题{12}
note: 需求标题
- field: openedBy
range: admin{8},user1{4},user2{4}
note: 创建人
- field: openedDate
range: 2023-01-01 00:00:00{6},2023-06-01 00:00:00{6},2023-12-01 00:00:00{6}
note: 创建时间
- field: assignedTo
range: admin{5},user1{5},user2{5},'{5}
note: 指派给
- field: version
range: 1{15},2{3},3{2}
note: 版本号
- field: estimate
range: 1{5},2{5},3{5},5{5}
note: 预估工时
- field: pri
range: 1{3},2{5},3{7},4{5}
note: 优先级
- field: stage
range: wait{4},planned{4},designing{4},developing{4},testing{4}
note: 阶段
- field: keywords
range: 关键词{10},''{10}
note: 关键词
- field: mailto
range: admin@test.com{5},''{15}
note: 抄送邮箱