+ [misc] Add unit tests for projectreleaseTao::getBranchName() method

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
liugang
2025-09-15 15:09:44 +08:00
co-authored by Claude
parent d581c9147e
commit 497fc2792b
3 changed files with 102 additions and 0 deletions
@@ -6,6 +6,7 @@ class projectreleaseTest
{
global $tester;
$this->objectModel = $tester->loadModel('projectrelease');
$this->objectTao = $tester->loadTao('projectrelease');
}
/**
@@ -99,4 +100,26 @@ class projectreleaseTest
return $isClickable ? 1 : 2;
}
/**
* 测试获取分支名称。
* Test get branch name.
*
* @param int $productID
* @param string $branch
* @param array $branchGroup
* @access public
* @return string|array
*/
public function getBranchNameTest(int $productID, string $branch, array $branchGroup): string|array
{
$reflectionClass = new ReflectionClass($this->objectTao);
$method = $reflectionClass->getMethod('getBranchName');
$method->setAccessible(true);
$result = $method->invoke($this->objectTao, $productID, $branch, $branchGroup);
if(dao::isError()) return dao::getError();
return $result;
}
}
+44
View File
@@ -0,0 +1,44 @@
#!/usr/bin/env php
<?php
/**
title=测试 projectreleaseTao::getBranchName();
timeout=0
cid=0
- 执行projectreleaseTest模块的getBranchNameTest方法,参数是1, '1', $branchGroup @branch1
- 执行projectreleaseTest模块的getBranchNameTest方法,参数是1, '1, 2, 3', $branchGroup @branch1,branch2,branch3
- 执行projectreleaseTest模块的getBranchNameTest方法,参数是1, '', $branchGroup @0
- 执行projectreleaseTest模块的getBranchNameTest方法,参数是999, '1', $branchGroup @0
- 执行projectreleaseTest模块的getBranchNameTest方法,参数是1, '999', $branchGroup @0
*/
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/projectrelease.unittest.class.php';
zenData('branch')->loadYaml('branch', false, 2)->gen(5);
su('admin');
$projectreleaseTest = new projectreleaseTest();
$branchGroup = array(
1 => array(
1 => 'branch1',
2 => 'branch2',
3 => 'branch3'
),
2 => array(
4 => 'branch4',
5 => 'branch5'
)
);
r($projectreleaseTest->getBranchNameTest(1, '1', $branchGroup)) && p() && e('branch1');
r($projectreleaseTest->getBranchNameTest(1, '1,2,3', $branchGroup)) && p() && e('branch1,branch2,branch3');
r($projectreleaseTest->getBranchNameTest(1, '', $branchGroup)) && p() && e('0');
r($projectreleaseTest->getBranchNameTest(999, '1', $branchGroup)) && p() && e('0');
r($projectreleaseTest->getBranchNameTest(1, '999', $branchGroup)) && p() && e('0');
@@ -0,0 +1,35 @@
---
title: 分支测试数据
desc: 用于测试getBranchName方法的分支数据
fields:
- field: id
note: 分支ID
range: 1-5
- field: product
note: 所属产品ID
range: 1{3},2{2}
- field: name
note: 分支名称
range: branch1,branch2,branch3,branch4,branch5
- field: default
note: 是否默认分支
range: '0{4},1{1}'
- field: status
note: 分支状态
range: active{4},closed{1}
- field: desc
note: 分支描述
range: 测试分支{5}
- field: createdDate
note: 创建日期
range: 2023-01-01,2023-01-02,2023-01-03,2023-01-04,2023-01-05
- field: closedDate
note: 关闭日期
range: '0000-00-00{4},2023-12-31{1}'
- field: order
note: 排序
range: 1-5
- field: deleted
note: 是否删除
range: '0'