From f9a09e40cc774404004ccd9799e3a0e4fa99444b Mon Sep 17 00:00:00 2001 From: songchenxuan Date: Mon, 18 Dec 2023 13:53:19 +0800 Subject: [PATCH] * Add metric test. --- module/metric/test/calc.class.php | 50 +++++++++++++++++-- .../metric/test/model/getmetricsbyidlist.php | 18 +++++++ .../metric/test/model/groupmetricbyobject.php | 24 +++++++++ 3 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 module/metric/test/model/getmetricsbyidlist.php create mode 100644 module/metric/test/model/groupmetricbyobject.php diff --git a/module/metric/test/calc.class.php b/module/metric/test/calc.class.php index 8d723d1473..4798fcec3c 100644 --- a/module/metric/test/calc.class.php +++ b/module/metric/test/calc.class.php @@ -25,7 +25,7 @@ class metricTest } /** - * 测试getByID方法。 + * 测试 getByID 方法。 * Test getByID method. * * @param int $metricID @@ -39,8 +39,21 @@ class metricTest } /** - * 测试getByID方法。 - * Test getByID method. + * 测试 getMetricsByIDList 方法。 + * Test getMetricsByIDList method. + * + * @param array|string $idList + * @access public + * @return array + */ + public function getMetricsByIDList($idList) + { + return $this->objectModel->getMetricsByIDList($idList); + } + + /** + * 测试 getByCode 方法。 + * Test getByCode method. * * @param string $code * @param array|string $fieldList @@ -53,7 +66,7 @@ class metricTest } /** - * 测试getByList方法。 + * 测试 getByList 方法。 * Test getByList method. * * @param string $scope @@ -69,7 +82,7 @@ class metricTest } /** - * 测试getScopePairs方法。 + * 测试 getScopePairs 方法。 * Test getScopePairs method. * * @param bool $all @@ -81,6 +94,33 @@ class metricTest return $this->objectModel->getScopePairs($all); } + /** + * 测试 groupMetricByObject 方法。 + * Test groupMetricByObject method. + * + * @param array $metrics + * @param bool $isObject true|false 去对象|计数 + * @param array $params array('group' => '', 'key' => '') + * @access public + * @return array + */ + public function groupMetricByObject($metrics, $isObject = true, $params = array('group' => 'program', 'key' => 1)) + { + $groupedMetrics = $this->objectModel->groupMetricByObject($metrics); + + if(!isset($params['group']) or !isset($groupedMetrics[$params['group']])) return false; + + $groupMetric = $groupedMetrics[$params['group']]; + if($isObject) + { + return (!isset($params['key']) or !isset($groupMetric[$params['key']])) ? false : $groupMetric[$params['key']]; + } + else + { + return array('count' => count($groupMetric)); + } + } + /** * 测试根据code获取度量项数据方法。 * Test get metric by code. diff --git a/module/metric/test/model/getmetricsbyidlist.php b/module/metric/test/model/getmetricsbyidlist.php new file mode 100644 index 0000000000..fa3ec44049 --- /dev/null +++ b/module/metric/test/model/getmetricsbyidlist.php @@ -0,0 +1,18 @@ +#!/usr/bin/env php +getMetricsByIDList('1,2')) && p('1:code') && e('count_of_doing_program'); // 使用字符串传入获取metric +r($metric->getMetricsByIDList(array(1,2))) && p('0:code') && e('count_of_program'); // 使用数组传入获取metric +r($metric->getMetricsByIDList('')) && p() && e('0'); // 传入一个空字符串没有metric返回 diff --git a/module/metric/test/model/groupmetricbyobject.php b/module/metric/test/model/groupmetricbyobject.php new file mode 100644 index 0000000000..5ce1e8e2f2 --- /dev/null +++ b/module/metric/test/model/groupmetricbyobject.php @@ -0,0 +1,24 @@ +#!/usr/bin/env php +getList('system', 'all'); + +r($metric->groupMetricByObject($systemMetrics, true, array('group' => 'doc', 'key' => 0))) && p('code') && e('count_of_annual_created_doc'); // 获取系统度量项文档分组的第3个度量的code +r($metric->groupMetricByObject($systemMetrics, true, array('group' => 'doc', 'key' => 2))) && p('code') && e('0'); // 获取系统度量项文档分组的第3个度量的code +r($metric->groupMetricByObject($systemMetrics, true, array('group' => 'docc', 'key' => 0))) && p('code') && e('0'); // 获取系统度量项docc分组的第一个度量的code +r($metric->groupMetricByObject($systemMetrics, false, array('group' => 'doc'))) && p('count') && e(2); // 获取系统度量项文档分组的求和 +r($metric->groupMetricByObject($systemMetrics, false, array('group' => 'product'))) && p('count') && e(5); // 获取系统度量项产品分组的求和 +r($metric->groupMetricByObject($systemMetrics, false, array('group' => 'project'))) && p('count') && e(22); // 获取系统度量项项目分组的求和 +r($metric->groupMetricByObject($systemMetrics, false, array('group' => 'projectt'))) && p('count') && e(0); // 获取系统度量项projectt分组的求和