znt/module/gitlab/test/model/apierrorhandling.php

68 lines
3.1 KiB
PHP
Executable file
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env php
<?php
/**
title=测试 gitlabModel::apiErrorHandling();
timeout=0
cid=16596
- 步骤1error字段错误处理 @403 Forbidden
- 步骤2字符串message错误处理 @保存失败群组URL路径已经被使用。
- 步骤3对象message数组字段错误处理第name条的0属性 @已经被使用
- 步骤4对象message字符串字段错误处理第password条的0属性 @密码太短最少8个字符
- 步骤5多字段错误处理 - 第一个name错误第name条的0属性 @GitLab项目已存在
- 步骤6空字段边界情况处理第valid_field条的0属性 @GitLab项目已存在
- 步骤7空响应异常情况处理 @0
*/
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/model.class.php';
zenData('pipeline')->gen(5);
su('admin');
$gitlab = new gitlabModelTest();
// 测试步骤1响应包含error字段的错误处理
$response1 = new stdclass();
$response1->error = '403 Forbidden';
// 测试步骤2响应包含字符串message的错误处理
$response2 = new stdclass();
$response2->message = 'Failed to save group {:path=>["已经被使用"]}';
// 测试步骤3响应包含对象message且字段为数组的错误处理
$response3 = new stdclass();
$response3->message = new stdclass();
$response3->message->name = array('已经被使用');
// 测试步骤4响应包含对象message且字段为字符串的错误处理
$response4 = new stdclass();
$response4->message = new stdclass();
$response4->message->password = 'is too short (minimum is 8 characters)';
// 测试步骤5响应包含多个字段错误的复杂错误处理
$response5 = new stdclass();
$response5->message = new stdclass();
$response5->message->name = array('has already been taken', 'is invalid');
$response5->message->path = 'admin is a reserved name';
// 测试步骤6响应包含空message的边界情况处理
$response6 = new stdclass();
$response6->message = new stdclass();
$response6->message->empty_field = array();
$response6->message->valid_field = 'has already been taken';
// 测试步骤7响应为空对象的异常情况处理
$response7 = new stdclass();
r($gitlab->apiErrorHandlingTest($response1)) && p('0') && e('403 Forbidden'); // 步骤1error字段错误处理
r($gitlab->apiErrorHandlingTest($response2)) && p('0') && e('保存失败群组URL路径已经被使用。'); // 步骤2字符串message错误处理
r($gitlab->apiErrorHandlingTest($response3)) && p('name:0') && e('已经被使用'); // 步骤3对象message数组字段错误处理
r($gitlab->apiErrorHandlingTest($response4)) && p('password:0') && e('密码太短最少8个字符'); // 步骤4对象message字符串字段错误处理
r($gitlab->apiErrorHandlingTest($response5)) && p('name:0') && e('GitLab项目已存在'); // 步骤5多字段错误处理 - 第一个name错误
r($gitlab->apiErrorHandlingTest($response6)) && p('valid_field:0') && e('GitLab项目已存在'); // 步骤6空字段边界情况处理
r($gitlab->apiErrorHandlingTest($response7)) && p('0') && e('0'); // 步骤7空响应异常情况处理