* [misc] Enhance unit tests for mrTao::getLinkedObjectPairs() 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:45 +08:00
co-authored by Claude
parent b8457fd0ed
commit 0e1a16ac8b
3 changed files with 149 additions and 13 deletions
+26
View File
@@ -1361,4 +1361,30 @@ class mrTest
return $result;
}
/**
* Test getLinkedObjectPairs method.
*
* @param int $MRID
* @param string $objectType
* @access public
* @return mixed
*/
public function getLinkedObjectPairsTest(int $MRID, string $objectType = 'story')
{
global $app;
$originalRawModule = $app->rawModule ?? '';
$app->rawModule = 'mr';
$method = new ReflectionMethod($this->objectTao, 'getLinkedObjectPairs');
$method->setAccessible(true);
$result = $method->invoke($this->objectTao, $MRID, $objectType);
if(dao::isError()) {
$app->rawModule = $originalRawModule;
return dao::getError();
}
$app->rawModule = $originalRawModule;
return $result;
}
}
+41 -13
View File
@@ -3,27 +3,55 @@
/**
title=测试 mrModel->getLinkedObjectPairs();
title=测试 mrTao::getLinkedObjectPairs();
timeout=0
cid=1
cid=0
- 不存在的合并请求 @0
- ID为1的合并请求关联的需求 @1|4|7|10
- ID为1的合并请求关联的任务 @2|5|8
- ID为1的合并请求关联的bug @3|6|9
- 测试步骤1:查询MR ID为1关联的story对象 @1|4|7
- 测试步骤2:查询MR ID为1关联的task对象 @2|5|8
- 测试步骤3:查询MR ID为1关联的bug对象 @3|6|9
- 测试步骤4:查询不存在的MR ID @0
- 测试步骤5:查询无效MR ID为0 @0
- 测试步骤6:查询MR ID为2但无story关联的情况 @0
- 测试步骤7:使用无效对象类型参数 @0
*/
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/mr.unittest.class.php';
zenData('relation')->loadYaml('relation')->gen(10);
su('admin');
global $tester;
$mrModel = $tester->loadModel('mr');
global $tester, $app;
$app->rawModule = 'mr';
r($mrModel->getLinkedObjectPairs(2, 'story')) && p() && e('0'); // 不存在的合并请求
// 手动准备测试数据
$db = $tester->loadModel('mr')->dao;
$db->delete()->from(TABLE_RELATION)->where('AType')->eq('mr')->exec();
r(implode('|', $mrModel->getLinkedObjectPairs(1, 'story'))) && p() && e('1|4|7|10'); // ID为1的合并请求关联的需求
r(implode('|', $mrModel->getLinkedObjectPairs(1, 'task'))) && p() && e('2|5|8'); // ID为1的合并请求关联的任务
r(implode('|', $mrModel->getLinkedObjectPairs(1, 'bug'))) && p() && e('3|6|9'); // ID为1的合并请求关联的bug
$testData = array(
array('product' => 1, 'project' => 0, 'AType' => 'mr', 'AID' => 1, 'AVersion' => 1, 'relation' => 'linkedto', 'BType' => 'story', 'BID' => 1, 'BVersion' => 1, 'extra' => ''),
array('product' => 1, 'project' => 0, 'AType' => 'mr', 'AID' => 1, 'AVersion' => 1, 'relation' => 'linkedto', 'BType' => 'story', 'BID' => 4, 'BVersion' => 1, 'extra' => ''),
array('product' => 1, 'project' => 0, 'AType' => 'mr', 'AID' => 1, 'AVersion' => 1, 'relation' => 'linkedto', 'BType' => 'story', 'BID' => 7, 'BVersion' => 1, 'extra' => ''),
array('product' => 1, 'project' => 0, 'AType' => 'mr', 'AID' => 1, 'AVersion' => 1, 'relation' => 'linkedto', 'BType' => 'task', 'BID' => 2, 'BVersion' => 1, 'extra' => ''),
array('product' => 1, 'project' => 0, 'AType' => 'mr', 'AID' => 1, 'AVersion' => 1, 'relation' => 'linkedto', 'BType' => 'task', 'BID' => 5, 'BVersion' => 1, 'extra' => ''),
array('product' => 1, 'project' => 0, 'AType' => 'mr', 'AID' => 1, 'AVersion' => 1, 'relation' => 'linkedto', 'BType' => 'task', 'BID' => 8, 'BVersion' => 1, 'extra' => ''),
array('product' => 1, 'project' => 0, 'AType' => 'mr', 'AID' => 1, 'AVersion' => 1, 'relation' => 'linkedto', 'BType' => 'bug', 'BID' => 3, 'BVersion' => 1, 'extra' => ''),
array('product' => 1, 'project' => 0, 'AType' => 'mr', 'AID' => 1, 'AVersion' => 1, 'relation' => 'linkedto', 'BType' => 'bug', 'BID' => 6, 'BVersion' => 1, 'extra' => ''),
array('product' => 1, 'project' => 0, 'AType' => 'mr', 'AID' => 1, 'AVersion' => 1, 'relation' => 'linkedto', 'BType' => 'bug', 'BID' => 9, 'BVersion' => 1, 'extra' => ''),
array('product' => 1, 'project' => 0, 'AType' => 'mr', 'AID' => 2, 'AVersion' => 1, 'relation' => 'linkedto', 'BType' => 'task', 'BID' => 10, 'BVersion' => 1, 'extra' => '')
);
foreach($testData as $data) {
$db->insert(TABLE_RELATION)->data($data)->exec();
}
$mrTest = new mrTest();
r(implode('|', $mrTest->getLinkedObjectPairsTest(1, 'story'))) && p() && e('1|4|7'); // 测试步骤1:查询MR ID为1关联的story对象
r(implode('|', $mrTest->getLinkedObjectPairsTest(1, 'task'))) && p() && e('2|5|8'); // 测试步骤2:查询MR ID为1关联的task对象
r(implode('|', $mrTest->getLinkedObjectPairsTest(1, 'bug'))) && p() && e('3|6|9'); // 测试步骤3:查询MR ID为1关联的bug对象
r($mrTest->getLinkedObjectPairsTest(999, 'story')) && p() && e('0'); // 测试步骤4:查询不存在的MR ID
r($mrTest->getLinkedObjectPairsTest(0, 'story')) && p() && e('0'); // 测试步骤5:查询无效MR ID为0
r($mrTest->getLinkedObjectPairsTest(2, 'story')) && p() && e('0'); // 测试步骤6:查询MR ID为2但无story关联的情况
r($mrTest->getLinkedObjectPairsTest(1, 'invalid_type')) && p() && e('0'); // 测试步骤7:使用无效对象类型参数
@@ -0,0 +1,82 @@
title: table zt_relation
desc: "MR关联对象关系测试数据"
author: automated test
version: "1.0"
fields:
- field: id
note: "ID"
range: 1-10
prefix: ""
postfix: ""
loop: 0
format: ""
- field: product
note: "所属产品"
range: 1
prefix: ""
postfix: ""
loop: 0
format: ""
- field: project
note: "所属项目"
range: 0
prefix: ""
postfix: ""
loop: 0
format: ""
- field: AType
note: "源对象类型"
range: mr
prefix: ""
postfix: ""
loop: 0
format: ""
- field: AID
note: "源对象ID"
range: 1{9},2{1}
prefix: ""
postfix: ""
loop: 0
format: ""
- field: AVersion
note: "源对象版本"
range: 1
prefix: ""
postfix: ""
loop: 0
format: ""
- field: relation
note: "关联关系"
range: linkedto
prefix: ""
postfix: ""
loop: 0
format: ""
- field: BType
note: "目标对象类型"
range: story{3},task{3},bug{3},task{1}
prefix: ""
postfix: ""
loop: 0
format: ""
- field: BID
note: "目标对象ID"
range: 1,4,7,2,5,8,3,6,9,10
prefix: ""
postfix: ""
loop: 0
format: ""
- field: BVersion
note: "目标对象版本"
range: 1
prefix: ""
postfix: ""
loop: 0
format: ""
- field: extra
note: "额外信息"
range: ""
prefix: ""
postfix: ""
loop: 0
format: ""