* [misc] Enhance unit tests for repoModel::processGitService() 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:32 +08:00
co-authored by Claude
parent 2c42269b3b
commit 4abeebd779
2 changed files with 98 additions and 11 deletions
@@ -761,9 +761,18 @@ class repoTest
return $objects;
}
/**
* Test processGitService method.
*
* @param int $repoID
* @access public
* @return mixed
*/
public function processGitServiceTest(int $repoID)
{
$repo = $this->objectModel->dao->select('*')->from(TABLE_REPO)->where('id')->eq($repoID)->fetch();
if(!$repo) return false;
$repo->codePath = $repo->path;
$objects = $this->objectModel->processGitService($repo);
@@ -773,6 +782,67 @@ class repoTest
return $objects;
}
/**
* Test processGitService method with getCodePath parameter.
*
* @param int $repoID
* @access public
* @return mixed
*/
public function processGitServiceTestWithCodePath(int $repoID)
{
$repo = $this->objectModel->dao->select('*')->from(TABLE_REPO)->where('id')->eq($repoID)->fetch();
$repo->codePath = $repo->path;
$objects = $this->objectModel->processGitService($repo, true);
if(dao::isError()) return dao::getError();
return $objects;
}
/**
* Test processGitService method with invalid path.
*
* @param int $repoID
* @access public
* @return mixed
*/
public function processGitServiceTestWithInvalidPath(int $repoID)
{
$repo = $this->objectModel->dao->select('*')->from(TABLE_REPO)->where('id')->eq($repoID)->fetch();
$repo->codePath = $repo->path;
$repo->path = '/invalid/path/that/does/not/exist';
$objects = $this->objectModel->processGitService($repo);
if(dao::isError()) return dao::getError();
return $objects;
}
/**
* Test processGitService method with empty serviceHost.
*
* @param int $repoID
* @access public
* @return mixed
*/
public function processGitServiceTestWithEmptyHost(int $repoID)
{
$repo = $this->objectModel->dao->select('*')->from(TABLE_REPO)->where('id')->eq($repoID)->fetch();
if(!$repo) return false;
$repo->codePath = $repo->path;
$repo->serviceHost = 0;
$objects = $this->objectModel->processGitService($repo);
if(dao::isError()) return dao::getError();
return $objects;
}
public function handleWebhookTest(string $event, object $data, int $repoID)
{
$repo = $this->objectModel->getByID($repoID);
+28 -11
View File
@@ -1,29 +1,46 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/repo.unittest.class.php';
su('admin');
/**
title=测试 repoModel->processGitService();
title=测试 repoModel::processGitService();
timeout=0
cid=1
cid=0
- 测试获取gitlab版本库
- 步骤1:正常处理Gitlab版本库
- 属性client @https://gitlabdev.qc.oop.cc
- 属性codePath @http://gitlabdev.qc.oop.cc/gitlab-instance-76af86df/testhtml
- 属性gitService @1
- 步骤2:正常处理Gitea版本库
- 属性codePath @https://giteadev.qc.oop.cc/gitea/unittest
- 属性name @unittest
- 步骤3:处理另一个Gitlab版本库属性gitService @1
- 步骤4:处理serviceHost=0的版本库属性gitService @1
- 步骤5:测试getCodePath=true的Gitlab版本库属性gitService @1
- 步骤6:测试路径不存在的情况属性gitService @1
- 步骤7:测试Gitea版本库的getCodePath属性name @unittest
*/
// 1. 导入依赖(路径固定,不可修改)
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/repo.unittest.class.php';
// 2. zendata数据准备
zenData('pipeline')->gen(5);
zenData('repo')->loadYaml('repo')->gen(5);
// 3. 用户登录
su('admin');
// 4. 创建测试实例
$repo = new repoTest();
$gitlabID = 1;
$giteaID = 3;
r($repo->processGitServiceTest($gitlabID)) && p('client,codePath,gitService') && e('https://gitlabdev.qc.oop.cc,http://gitlabdev.qc.oop.cc/gitlab-instance-76af86df/testhtml,1'); //测试获取gitlab版本库
r($repo->processGitServiceTest($giteaID)) && p('codePath,project') && e('https://giteadev.qc.oop.cc/gitea/unittest,gitea/unittest'); //测试获取gitea版本库
// 5. 强制要求:必须包含至少7个测试步骤
r($repo->processGitServiceTest(1)) && p('client,codePath,gitService') && e('https://gitlabdev.qc.oop.cc,http://gitlabdev.qc.oop.cc/gitlab-instance-76af86df/testhtml,1'); // 步骤1:正常处理Gitlab版本库
r($repo->processGitServiceTest(3)) && p('codePath,name') && e('https://giteadev.qc.oop.cc/gitea/unittest,unittest'); // 步骤2:正常处理Gitea版本库
r($repo->processGitServiceTest(2)) && p('gitService') && e('1'); // 步骤3:处理另一个Gitlab版本库
r($repo->processGitServiceTest(5)) && p('gitService') && e('1'); // 步骤4:处理serviceHost=0的版本库
r($repo->processGitServiceTestWithCodePath(1)) && p('gitService') && e('1'); // 步骤5:测试getCodePath=true的Gitlab版本库
r($repo->processGitServiceTestWithInvalidPath(1)) && p('gitService') && e('1'); // 步骤6:测试路径不存在的情况
r($repo->processGitServiceTestWithCodePath(3)) && p('name') && e('unittest'); // 步骤7:测试Gitea版本库的getCodePath