* [misc] Enhance unit tests for gitModel::setRepo() 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:11 +08:00
co-authored by Claude
parent 66576506b8
commit 7f5ff3c5a7
2 changed files with 46 additions and 11 deletions
@@ -212,4 +212,23 @@ class gitTest
return 'error';
}
}
/**
* Test setRepo method.
*
* @param object $repo
* @access public
* @return array
*/
public function setRepoTest(object $repo): array
{
$result = $this->gitModel->setRepo($repo);
if(dao::isError()) return array('error' => dao::getError());
return array(
'result' => $result ? '1' : '0',
'client' => $this->gitModel->client,
'repoRoot' => $this->gitModel->repoRoot
);
}
}
+27 -11
View File
@@ -3,26 +3,42 @@
/**
title=gitModel->setRepo();
title=测试 gitModel::setRepo();
timeout=0
cid=1
cid=0
- 查询Git仓库信息
- 属性repoRoot @https://gitlabdev.qc.oop.cc/root/unittest1
- 属性client @https://gitlabdev.qc.oop.cc
- 测试步骤1:正常有效的Git仓库对象属性result @1
- 测试步骤2:包含空client属性的仓库对象属性result @0
- 测试步骤3:验证client属性正确设置属性client @https://gitlabdev.qc.oop.cc
- 测试步骤4:验证repoRoot属性正确设置属性repoRoot @https://gitlabdev.qc.oop.cc/root/unittest1
- 测试步骤5:测试空client的处理属性result @0
*/
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/git.unittest.class.php';
zenData('pipeline')->gen(1);
zenData('repo')->loadYaml('repo')->gen(1);
su('admin');
global $tester;
$git = $tester->loadModel('git');
$git->setRepos();
$gitTest = new gitTest();
$repo = $git->repos[1];
$git->setRepo($repo);
r($git) && p('repoRoot,client') && e('https://gitlabdev.qc.oop.cc/root/unittest1,https://gitlabdev.qc.oop.cc'); // 查询Git仓库信息
// 准备测试数据
$validRepo = new stdclass();
$validRepo->client = 'https://gitlabdev.qc.oop.cc';
$validRepo->path = 'https://gitlabdev.qc.oop.cc/root/unittest1';
$invalidRepo = new stdclass();
$invalidRepo->client = '';
$invalidRepo->path = '/invalid/path';
$nullClientRepo = new stdclass();
$nullClientRepo->client = null;
$nullClientRepo->path = '/some/path';
r($gitTest->setRepoTest($validRepo)) && p('result') && e('1'); // 测试步骤1:正常有效的Git仓库对象
r($gitTest->setRepoTest($invalidRepo)) && p('result') && e('0'); // 测试步骤2:包含空client属性的仓库对象
r($gitTest->setRepoTest($validRepo)) && p('client') && e('https://gitlabdev.qc.oop.cc'); // 测试步骤3:验证client属性正确设置
r($gitTest->setRepoTest($validRepo)) && p('repoRoot') && e('https://gitlabdev.qc.oop.cc/root/unittest1'); // 测试步骤4:验证repoRoot属性正确设置
r($gitTest->setRepoTest($nullClientRepo)) && p('result') && e('0'); // 测试步骤5:测试空client的处理