diff --git a/module/git/test/lib/git.unittest.class.php b/module/git/test/lib/git.unittest.class.php index efdc1d5521..0e26b6245c 100755 --- a/module/git/test/lib/git.unittest.class.php +++ b/module/git/test/lib/git.unittest.class.php @@ -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 + ); + } } diff --git a/module/git/test/model/setrepo.php b/module/git/test/model/setrepo.php index 4f7a863c9b..e807425b91 100755 --- a/module/git/test/model/setrepo.php +++ b/module/git/test/model/setrepo.php @@ -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仓库信息 \ No newline at end of file +// 准备测试数据 +$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的处理 \ No newline at end of file