From 75622a305e7fca3985c70fab6f73cc3dac76e276 Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Fri, 22 Dec 2023 18:55:16 +0800 Subject: [PATCH] + Add unit test case for git->run. --- module/git/test/git.class.php | 76 ++++++--------------------- module/git/test/model/run.php | 24 +++++++++ module/git/test/yaml/repohistory.yaml | 8 +-- 3 files changed, 44 insertions(+), 64 deletions(-) create mode 100755 module/git/test/model/run.php diff --git a/module/git/test/git.class.php b/module/git/test/git.class.php index 22ade7c57b..e1952ffcc1 100755 --- a/module/git/test/git.class.php +++ b/module/git/test/git.class.php @@ -24,66 +24,6 @@ class gitTest return $this->gitModel->dao->select('*')->from(TABLE_REPOHISTORY)->where('repo')->eq($repoID)->orderBy('id_desc')->fetch(); } - /** - * Set the repos. - * - * @access public - * @return object - */ - public function setRepos() - { - $this->gitModel->setRepos(); - $repo = array_shift($this->gitModel->repos); - return $repo; - } - - /** - * Get repos. - * - * @access public - * @return string - */ - public function getRepos() - { - $pairs = $this->gitModel->getRepos(); - return array_shift($pairs); - } - - /** - * Set repo. - * - * @param object $repo - * @access public - * @return object - */ - public function setRepo($repo) - { - $this->gitModel->client = ''; - $this->gitModel->repoRoot = ''; - - $result = $this->gitModel->setRepo($repo); - - $data = new stdclass(); - $data->result = $result; - $data->client = !empty($this->gitModel->client); - $data->repoRoot = !empty($this->gitModel->repoRoot); - return $data; - } - - /** - * get tags histories for repo. - * - * @param object $repo - * @access public - * @return int - */ - public function getRepoTags($repo) - { - $tags = $this->gitModel->getRepoTags($repo); - if(is_array($tags) and count($tags) >= 1) return 1; - return 0; - } - /** * Get repo logs. * @@ -97,4 +37,20 @@ class gitTest $repo = $this->gitModel->loadModel('repo')->getByID($repoID); return $this->gitModel->getRepoLogs($repo, $branch); } + + /** + * Test run method. + * + * @access public + * @return object|bool + */ + public function runTest(): object|bool + { + ob_start(); + $this->gitModel->run(); + ob_get_clean(); + if(dao::isError()) return dao::getError(); + + return $this->gitModel->dao->select('*')->from(TABLE_REPOHISTORY)->where('id')->eq(2)->fetch(); + } } diff --git a/module/git/test/model/run.php b/module/git/test/model/run.php new file mode 100755 index 0000000000..ae1704a0c8 --- /dev/null +++ b/module/git/test/model/run.php @@ -0,0 +1,24 @@ +#!/usr/bin/env php +run(); +timeout=0 +cid=1 + +- 更新git提交信息到禅道,Gtilab的webhook调用 @0 + +*/ + +include dirname(__FILE__, 5) . '/test/lib/init.php'; +include dirname(__FILE__, 2) . '/git.class.php'; + +zdTable('job')->gen(0); +zdTable('repo')->config('repo')->gen(1); +zdTable('repohistory')->gen(0); +su('admin'); + +$git = new gitTest(); + +r($git->runTest()) && p() && e('0'); // 更新git提交信息到禅道,Gtilab的webhook调用 \ No newline at end of file diff --git a/module/git/test/yaml/repohistory.yaml b/module/git/test/yaml/repohistory.yaml index 6b303c9400..023d80d228 100644 --- a/module/git/test/yaml/repohistory.yaml +++ b/module/git/test/yaml/repohistory.yaml @@ -7,12 +7,12 @@ fields: - field: repo range: 1 - field: revision - range: 1 + range: 0dbb150d4904c9a9d5a804b6cdddea3cb3d856bb - field: commit range: 1 - field: comment - range: '+ Add fiel.' + range: 'Initial commit' - field: committer - range: admin + range: gitea - field: time - range: '`2023-12-14 09:04:27`' + range: '`2023-12-13 09:04:27`'