From ac6ccbace183477b1419371237d091891bf8909c Mon Sep 17 00:00:00 2001 From: liugang Date: Wed, 10 Sep 2025 01:46:59 +0800 Subject: [PATCH] + [misc] Add unit tests for storyModel::getLinkedCommits() 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 --- .../story/test/lib/story.unittest.class.php | 16 ++++++++ module/story/test/model/getlinkedcommits.php | 33 +++++++++++++++ .../model/yaml/relation_getlinkedcommits.yaml | 41 +++++++++++++++++++ .../yaml/repohistory_getlinkedcommits.yaml | 27 ++++++++++++ .../model/yaml/story_getlinkedcommits.yaml | 39 ++++++++++++++++++ 5 files changed, 156 insertions(+) create mode 100755 module/story/test/model/getlinkedcommits.php create mode 100644 module/story/test/model/yaml/relation_getlinkedcommits.yaml create mode 100644 module/story/test/model/yaml/repohistory_getlinkedcommits.yaml create mode 100644 module/story/test/model/yaml/story_getlinkedcommits.yaml diff --git a/module/story/test/lib/story.unittest.class.php b/module/story/test/lib/story.unittest.class.php index 0156711fb5..9a6393cf4b 100644 --- a/module/story/test/lib/story.unittest.class.php +++ b/module/story/test/lib/story.unittest.class.php @@ -1578,4 +1578,20 @@ class storyTest return $result; } + + /** + * Test getLinkedCommits method. + * + * @param int $repoID + * @param array $revisions + * @access public + * @return mixed + */ + public function getLinkedCommitsTest(int $repoID, array $revisions) + { + $result = $this->objectModel->getLinkedCommits($repoID, $revisions); + if(dao::isError()) return dao::getError(); + + return count($result); + } } diff --git a/module/story/test/model/getlinkedcommits.php b/module/story/test/model/getlinkedcommits.php new file mode 100755 index 0000000000..9aeda55624 --- /dev/null +++ b/module/story/test/model/getlinkedcommits.php @@ -0,0 +1,33 @@ +#!/usr/bin/env php +loadYaml('repohistory_getlinkedcommits', false, 2)->gen(5); +zendata('relation')->loadYaml('relation_getlinkedcommits', false, 2)->gen(5); +zendata('story')->loadYaml('story_getlinkedcommits', false, 2)->gen(5); + +su('admin'); + +$storyTest = new storyTest(); + +r($storyTest->getLinkedCommitsTest(1, array('abc123', 'def456'))) && p() && e('0'); +r($storyTest->getLinkedCommitsTest(999, array('abc123'))) && p() && e('0'); +r($storyTest->getLinkedCommitsTest(1, array())) && p() && e('0'); +r($storyTest->getLinkedCommitsTest(0, array('abc123'))) && p() && e('0'); +r($storyTest->getLinkedCommitsTest(1, array('abc123', 'def456', 'ghi789'))) && p() && e('0'); \ No newline at end of file diff --git a/module/story/test/model/yaml/relation_getlinkedcommits.yaml b/module/story/test/model/yaml/relation_getlinkedcommits.yaml new file mode 100644 index 0000000000..507ee9ca80 --- /dev/null +++ b/module/story/test/model/yaml/relation_getlinkedcommits.yaml @@ -0,0 +1,41 @@ +--- +title: 关系表数据定义 +desc: 用于getLinkedCommits方法测试的关系表数据 + +fields: +- field: id + note: 关系ID + range: 1-8 +- field: project + note: 项目ID + range: 1{3}, 2{3}, 3{2} +- field: product + note: 产品ID + range: 1{4}, 2{4} +- field: execution + note: 执行ID + range: 1{4}, 2{4} +- field: AType + note: A类型 + range: story{8} +- field: AID + note: A对象ID(需求ID) + range: 1{2}, 2{2}, 3{2}, 4{1}, 5{1} +- field: AVersion + note: A版本 + range: 1{8} +- field: relation + note: 关系类型 + range: completedin{8} +- field: BType + note: B类型 + range: commit{8} +- field: BID + note: B对象ID(提交ID) + range: 1-8 +- field: BVersion + note: B版本 + range: 1{8} +- field: extra + note: 额外信息 + range: []{8} \ No newline at end of file diff --git a/module/story/test/model/yaml/repohistory_getlinkedcommits.yaml b/module/story/test/model/yaml/repohistory_getlinkedcommits.yaml new file mode 100644 index 0000000000..31e0750653 --- /dev/null +++ b/module/story/test/model/yaml/repohistory_getlinkedcommits.yaml @@ -0,0 +1,27 @@ +--- +title: 仓库历史记录数据定义 +desc: 用于getLinkedCommits方法测试的仓库历史记录数据 + +fields: +- field: id + note: 历史记录ID + range: 1-10 +- field: repo + note: 仓库ID + range: 1{5}, 2{3}, 3{2} +- field: revision + note: 版本号 + range: abc123,def456,ghi789,jkl012,mno345 +- field: commit + note: 提交ID + range: 1-10 +- field: comment + note: 提交注释 + range: Fix bug in user module,Add new feature to story,Update documentation,Refactor code structure,Optimize database queries,Add unit tests,Fix typo in comments,Remove unused code,Update configuration,Clean up old files +- field: committer + note: 提交者 + range: admin{3},user1{2},user2{2},tester{2},developer{1} +- field: time + note: 提交时间 + range: (-30D)-(-1D):1D + format: YYYY-MM-DD hh:mm:ss \ No newline at end of file diff --git a/module/story/test/model/yaml/story_getlinkedcommits.yaml b/module/story/test/model/yaml/story_getlinkedcommits.yaml new file mode 100644 index 0000000000..b7e91c6fec --- /dev/null +++ b/module/story/test/model/yaml/story_getlinkedcommits.yaml @@ -0,0 +1,39 @@ +--- +title: 需求表数据定义 +desc: 用于getLinkedCommits方法测试的需求表数据 + +fields: +- field: id + note: 需求ID + range: 1-5 +- field: product + note: 产品ID + range: 1{3}, 2{2} +- field: branch + note: 分支ID + range: 0{5} +- field: title + note: 需求标题 + range: 用户登录功能,产品管理模块,数据统计功能,权限管理系统,接口优化需求 +- field: status + note: 需求状态 + range: active{3}, draft{1}, closed{1} +- field: stage + note: 需求阶段 + range: projected{2}, developing{2}, testing{1} +- field: type + note: 需求类型 + range: story{5} +- field: estimate + note: 预计工时 + range: 8{2}, 16{2}, 24{1} +- field: version + note: 版本号 + range: 1{5} +- field: openedBy + note: 创建者 + range: admin{2}, user1{2}, user2{1} +- field: openedDate + note: 创建时间 + range: (-15D)-(-5D):2D + format: YYYY-MM-DD hh:mm:ss \ No newline at end of file