#!/usr/bin/env php loadYaml('metric_getviewtabledata', false, 2)->gen(5); zenData('product')->loadYaml('product_getviewtabledata', false, 2)->gen(3); su('admin'); $metricTest = new metricModelTest(); // 构造测试用的metric对象 $systemMetric = new stdclass(); $systemMetric->scope = 'system'; $systemMetric->code = 'test_system'; $productMetric = new stdclass(); $productMetric->scope = 'product'; $productMetric->code = 'test_product'; // 测试步骤1:正常输入情况 - 系统范围数据 $systemResult = array( (object)array('date' => '2024-01-01', 'value' => '100', 'calcType' => 'cron', 'calculatedBy' => 'system', 'year' => '2024', 'month' => '01', 'day' => '01') ); r($metricTest->getViewTableDataTest($systemMetric, $systemResult)) && p('0:value,calcType') && e('100,cron'); // 测试步骤2:正常输入情况 - 产品范围数据 $productResult = array( (object)array('date' => '2024-01-01', 'product' => 1, 'value' => '200', 'calcType' => 'cron', 'calculatedBy' => 'system', 'year' => '2024', 'month' => '01', 'day' => '01') ); r($metricTest->getViewTableDataTest($productMetric, $productResult)) && p('0:scopeID,value') && e('1,200'); // 测试步骤3:边界值输入 - 空结果数组 r($metricTest->getViewTableDataTest($systemMetric, array())) && p() && e('0'); // 测试步骤4:异常输入情况 - 无效日期数据 $invalidResult = array( (object)array('value' => '300', 'calcType' => 'inference', 'calculatedBy' => 'manual', 'year' => '', 'month' => '', 'day' => '') ); r($metricTest->getViewTableDataTest($systemMetric, $invalidResult)) && p('0:value,calcType') && e('300,inference'); // 测试步骤5:数值处理验证 - 浮点数值四舍五入 $floatResult = array( (object)array('date' => '2024-01-01', 'value' => '123.456789', 'calcType' => 'cron', 'calculatedBy' => 'system', 'year' => '2024', 'month' => '01', 'day' => '01') ); r($metricTest->getViewTableDataTest($systemMetric, $floatResult)) && p('0:value') && e('123.46');