* [misc] Enhance unit tests for gitModel::setRepoRoot() 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 7f5ff3c5a7
commit 3c417a66ff
3 changed files with 113 additions and 10 deletions
@@ -231,4 +231,19 @@ class gitTest
'repoRoot' => $this->gitModel->repoRoot
);
}
/**
* Test setRepoRoot method.
*
* @param object $repo
* @access public
* @return string
*/
public function setRepoRootTest(object $repo): string
{
$this->gitModel->setRepoRoot($repo);
if(dao::isError()) return dao::getError();
return $this->gitModel->repoRoot;
}
}
+35 -10
View File
@@ -3,23 +3,48 @@
/**
title=gitModel->setRepoRoot();
title=测试 gitModel::setRepoRoot();
timeout=0
cid=1
cid=0
- 查询Git仓库信息属性repoRoot @https://gitlabdev.qc.oop.cc/root/unittest1
- 执行gitTest模块的setRepoRootTest方法,参数是$normalRepo @/home/git/normal
- 执行gitTest模块的setRepoRootTest方法,参数是$specialRepo @/path/with-special_chars
- 执行gitTest模块的setRepoRootTest方法,参数是$chineseRepo @/路径/包含中文字符
- 执行gitTest模块的setRepoRootTest方法,参数是$emptyRepo @0
- 执行gitTest模块的setRepoRootTest方法,参数是$longRepo @/very/long/path/that/contains/many/levels/of/directories/and/subdirectories/to/test/long/path/handling
- 执行gitTest模块的setRepoRootTest方法,参数是$spaceRepo @/path with spaces
*/
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/git.unittest.class.php';
zenData('repo')->loadYaml('repo')->gen(1);
zenData('repo')->loadYaml('repo_setreporoot', false, 2)->gen(6);
su('admin');
global $tester;
$git = $tester->loadModel('git');
$git->setRepos();
$gitTest = new gitTest();
$repo = $git->repos[1];
$git->setRepoRoot($repo);
r($git) && p('repoRoot') && e('https://gitlabdev.qc.oop.cc/root/unittest1'); // 查询Git仓库信息
$normalRepo = new stdclass();
$normalRepo->path = '/home/git/normal';
$specialRepo = new stdclass();
$specialRepo->path = '/path/with-special_chars';
$chineseRepo = new stdclass();
$chineseRepo->path = '/路径/包含中文字符';
$emptyRepo = new stdclass();
$emptyRepo->path = '';
$longRepo = new stdclass();
$longRepo->path = '/very/long/path/that/contains/many/levels/of/directories/and/subdirectories/to/test/long/path/handling';
$spaceRepo = new stdclass();
$spaceRepo->path = '/path with spaces';
r($gitTest->setRepoRootTest($normalRepo)) && p() && e('/home/git/normal');
r($gitTest->setRepoRootTest($specialRepo)) && p() && e('/path/with-special_chars');
r($gitTest->setRepoRootTest($chineseRepo)) && p() && e('/路径/包含中文字符');
r($gitTest->setRepoRootTest($emptyRepo)) && p() && e('0');
r($gitTest->setRepoRootTest($longRepo)) && p() && e('/very/long/path/that/contains/many/levels/of/directories/and/subdirectories/to/test/long/path/handling');
r($gitTest->setRepoRootTest($spaceRepo)) && p() && e('/path with spaces');
@@ -0,0 +1,63 @@
---
title: setRepoRoot方法测试数据
desc: 为gitModel::setRepoRoot()方法提供多种路径场景的测试数据
author: Claude
version: 1.0
fields:
- field: id
note: 仓库ID
range: 1-10
prefix: ""
postfix: ""
loop: 0
format: ""
- field: path
note: 仓库路径
range: '[/home/git/normal,/path/with-special_chars,/路径/包含中文字符,,/very/long/path/that/contains/many/levels/of/directories/and/subdirectories/to/test/long/path/handling,/path with spaces]'
prefix: ""
postfix: ""
loop: 0
format: ""
- field: name
note: 仓库名称
range: '[normal_repo,special_repo,chinese_repo,empty_repo,long_repo,space_repo]'
prefix: ""
postfix: ""
loop: 0
format: ""
- field: SCM
note: SCM类型
range: Git{6}
prefix: ""
postfix: ""
loop: 0
format: ""
- field: client
note: 客户端路径
range: '/usr/bin/git{6}'
prefix: ""
postfix: ""
loop: 0
format: ""
- field: account
note: 账户
range: 'testuser{6}'
prefix: ""
postfix: ""
loop: 0
format: ""
- field: password
note: 密码
range: 'testpass{6}'
prefix: ""
postfix: ""
loop: 0
format: ""
- field: encoding
note: 编码
range: 'utf-8{6}'
prefix: ""
postfix: ""
loop: 0
format: ""