diff --git a/module/repo/test/lib/repo.unittest.class.php b/module/repo/test/lib/repo.unittest.class.php index 72899e2361..e311274bfb 100755 --- a/module/repo/test/lib/repo.unittest.class.php +++ b/module/repo/test/lib/repo.unittest.class.php @@ -42,6 +42,23 @@ class repoTest return $result; } + /** + * Test getLastRevision method. + * + * @param int $repoID + * @access public + * @return mixed + */ + public function getLastRevisionTest(int $repoID) + { + $method = new ReflectionMethod($this->objectTao, 'getLastRevision'); + $method->setAccessible(true); + $result = $method->invoke($this->objectTao, $repoID); + if(dao::isError()) return dao::getError(); + + return $result; + } + public function setMenuTest(int $repoID = 0) { $repos = $this->objectModel->dao->select('id')->from(TABLE_REPO)->fetchPairs('id'); @@ -1851,4 +1868,23 @@ class repoTest return $result; } + + /** + * Test getLatestCommitTime method. + * + * @param int $repoID + * @param string $revision + * @param string $branch + * @access public + * @return mixed + */ + public function getLatestCommitTimeTest(int $repoID, string $revision = 'HEAD', string $branch = '') + { + $method = new ReflectionMethod($this->objectTao, 'getLatestCommitTime'); + $method->setAccessible(true); + $result = $method->invoke($this->objectTao, $repoID, $revision, $branch); + if(dao::isError()) return dao::getError(); + + return $result; + } } diff --git a/module/repo/test/tao/getlatestcommittime.php b/module/repo/test/tao/getlatestcommittime.php index 704950e708..975da6defe 100755 --- a/module/repo/test/tao/getlatestcommittime.php +++ b/module/repo/test/tao/getlatestcommittime.php @@ -1,31 +1,36 @@ #!/usr/bin/env php getLatestCommitTime(); +title=测试 repoTao::getLatestCommitTime(); timeout=0 -cid=8 +cid=0 -- 获取版本库1提交时间 @2023-12-13 19:00:25 -- 获取版本库3提交时间 @2023-12-18 19:00:25 -- 指定revision获取版本库3提交时间 @2023-12-13 13:04:27 +- 测试步骤1:正常获取版本库1的HEAD提交时间 @2023-12-13 19:00:25 +- 测试步骤2:正常获取版本库3的HEAD提交时间 @2023-12-18 19:00:25 +- 测试步骤3:指定特定revision获取提交时间 @2023-12-13 13:04:27 +- 测试步骤4:测试不存在的分支 @0 +- 测试步骤5:测试无效版本库ID的边界情况 @0 +- 测试步骤6:测试不存在的revision @0 +- 测试步骤7:测试版本库ID为0的边界情况 @0 */ +include dirname(__FILE__, 5) . '/test/lib/init.php'; +include dirname(__FILE__, 2) . '/lib/repo.unittest.class.php'; + zenData('repo')->loadYaml('repo')->gen(4); zenData('repohistory')->loadYaml('repohistory')->gen(3); -$repo = $tester->loadModel('repo'); +su('admin'); -$gitlabID = 1; -$giteaID = 3; -$revision = 'HEAD'; +$repoTest = new repoTest(); -r($repo->getLatestCommitTime($gitlabID, $revision, '')) && p() && e('2023-12-13 19:00:25'); //获取版本库1提交时间 -r($repo->getLatestCommitTime($giteaID, $revision, '')) && p() && e('2023-12-18 19:00:25'); //获取版本库3提交时间 -$revision = '0dbb150d4904c9a9d5a804b6cdddea3cb3d856bb'; -r($repo->getLatestCommitTime($giteaID, $revision, '')) && p() && e('2023-12-13 13:04:27'); //指定revision获取版本库3提交时间 \ No newline at end of file +r($repoTest->getLatestCommitTimeTest(1, 'HEAD', '')) && p() && e('2023-12-13 19:00:25'); // 测试步骤1:正常获取版本库1的HEAD提交时间 +r($repoTest->getLatestCommitTimeTest(3, 'HEAD', '')) && p() && e('2023-12-18 19:00:25'); // 测试步骤2:正常获取版本库3的HEAD提交时间 +r($repoTest->getLatestCommitTimeTest(3, '0dbb150d4904c9a9d5a804b6cdddea3cb3d856bb', '')) && p() && e('2023-12-13 13:04:27'); // 测试步骤3:指定特定revision获取提交时间 +r($repoTest->getLatestCommitTimeTest(1, 'HEAD', 'develop')) && p() && e('0'); // 测试步骤4:测试不存在的分支 +r($repoTest->getLatestCommitTimeTest(999, 'HEAD', '')) && p() && e('0'); // 测试步骤5:测试无效版本库ID的边界情况 +r($repoTest->getLatestCommitTimeTest(1, 'nonexistent-revision', '')) && p() && e('0'); // 测试步骤6:测试不存在的revision +r($repoTest->getLatestCommitTimeTest(0, 'HEAD', '')) && p() && e('0'); // 测试步骤7:测试版本库ID为0的边界情况 \ No newline at end of file