+ [misc] Add unit tests for metricModel::processOldMetrics() method
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -854,4 +854,149 @@ class metricTest
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test processOldMetrics method.
|
||||
*
|
||||
* @param mixed $metrics
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function processOldMetricsTest($metrics = null)
|
||||
{
|
||||
if($metrics === null)
|
||||
{
|
||||
// 默认测试数据
|
||||
$metrics = array();
|
||||
$metric1 = new stdClass();
|
||||
$metric1->id = 1;
|
||||
$metric1->type = 'sql';
|
||||
$metric1->fromID = 1;
|
||||
$metric1->unit = '';
|
||||
$metrics[] = $metric1;
|
||||
|
||||
$metric2 = new stdClass();
|
||||
$metric2->id = 2;
|
||||
$metric2->type = 'php';
|
||||
$metric2->fromID = 2;
|
||||
$metric2->unit = '';
|
||||
$metrics[] = $metric2;
|
||||
}
|
||||
|
||||
$result = $this->objectModel->processOldMetrics($metrics);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test processOldMetrics method with open edition.
|
||||
*
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function processOldMetricsOpenTest()
|
||||
{
|
||||
global $config;
|
||||
$originalEdition = $config->edition;
|
||||
$config->edition = 'open';
|
||||
|
||||
try {
|
||||
$metrics = array();
|
||||
$metric1 = new stdClass();
|
||||
$metric1->id = 1;
|
||||
$metric1->type = 'sql';
|
||||
$metric1->fromID = 1;
|
||||
$metric1->unit = '';
|
||||
$metrics[] = $metric1;
|
||||
|
||||
$result = $this->objectModel->processOldMetrics($metrics);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
finally
|
||||
{
|
||||
$config->edition = $originalEdition;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test processOldMetrics method with max edition.
|
||||
*
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function processOldMetricsMaxTest()
|
||||
{
|
||||
global $config;
|
||||
$originalEdition = $config->edition;
|
||||
$config->edition = 'max';
|
||||
|
||||
try {
|
||||
$metrics = array();
|
||||
$metric1 = new stdClass();
|
||||
$metric1->id = 1;
|
||||
$metric1->type = 'sql';
|
||||
$metric1->fromID = 1;
|
||||
$metric1->unit = '';
|
||||
$metrics[] = $metric1;
|
||||
|
||||
$result = $this->objectModel->processOldMetrics($metrics);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
finally
|
||||
{
|
||||
$config->edition = $originalEdition;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test processOldMetrics method with empty metrics.
|
||||
*
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function processOldMetricsEmptyTest()
|
||||
{
|
||||
$metrics = array();
|
||||
$result = $this->objectModel->processOldMetrics($metrics);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test processOldMetrics method with new metric type.
|
||||
*
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function processOldMetricsNewTest()
|
||||
{
|
||||
global $config;
|
||||
$originalEdition = $config->edition;
|
||||
$config->edition = 'max';
|
||||
|
||||
try {
|
||||
$metrics = array();
|
||||
$metric = new stdClass();
|
||||
$metric->id = 1;
|
||||
$metric->type = 'php';
|
||||
$metric->fromID = 1;
|
||||
$metric->unit = '';
|
||||
$metrics[] = $metric;
|
||||
|
||||
$result = $this->objectModel->processOldMetrics($metrics);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
finally
|
||||
{
|
||||
$config->edition = $originalEdition;
|
||||
}
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/**
|
||||
|
||||
title=测试 metricModel::processOldMetrics();
|
||||
timeout=0
|
||||
cid=0
|
||||
|
||||
- 步骤1:open版本处理第0条的isOldMetric属性 @1
|
||||
- 步骤2:max版本处理旧度量项第0条的isOldMetric属性 @0
|
||||
- 步骤3:空数据输入 @~~
|
||||
- 步骤4:新度量项处理第0条的isOldMetric属性 @~~
|
||||
- 步骤5:当前环境处理旧度量项第0条的isOldMetric属性 @~~
|
||||
|
||||
*/
|
||||
|
||||
// 1. 导入依赖(路径固定,不可修改)
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/metric.unittest.class.php';
|
||||
|
||||
// 2. zendata数据准备(根据需要配置)
|
||||
$table = zenData('basicmeas');
|
||||
$table->id->range('1-10');
|
||||
$table->name->range('基础度量项1,基础度量项2,基础度量项3,基础度量项4,基础度量项5,基础度量项6,基础度量项7,基础度量项8,基础度量项9,基础度量项10');
|
||||
$table->code->range('metric1,metric2,metric3,metric4,metric5,metric6,metric7,metric8,metric9,metric10');
|
||||
$table->unit->range('个,次,项,条,人,天,小时,百分比,元,台');
|
||||
$table->deleted->range('0{10}');
|
||||
$table->gen(10);
|
||||
|
||||
// 3. 用户登录(选择合适角色)
|
||||
su('admin');
|
||||
|
||||
// 4. 创建测试实例(变量名与模块名一致)
|
||||
$metricTest = new metricTest();
|
||||
|
||||
// 5. 🔴 强制要求:必须包含至少5个测试步骤
|
||||
r($metricTest->processOldMetricsOpenTest()) && p('0:isOldMetric') && e('1'); // 步骤1:open版本处理
|
||||
r($metricTest->processOldMetricsMaxTest()) && p('0:isOldMetric') && e('0'); // 步骤2:max版本处理旧度量项
|
||||
r($metricTest->processOldMetricsEmptyTest()) && p() && e('~~'); // 步骤3:空数据输入
|
||||
r($metricTest->processOldMetricsNewTest()) && p('0:isOldMetric') && e('~~'); // 步骤4:新度量项处理
|
||||
r($metricTest->processOldMetricsTest()) && p('0:isOldMetric') && e('~~'); // 步骤5:当前环境处理旧度量项
|
||||
@@ -0,0 +1,48 @@
|
||||
---
|
||||
title: 为processOldMetrics方法提供基础测量数据
|
||||
desc: 提供basicmeas表的测试数据以支持processOldMetrics方法的测试
|
||||
|
||||
fields:
|
||||
- field: id
|
||||
note: 基础测量ID
|
||||
range: 1-10
|
||||
|
||||
- field: purpose
|
||||
note: 目的
|
||||
range: '基础度量目的1,基础度量目的2,基础度量目的3,基础度量目的4,基础度量目的5,基础度量目的6,基础度量目的7,基础度量目的8,基础度量目的9,基础度量目的10'
|
||||
|
||||
- field: scope
|
||||
note: 作用范围
|
||||
range: 'system,product,project,execution,user'
|
||||
|
||||
- field: object
|
||||
note: 对象类型
|
||||
range: 'story,task,bug,case,project'
|
||||
|
||||
- field: name
|
||||
note: 基础测量名称
|
||||
range: '基础度量项1,基础度量项2,基础度量项3,基础度量项4,基础度量项5,基础度量项6,基础度量项7,基础度量项8,基础度量项9,基础度量项10'
|
||||
|
||||
- field: code
|
||||
note: 基础测量代码
|
||||
range: 'metric1,metric2,metric3,metric4,metric5,metric6,metric7,metric8,metric9,metric10'
|
||||
|
||||
- field: unit
|
||||
note: 单位
|
||||
range: '个,次,项,条,人,天,小时,百分比,元,台'
|
||||
|
||||
- field: configure
|
||||
note: 配置信息
|
||||
range: '{"type":"sql","sql":"SELECT COUNT(*) FROM zt_story"},{"type":"php","method":"getStoryCount"},{"type":"sql","sql":"SELECT COUNT(*) FROM zt_task"},{"type":"php","method":"getTaskCount"},{"type":"sql","sql":"SELECT COUNT(*) FROM zt_bug"},{"type":"php","method":"getBugCount"},{"type":"sql","sql":"SELECT COUNT(*) FROM zt_case"},{"type":"php","method":"getCaseCount"},{"type":"sql","sql":"SELECT COUNT(*) FROM zt_project"},{"type":"php","method":"getProjectCount"}'
|
||||
|
||||
- field: params
|
||||
note: 参数
|
||||
range: '[]{10}'
|
||||
|
||||
- field: definition
|
||||
note: 定义
|
||||
range: '度量项定义1,度量项定义2,度量项定义3,度量项定义4,度量项定义5,度量项定义6,度量项定义7,度量项定义8,度量项定义9,度量项定义10'
|
||||
|
||||
- field: deleted
|
||||
note: 是否删除
|
||||
range: '0{10}'
|
||||
Reference in New Issue
Block a user