From ab17fba4bdfd64f7286540110caa01fa265e08b4 Mon Sep 17 00:00:00 2001 From: liumengyi Date: Fri, 1 Dec 2023 14:21:57 +0800 Subject: [PATCH] * Refactor reportModel::getStatusOverview, and modify its unit test. --- module/report/model.php | 9 +++++---- module/report/test/model/getstatusoverview.php | 6 +++++- module/report/test/report.class.php | 13 +++++++------ 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/module/report/model.php b/module/report/model.php index 12495d9fcf..a5b829a9f3 100644 --- a/module/report/model.php +++ b/module/report/model.php @@ -530,6 +530,7 @@ class reportModel extends model } /** + * 获取状态总览。 * Get status overview. * * @param string $objectType @@ -537,16 +538,16 @@ class reportModel extends model * @access public * @return string */ - public function getStatusOverview($objectType, $statusStat) + public function getStatusOverview(string $objectType, array $statusStat): string { $allCount = 0; $undoneCount = 0; foreach($statusStat as $status => $count) { $allCount += $count; - if($objectType == 'story' and $status != 'closed') $undoneCount += $count; - if($objectType == 'task' and $status != 'done' and $status != 'closed' and $status != 'cancel') $undoneCount += $count; - if($objectType == 'bug' and $status == 'active') $undoneCount += $count; + if($objectType == 'story' && $status != 'closed') $undoneCount += $count; + if($objectType == 'task' && $status != 'done' && $status != 'closed' && $status != 'cancel') $undoneCount += $count; + if($objectType == 'bug' && $status == 'active') $undoneCount += $count; } $overview = ''; diff --git a/module/report/test/model/getstatusoverview.php b/module/report/test/model/getstatusoverview.php index 3c8ec14029..d14a674b1f 100755 --- a/module/report/test/model/getstatusoverview.php +++ b/module/report/test/model/getstatusoverview.php @@ -1,7 +1,11 @@ #!/usr/bin/env php gen(1); + su('admin'); /** @@ -22,4 +26,4 @@ $report = new reportTest(); r($report->getStatusOverviewTest($objectType[0], $statusStat)) && p() && e('总需求   21
未完成   16'); // 测试获取 story 状态数量 r($report->getStatusOverviewTest($objectType[1], $statusStat)) && p() && e('总任务   21
未完成   6'); // 测试获取 task 状态数量 -r($report->getStatusOverviewTest($objectType[2], $statusStat)) && p() && e('总Bug   21
未解决   1'); // 测试获取 bug 状态数量 \ No newline at end of file +r($report->getStatusOverviewTest($objectType[2], $statusStat)) && p() && e('总Bug   21
未解决   1'); // 测试获取 bug 状态数量 diff --git a/module/report/test/report.class.php b/module/report/test/report.class.php index ce1beb097e..6f930130e2 100644 --- a/module/report/test/report.class.php +++ b/module/report/test/report.class.php @@ -508,20 +508,21 @@ class reportTest } /** + * 测试获取状态总览。 * Test get status overview. * - * @param string $objectType - * @param array $statusStat + * @param string $objectType + * @param array $statusStat * @access public - * @return string + * @return string|array */ - public function getStatusOverviewTest($objectType, $statusStat) + public function getStatusOverviewTest(string $objectType, array $statusStat): string|array { - $object = $this->objectModel->getStatusOverview($objectType, $statusStat); + $return = $this->objectModel->getStatusOverview($objectType, $statusStat); if(dao::isError()) return dao::getError(); - return $object; + return $return; } /**