+ [misc] Add unit tests for metricZen::getRecordByCodeAndDate() method

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
liugang
2025-09-15 15:09:57 +08:00
co-authored by Claude
parent 6e44903bb2
commit 212fd6039f
3 changed files with 165 additions and 0 deletions
@@ -239,4 +239,24 @@ class metricZenTest
if(dao::isError()) return dao::getError();
return $result;
}
/**
* Test getRecordByCodeAndDate method.
*
* @param string $code
* @param object $calc
* @param string $date
* @param string $type
* @access public
* @return mixed
*/
public function getRecordByCodeAndDateZenTest($code, $calc, $date, $type = 'single')
{
$method = $this->metricZenTest->getMethod('getRecordByCodeAndDate');
$method->setAccessible(true);
$result = $method->invokeArgs($this->metricZenTest->newInstance(), array($code, $calc, $date, $type));
if(dao::isError()) return dao::getError();
return $result;
}
}
+63
View File
@@ -0,0 +1,63 @@
#!/usr/bin/env php
<?php
/**
title=测试 metricZen::getRecordByCodeAndDate();
timeout=0
cid=0
- 步骤1:正常度量项查询第0条的metricCode属性 @test_metric_001
- 步骤2:无效度量编码 @0
- 步骤3:无日期类型度量项第0条的metricCode属性 @no_date_metric
- 步骤4:全类型查询但有推断 @0
- 步骤5:验证返回的数据值第0条的value属性 @100
*/
// 1. 导入依赖
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/metriczen.unittest.class.php';
// 2. zendata数据准备
$table = zenData('metric');
$table->id->range('1-5');
$table->purpose->range('scale,quality,efficiency,performance,scale');
$table->scope->range('system,product,project,execution,system');
$table->object->range('product,project,execution,story,task');
$table->stage->range('released{4},wait');
$table->name->range('测试度量项1,测试度量项2,测试度量项3,无日期度量项,全类型度量项');
$table->code->range('test_metric_001,test_metric_002,test_metric_003,no_date_metric,all_type_metric');
$table->unit->range('个,天,小时,%,次');
$table->dateType->range('day,week,month,year,nodate');
$table->createdBy->range('admin{5}');
$table->createdDate->range("`2024-01-01 00:00:00`,`2024-01-02 00:00:00`,`2024-01-03 00:00:00`,`2024-01-04 00:00:00`,`2024-01-05 00:00:00`");
$table->gen(5);
// 3. 用户登录
su('admin');
// 4. 创建测试实例
$metricZenTest = new metricZenTest();
// 5. 创建模拟计算器对象
class MockCalc
{
public function getResult($dateConfig)
{
return array(
array('value' => 100, 'product' => 1),
array('value' => 200, 'project' => 2),
array('value' => 150, 'execution' => 3)
);
}
}
$calc = new MockCalc();
// 6. 测试步骤
r($metricZenTest->getRecordByCodeAndDateZenTest('test_metric_001', $calc, '2024-01-01', 'single')) && p('0:metricCode') && e('test_metric_001'); // 步骤1:正常度量项查询
r($metricZenTest->getRecordByCodeAndDateZenTest('invalid_code', $calc, '2024-01-01', 'single')) && p() && e('0'); // 步骤2:无效度量编码
r($metricZenTest->getRecordByCodeAndDateZenTest('no_date_metric', $calc, '2024-01-01', 'single')) && p('0:metricCode') && e('no_date_metric'); // 步骤3:无日期类型度量项
r($metricZenTest->getRecordByCodeAndDateZenTest('all_type_metric', $calc, '2024-01-01', 'all')) && p() && e('0'); // 步骤4:全类型查询但有推断
r($metricZenTest->getRecordByCodeAndDateZenTest('test_metric_002', $calc, '2024-01-02', 'single')) && p('0:value') && e('100'); // 步骤5:验证返回的数据值
@@ -0,0 +1,82 @@
---
title: 测试度量项数据
desc: 为getRecordByCodeAndDate方法测试提供数据
fields:
- field: id
note: 度量项ID
range: 1-10
prefix: ""
postfix: ""
loop: 0
format: ""
- field: purpose
note: 度量用途
range: scale,quality,efficiency
prefix: ""
postfix: ""
loop: 0
format: ""
- field: scope
note: 度量范围
range: system,product,project,execution
prefix: ""
postfix: ""
loop: 0
format: ""
- field: object
note: 度量对象
range: product,project,execution,story,task,bug
prefix: ""
postfix: ""
loop: 0
format: ""
- field: stage
note: 阶段状态
range: wait,released
prefix: ""
postfix: ""
loop: 0
format: ""
- field: name
note: 度量项名称
range: 测试度量项{1-10}
prefix: ""
postfix: ""
loop: 0
format: ""
- field: code
note: 度量项编码
range: test_metric_001,test_metric_002,test_metric_003,no_date_metric,all_type_metric
prefix: ""
postfix: ""
loop: 0
format: ""
- field: unit
note: 度量单位
range: 个,天,小时,%
prefix: ""
postfix: ""
loop: 0
format: ""
- field: dateType
note: 日期类型
range: day,week,month,year,nodate
prefix: ""
postfix: ""
loop: 0
format: ""
- field: createdBy
note: 创建者
range: admin,user1,user2
prefix: ""
postfix: ""
loop: 0
format: ""
- field: createdDate
note: 创建日期
range: '2024-01-01 00:00:00','2024-01-02 00:00:00','2024-01-03 00:00:00','2024-01-04 00:00:00','2024-01-05 00:00:00'
prefix: ""
postfix: ""
loop: 0
format: ""