diff --git a/module/testcase/model.php b/module/testcase/model.php index 3938169abc..9e5f9f2aa8 100644 --- a/module/testcase/model.php +++ b/module/testcase/model.php @@ -584,22 +584,29 @@ class testcaseModel extends model } /** + * 获取需求列表关联的用例数量数组。 * Get counts of some stories' cases. * * @param array $stories * @access public - * @return int + * @return array */ - public function getStoryCaseCounts($stories) + public function getStoryCaseCounts(array $stories): array { if(empty($stories)) return array(); + $caseCounts = $this->dao->select('story, COUNT(*) AS cases') ->from(TABLE_CASE) ->where('story')->in($stories) ->andWhere('deleted')->eq(0) ->groupBy('story') ->fetchPairs(); - foreach($stories as $storyID) if(!isset($caseCounts[$storyID])) $caseCounts[$storyID] = 0; + + foreach($stories as $storyID) + { + if(!isset($caseCounts[$storyID])) $caseCounts[$storyID] = 0; + } + return $caseCounts; } diff --git a/module/testcase/test/model/getstorycasecounts.php b/module/testcase/test/model/getstorycasecounts.php index c29ab599c0..615ce8a1c9 100755 --- a/module/testcase/test/model/getstorycasecounts.php +++ b/module/testcase/test/model/getstorycasecounts.php @@ -2,6 +2,10 @@ gen('20'); +zdTable('user')->gen('1'); + su('admin'); /** @@ -10,20 +14,14 @@ title=测试 testcaseModel->getStoryCaseCounts(); cid=1 pid=1 -测试获取需求 1 2 的测试用例个数 >> 0;8 -测试获取需求 3 4 的测试用例个数 >> 0;0 -测试获取需求 5 6 的测试用例个数 >> 0;8 -测试获取需求 7 8 的测试用例个数 >> 0;0 -测试获取需求 9 10 的测试用例个数 >> 0;6 - */ $stories = array(array('1' => 1, '2' => 2 ), array('3' => 3, '4' => 4 ), array('5' => 5, '6' => 6 ), array('7' => 7, '8' => 8 ), array('9' => 9, '10' => 10 )); $testcase = new testcaseTest(); -r($testcase->getStoryCaseCountsTest($stories[0])) && p('1;2') && e('0;8'); // 测试获取需求 1 2 的测试用例个数 +r($testcase->getStoryCaseCountsTest($stories[0])) && p('1;2') && e('0;4'); // 测试获取需求 1 2 的测试用例个数 r($testcase->getStoryCaseCountsTest($stories[1])) && p('3;4') && e('0;0'); // 测试获取需求 3 4 的测试用例个数 -r($testcase->getStoryCaseCountsTest($stories[2])) && p('5;6') && e('0;8'); // 测试获取需求 5 6 的测试用例个数 +r($testcase->getStoryCaseCountsTest($stories[2])) && p('5;6') && e('0;4'); // 测试获取需求 5 6 的测试用例个数 r($testcase->getStoryCaseCountsTest($stories[3])) && p('7;8') && e('0;0'); // 测试获取需求 7 8 的测试用例个数 -r($testcase->getStoryCaseCountsTest($stories[4])) && p('9;10') && e('0;6'); // 测试获取需求 9 10 的测试用例个数 \ No newline at end of file +r($testcase->getStoryCaseCountsTest($stories[4])) && p('9;10') && e('0;4'); // 测试获取需求 9 10 的测试用例个数 diff --git a/module/testcase/test/testcase.class.php b/module/testcase/test/testcase.class.php index 45c90bbdfc..604bce29f1 100644 --- a/module/testcase/test/testcase.class.php +++ b/module/testcase/test/testcase.class.php @@ -318,13 +318,14 @@ class testcaseTest } /** + * 测试获取需求列表关联的用例数量数组。 * Test get counts of some stories' cases. * * @param array $stories * @access public - * @return void + * @return array */ - public function getStoryCaseCountsTest($stories) + public function getStoryCaseCountsTest(array $stories): array { $counts = $this->objectModel->getStoryCaseCounts($stories);