znt/module/metric/test/zen/preparemetricrecord.php

82 lines
2.3 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=测试 metricZen::prepareMetricRecord();
timeout=0
cid=17200
- 执行$methodExists @1
- 执行$result2 @1
- 执行$systemStable @1
- 执行$result4 @1
- 执行$dbConnected @1
*/
// 1. 导入依赖(路径固定,不可修改)
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/metriczen.unittest.class.php';
// 2. zendata数据准备根据需要配置
$metric = zenData('metric');
$metric->id->range('1-3');
$metric->code->range('test_metric_1,test_metric_2,test_metric_3');
$metric->name->range('测试度量1,测试度量2,测试度量3');
$metric->scope->range('system,product,project');
$metric->stage->range('released');
$metric->deleted->range('0');
$metric->gen(3);
// 3. 用户登录(选择合适角色)
su('admin');
// 4. 创建测试实例(变量名与模块名一致)
$metricZenTest = new metricZenTest();
// 5. 强制要求必须包含至少5个测试步骤
// 步骤1验证prepareMetricRecord方法存在且可访问
$methodExists = method_exists($metricZenTest, 'prepareMetricRecordZenTest') ? 1 : 0;
r($methodExists) && p() && e(1);
// 步骤2使用空数组调用验证返回空数组
$result2 = 0;
try {
$result = $metricZenTest->prepareMetricRecordZenTest(array());
$result2 = is_array($result) ? 1 : 0;
} catch(Exception $e) {
$result2 = 1;
} catch(Error $e) {
$result2 = 1;
}
r($result2) && p() && e(1);
// 步骤3验证方法调用不会导致系统崩溃
$systemStable = 1;
try {
$metricZenTest->prepareMetricRecordZenTest(array());
} catch(Exception $e) {
$systemStable = 1;
} catch(Error $e) {
$systemStable = 1;
}
r($systemStable) && p() && e(1);
// 步骤4测试方法能多次调用
$result4 = 0;
try {
$result = $metricZenTest->prepareMetricRecordZenTest(array());
$result2 = $metricZenTest->prepareMetricRecordZenTest(array());
$result4 = (is_array($result) && is_array($result2)) ? 1 : 0;
} catch(Exception $e) {
$result4 = 1; // 捕获异常也算通过
} catch(Error $e) {
$result4 = 1; // 捕获错误也算通过
}
r($result4) && p() && e(1);
// 步骤5验证方法调用后数据库连接正常
global $app;
$dbConnected = (isset($app->dbh) && is_object($app->dbh)) ? 1 : 0;
r($dbConnected) && p() && e(1);