+ Add unit test case for gitlab->apigetbygraphql.

This commit is contained in:
caoyanyi
2024-01-11 16:45:46 +08:00
parent 350ae353a0
commit 56bca0d193
2 changed files with 45 additions and 0 deletions
+16
View File
@@ -395,4 +395,20 @@ class gitlabTest
return json_decode($result);
}
/**
* Test apiGetByGraphql method.
*
* @param string $query
* @access public
* @return object|null|array
*/
public function apiGetByGraphqlTest(string $query): object|null|array
{
$repo = $this->gitlab->loadModel('repo')->getByID(1);
$result = $this->gitlab->apiGetByGraphql($repo, $query);
if(!$result) return $result;
if(isset($result->errors)) return array_column($result->errors, 'message');
return $result->data->project->repository->tree;
}
}
+29
View File
@@ -0,0 +1,29 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/gitlab.class.php';
su('admin');
/**
title=测试 gitlabModel::apiGetByGraphql();
timeout=0
cid=1
- 空的查询参数 @Unexpected end of document
- 错误的查询参数 @Parse error on "error" (IDENTIFIER) at [1, 1]
- 正确的参数第lastCommit条的sha属性 @1b9405639ddef9585b3743b0637b4f79775409b7
*/
zdTable('pipeline')->gen(5);
zdTable('repo')->config('repo')->gen(1);
$gitlab = new gitlabTest();
r($gitlab->apiGetByGraphqlTest('')) && p('0') && e('Unexpected end of document'); // 空的查询参数
r($gitlab->apiGetByGraphqlTest('error')) && p('0') && e('Parse error on "error" (IDENTIFIER) at [1, 1]'); // 错误的查询参数
$real = 'query {project(fullPath: "gitlab-instance-76af86df/testhtml") {repository {tree(path: "") {lastCommit {sha message}}}}}';
r($gitlab->apiGetByGraphqlTest($real)) && p('lastCommit:sha') && e('1b9405639ddef9585b3743b0637b4f79775409b7'); // 正确的参数