+ [misc] Add unit tests for metricTao::fetchMetricRecords() method
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1305,4 +1305,31 @@ class metricTest
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test fetchMetricRecords method.
|
||||
*
|
||||
* @param string $code
|
||||
* @param array $fieldList
|
||||
* @param array $query
|
||||
* @param object $pager
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function fetchMetricRecordsTest($code = '', $fieldList = array(), $query = array(), $pager = null)
|
||||
{
|
||||
// 检查度量项是否存在,如果不存在则返回空数组
|
||||
$metric = $this->objectModel->getByCode($code);
|
||||
if(!$metric) return array();
|
||||
|
||||
// 使用反射来调用protected方法
|
||||
$reflection = new ReflectionClass($this->objectTao);
|
||||
$method = $reflection->getMethod('fetchMetricRecords');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($this->objectTao, $code, $fieldList, $query, $pager);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/**
|
||||
|
||||
title=测试 metricTao::fetchMetricRecords();
|
||||
timeout=0
|
||||
cid=0
|
||||
|
||||
- 执行metricTest模块的fetchMetricRecordsTest方法,参数是'storyScale', array @0
|
||||
- 执行metricTest模块的fetchMetricRecordsTest方法,参数是'taskProgress', array @0
|
||||
- 执行metricTest模块的fetchMetricRecordsTest方法,参数是'invalidCode', array @0
|
||||
- 执行metricTest模块的fetchMetricRecordsTest方法,参数是'bugDensity', array @0
|
||||
- 执行metricTest模块的fetchMetricRecordsTest方法,参数是'codeQuality', array @0
|
||||
|
||||
*/
|
||||
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/metric.unittest.class.php';
|
||||
|
||||
zenData('metric')->loadYaml('metric_fetchmetricrecords', false, 2)->gen(10);
|
||||
zenData('metriclib')->loadYaml('metriclib_fetchmetricrecords', false, 2)->gen(50);
|
||||
|
||||
su('admin');
|
||||
|
||||
$metricTest = new metricTest();
|
||||
|
||||
r($metricTest->fetchMetricRecordsTest('storyScale', array('project', 'product'), array())) && p() && e('0');
|
||||
r($metricTest->fetchMetricRecordsTest('taskProgress', array(), array())) && p() && e('0');
|
||||
r($metricTest->fetchMetricRecordsTest('invalidCode', array('project'), array())) && p() && e('0');
|
||||
r($metricTest->fetchMetricRecordsTest('bugDensity', array('execution'), array('scope' => array(1, 2)))) && p() && e('0');
|
||||
r($metricTest->fetchMetricRecordsTest('codeQuality', array('system'), array())) && p() && e('0');
|
||||
Reference in New Issue
Block a user