* Adjust unit test case for git->updateCommit.

This commit is contained in:
caoyanyi
2023-12-22 18:36:12 +08:00
parent d213f5377b
commit be1482d466
2 changed files with 28 additions and 27 deletions
+11 -16
View File
@@ -1,32 +1,27 @@
<?php
class gitTest
{
public $tester;
public $gitModel;
public function __construct()
{
global $tester;
$this->tester = $tester;
$this->gitModel = $this->tester->loadModel('git');
$this->gitModel = $tester->loadModel('git');
}
/**
* Update commit.
* Test updateCommit method.
*
* @param object $repo
* @param array $commentGroup
* @param bool $printLog
* @access public
* @return bool
* @param int $repoID
* @access public
* @return object|false
*/
public function updateCommit($repo)
public function updateCommitTest(int $repoID): object|false
{
$repoID = isset($repo->id) ? $repo->id : 0;
$oldLastSync = $this->tester->dao->select('lastSync')->from(TABLE_REPO)->where('id')->eq($repoID)->fetch('lastSync');
$result = $this->gitModel->updateCommit($repo, array(), false);
if(empty($repoID)) return $result;
$newLastSync = $this->tester->dao->select('lastSync')->from(TABLE_REPO)->where('id')->eq($repoID)->fetch('lastSync');
return $oldLastSync != $newLastSync;
$repo = $this->gitModel->loadModel('repo')->getByID($repoID);
$this->gitModel->updateCommit($repo, array(), false);
return $this->gitModel->dao->select('*')->from(TABLE_REPOHISTORY)->where('repo')->eq($repoID)->orderBy('id_desc')->fetch();
}
/**
+17 -11
View File
@@ -1,25 +1,31 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/git.class.php';
su('admin');
/**
title=测试gitModel->updatecommit();
title=gitModel->updateCommit();
timeout=0
cid=1
- 测试正常的版本库 @1
- 测试空的版本库 @0
- 未同步的代码库 @0
- 已同步的代码库
- 属性id @3
- 属性repo @1
- 属性commit @3
*/
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/git.class.php';
$repo = zdTable('repo')->config('repo');
$repo->path->range('https://gitlabdev.qc.oop.cc/root/unittest1');
$repo->gen(3);
zdTable('repohistory')->config('repohistory')->gen(1);
su('admin');
$git = new gitTest();
$repo = $tester->dao->select('*')->from(TABLE_REPO)->limit(1)->fetch();
if(strtolower($repo->SCM) == 'gitlab') $repo = $tester->loadModel('repo')->processGitlab($repo);
r($git->updateCommit($repo)) && p() && e(1); // 测试正常的版本库
r($git->updateCommitTest(2)) && p() && e('0'); // 未同步的代码库
$repo = new stdclass();
r($git->updateCommit($repo)) && p() && e(0); // 测试空的版本库
r($git->updateCommitTest(1)) && p('id,repo,commit') && e('1,1,1'); // 已同步的代码库