From b3d41cc72a15a4364c3ae858b1be1c7412f7d8fa Mon Sep 17 00:00:00 2001 From: zenggang Date: Thu, 11 Jan 2024 09:41:47 +0000 Subject: [PATCH] * Adjust gitlab unit test --- module/gitlab/model.php | 8 +++---- module/gitlab/test/gitlab.class.php | 33 ++++++++++++++++++----------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index c976a20cae..c7e8d0599e 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -337,13 +337,13 @@ class gitlabModel extends model * Send an api post request. * * @param int|string $host gitlab server ID | gitlab host url. - * @param string $api - * @param array $data - * @param array $options + * @param string $api + * @param array|object $data + * @param array $options * @access public * @return object|array|null */ - public function apiPost(int|string $host, string $api, array $data = array(), array $options = array()): object|array|null + public function apiPost(int|string $host, string $api, array|object $data = array(), array $options = array()): object|array|null { if(is_numeric($host)) $host = $this->getApiRoot($host); if(strpos($host, 'http://') !== 0 and strpos($host, 'https://') !== 0) return false; diff --git a/module/gitlab/test/gitlab.class.php b/module/gitlab/test/gitlab.class.php index 05e27e4047..a260f77061 100644 --- a/module/gitlab/test/gitlab.class.php +++ b/module/gitlab/test/gitlab.class.php @@ -412,20 +412,29 @@ class gitlabTest return $result->data->project->repository->tree; } - /** - * Test getFileLastCommit method. - * - * @param string $path - * @param string $branch - * @access public - * @return object|null|array - */ - public function getFileLastCommitTest(string $path, string $branch): object|array|null + public function getFileLastCommitTest(int $repoID, string $path, string $branch = 'HEAD') { - $repo = $this->gitlab->loadModel('repo')->getByID(1); + $repo = $this->gitlab->loadModel('repo')->getByID($repoID); + $result = $this->gitlab->getFileLastCommit($repo, $path, $branch); - if(!$result) return $result; - if(isset($result->errors)) return array_column($result->errors, 'message'); + return $result; + } + + public function apiGetTest(int|string $host, string $api) + { + $result = $this->gitlab->apiGet($host, $api); + + if(is_null($result)) return 'return null'; + if(isset($result->id)) return 'success'; + return $result; + } + + public function apiPostTest(int|string $host, string $api, array|object $data = array(), array $options = array()) + { + $result = $this->gitlab->apiGet($host, $api, $data, $options); + + if(is_null($result)) return 'return null'; + if(isset($result->name)) return 'success'; return $result; } }