diff --git a/module/metric/test/lib/metric.unittest.class.php b/module/metric/test/lib/metric.unittest.class.php index 687f864849..46a6088ec3 100644 --- a/module/metric/test/lib/metric.unittest.class.php +++ b/module/metric/test/lib/metric.unittest.class.php @@ -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; + } } \ No newline at end of file diff --git a/module/metric/test/tao/fetchmetricrecords.php b/module/metric/test/tao/fetchmetricrecords.php new file mode 100755 index 0000000000..5ae393eeb0 --- /dev/null +++ b/module/metric/test/tao/fetchmetricrecords.php @@ -0,0 +1,32 @@ +#!/usr/bin/env php +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'); \ No newline at end of file