* Refactor testcaseModel::getStoryCaseCount, and modify its unit test.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/testcase.class.php';
|
||||
|
||||
zdTable('case')->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 的测试用例个数
|
||||
r($testcase->getStoryCaseCountsTest($stories[4])) && p('9;10') && e('0;4'); // 测试获取需求 9 10 的测试用例个数
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user