* Adjust mr create method unit test case.

This commit is contained in:
caoyanyi
2023-12-15 13:59:37 +08:00
parent 9e8856dbf4
commit e010ce212c
2 changed files with 44 additions and 31 deletions
+2 -2
View File
@@ -535,9 +535,9 @@ class mrModel extends model
* @param string $projectID
* @param object $MR
* @access public
* @return object
* @return object|null
*/
public function apiCreateMR(int $hostID, string $projectID, object $MR): object
public function apiCreateMR(int $hostID, string $projectID, object $MR): object|null
{
$host = $this->loadModel('pipeline')->getByID($hostID);
Regular → Executable
+42 -29
View File
@@ -1,44 +1,57 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 5) . '/test/lib/init.php';
/**
title=测试 mrModel::create();
timeout=0
cid=0
pid=0
使用空的repoID, gitlabID。创建mr。 >> 『GitLab』不能为空。
使用正确的repoID, gitlabID。POST数据正确 或者错误原因为已存在一样的mr请求 >> success
使用源分支和目标分支一样的数据mr请求 >> 通过API创建合并请求失败,失败原因:源项目分支与目标项目分支不能相同
- hostID为空第hostID条的0属性 @『服务器』不能为空。
- 使用已存在的mr请求数据 @存在重复并且未关闭的合并请求: ID1
- 使用源项目分支与目标项目分支相同的mr请求数据属性result @存在另外一个同样的合并请求在源项目分支中: ID30
- 使用源项目分支与目标项目分支相同的mr请求数据 @源项目分支与目标项目分支不能相同
- 使用正确的mr请求数据属性result @success
*/
$mrModel = $tester->loadModel('mr');
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/mr.class.php';
$_POST = array();
zdTable('pipeline')->gen(1);
zdTable('repo')->config('repo')->gen(1);
zdTable('mr')->config('mr')->gen(1);
$_POST['gitlabID'] = 0;
$_POST['repoID'] = 0;
$_POST['sourceProject'] = 42;
$_POST['sourceBranch'] = 'branch-08';
$_POST['targetProject'] = 42;
$_POST['targetBranch'] = 'branch-09';
$result = $mrModel->create();
r($result) && p('message[gitlabID]:0') && e('『GitLab』不能为空。'); //使用空的repoID, gitlabID。创建mr。
$mrModel = new mrTest();
$_POST['gitlabID'] = 1;
$_POST['title'] = 'test_create';
$_POST['description'] = 'test_create';
$_POST['repoID'] = 1;
$_POST['assignee'] = '';
$_POST['removeSourceBranch'] = '1';
$result = $mrModel->create();
if($result['result'] == 'success') $result = 'success';
$result = preg_match('/存在另外一个同样的合并请求在源项目分支中: ID([0-9]+)/', $result['message'], $matches); //检查错误原因是否是已存在一样的mr请求
if($result) $result = 'success';
r($result) && p() && e('success'); //使用正确的repoID, gitlabID。POST数据正确 或者错误原因为已存在一样的mr请求
$MR = new stdclass();
$MR->hostID = 0;
$MR->sourceProject = '3';
$MR->targetProject = '3';
$MR->sourceBranch = 'test1';
$MR->targetBranch = 'master';
$MR->title = 'test-merge';
$MR->assignee = 'admin';
$MR->repoID = 1;
$MR->executionID = 0;
$MR->needCI = 0;
$MR->removeSourceBranch = 0;
$MR->squash = 0;
$MR->jobID = 0;
$MR->description = 'test-merge';
$MR->createdBy = 'admin';
$MR->createdDate = '2023-12-01 00:00:00';
$_POST['targetBranch'] = 'branch-08';
$result = $mrModel->create();
r($result) && p('message') && e('通过API创建合并请求失败,失败原因:源项目分支与目标项目分支不能相同'); //使用源分支和目标分支一样的数据mr请求
r($mrModel->createTester($MR)) && p('hostID:0') && e('『服务器』不能为空。'); // hostID为空
$MR->hostID = 1;
r($mrModel->createTester($MR)) && p() && e('存在重复并且未关闭的合并请求: ID1'); // 使用已存在的mr请求数据
$MR->sourceBranch = 'laudantium-unde-et-iste-et';
r($mrModel->createTester($MR)) && p('result') && e('存在另外一个同样的合并请求在源项目分支中: ID30'); // 使用源项目分支与目标项目分支相同的mr请求数据
$MR->targetBranch = 'laudantium-unde-et-iste-et';
r($mrModel->createTester($MR)) && p() && e('源项目分支与目标项目分支不能相同'); // 使用源项目分支与目标项目分支相同的mr请求数据
$MR->sourceBranch = 'test';
r($mrModel->createTester($MR)) && p('result') && e('success'); // 使用正确的mr请求数据