* [misc] Enhance unit tests for mrModel::getGogsProjects() method
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -89,14 +89,38 @@ class mrTest
|
||||
*
|
||||
* @param int $hostID
|
||||
* @access public
|
||||
* @return array|null
|
||||
* @return mixed
|
||||
*/
|
||||
public function getGogsProjectsTester(int $hostID): array|null
|
||||
public function getGogsProjectsTester(int $hostID)
|
||||
{
|
||||
$projects = $this->objectModel->getGogsProjects($hostID);
|
||||
if(empty($projects[$hostID])) return null;
|
||||
$result = $this->objectModel->getGogsProjects($hostID);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $projects[$hostID];
|
||||
// 如果结果为空数组或无对应hostID,返回0表示无项目
|
||||
if(empty($result[$hostID])) return 0;
|
||||
|
||||
// 返回项目数量
|
||||
return count($result[$hostID]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getGogsProjects method for project details.
|
||||
*
|
||||
* @param int $hostID
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function getGogsProjectsDetailTester(int $hostID)
|
||||
{
|
||||
$result = $this->objectModel->getGogsProjects($hostID);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
// 如果结果为空数组或无对应hostID,返回null
|
||||
if(empty($result[$hostID])) return null;
|
||||
|
||||
// 返回第一个项目的信息用于测试
|
||||
$firstProject = reset($result[$hostID]);
|
||||
return $firstProject;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,13 +5,15 @@
|
||||
|
||||
title=测试 mrModel::getGogsProjects();
|
||||
timeout=0
|
||||
cid=1
|
||||
cid=0
|
||||
|
||||
- 服务器ID正确
|
||||
- 第easycorp/unittest条的id属性 @1
|
||||
- 第easycorp/unittest条的name属性 @unittest
|
||||
- 服务器ID为空 @0
|
||||
- 服务器ID不存在 @0
|
||||
- 测试步骤1:有效服务器ID查询项目数量 @1
|
||||
- 测试步骤2:项目详细信息验证
|
||||
- 属性id @1
|
||||
- 属性name @unittest
|
||||
- 测试步骤3:服务器ID为0的边界值测试 @0
|
||||
- 测试步骤4:不存在的服务器ID测试 @0
|
||||
- 测试步骤5:负数服务器ID测试 @0
|
||||
|
||||
*/
|
||||
|
||||
@@ -19,10 +21,14 @@ include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/mr.unittest.class.php';
|
||||
|
||||
zenData('pipeline')->gen(5);
|
||||
zenData('oauth')->loadYaml('oauth', false, 2)->gen(5);
|
||||
|
||||
su('admin');
|
||||
|
||||
$mrTester = new mrTest();
|
||||
$mrTest = new mrTest();
|
||||
|
||||
r($mrTester->getGogsProjectsTester(5)) && p('easycorp/unittest:id,name') && e('1,unittest'); // 服务器ID正确
|
||||
r($mrTester->getGogsProjectsTester(0)) && p() && e('0'); // 服务器ID为空
|
||||
r($mrTester->getGogsProjectsTester(100)) && p() && e('0'); // 服务器ID不存在
|
||||
r($mrTest->getGogsProjectsTester(5)) && p() && e('1'); // 测试步骤1:有效服务器ID查询项目数量
|
||||
r($mrTest->getGogsProjectsDetailTester(5)) && p('id,name') && e('1,unittest'); // 测试步骤2:项目详细信息验证
|
||||
r($mrTest->getGogsProjectsTester(0)) && p() && e('0'); // 测试步骤3:服务器ID为0的边界值测试
|
||||
r($mrTest->getGogsProjectsTester(999)) && p() && e('0'); // 测试步骤4:不存在的服务器ID测试
|
||||
r($mrTest->getGogsProjectsTester(-1)) && p() && e('0'); // 测试步骤5:负数服务器ID测试
|
||||
Reference in New Issue
Block a user