From 3c417a66ffcdc84d1dced050e7c8480939f2817e Mon Sep 17 00:00:00 2001 From: liugang Date: Mon, 22 Sep 2025 16:24:11 +0800 Subject: [PATCH] * [misc] Enhance unit tests for gitModel::setRepoRoot() method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- module/git/test/lib/git.unittest.class.php | 15 +++++ module/git/test/model/setreporoot.php | 45 ++++++++++--- .../git/test/model/yaml/repo_setreporoot.yaml | 63 +++++++++++++++++++ 3 files changed, 113 insertions(+), 10 deletions(-) create mode 100644 module/git/test/model/yaml/repo_setreporoot.yaml diff --git a/module/git/test/lib/git.unittest.class.php b/module/git/test/lib/git.unittest.class.php index 0e26b6245c..3bfd5d9e49 100755 --- a/module/git/test/lib/git.unittest.class.php +++ b/module/git/test/lib/git.unittest.class.php @@ -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; + } } diff --git a/module/git/test/model/setreporoot.php b/module/git/test/model/setreporoot.php index ffab0ee26c..d7680e57aa 100755 --- a/module/git/test/model/setreporoot.php +++ b/module/git/test/model/setreporoot.php @@ -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仓库信息 \ No newline at end of file +$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'); \ No newline at end of file diff --git a/module/git/test/model/yaml/repo_setreporoot.yaml b/module/git/test/model/yaml/repo_setreporoot.yaml new file mode 100644 index 0000000000..d8f6862cde --- /dev/null +++ b/module/git/test/model/yaml/repo_setreporoot.yaml @@ -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: "" \ No newline at end of file