From 9779937c23ea44ee2f285190f7eb8cb545268d4c Mon Sep 17 00:00:00 2001 From: liumengyi Date: Mon, 5 Jun 2023 11:18:48 +0800 Subject: [PATCH] * Refactor bugModel-getReleaseBugs, and modify its unit test. --- module/bug/model.php | 17 +++++++++-------- module/bug/test/bug.class.php | 7 ++++--- module/bug/test/model/getreleasebugs.php | 18 +++++++----------- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/module/bug/model.php b/module/bug/model.php index 1b5152ca90..a700de8442 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -1159,17 +1159,18 @@ class bugModel extends model } /** + * 通过版本 id 和产品 id 获取 bugs。 * Get bugs according to buildID and productID. * - * @param int|string $buildIdList - * @param int $productID - * @param string $branch - * @param string $linkedBugs - * @param object $pager + * @param array $buildIdList + * @param int $productID + * @param string $branch + * @param string $linkedBugs + * @param object $pager * @access public * @return array */ - public function getReleaseBugs($buildIdList, $productID, $branch = 0, $linkedBugs = '', $pager = null) + public function getReleaseBugs(array $buildIdList, int $productID, int $branch = 0, string $linkedBugs = '', object $pager = null): array { $executionIdList = $this->getLinkedExecutionByIdList($buildIdList); if(empty($executionIdList)) return array(); @@ -1184,8 +1185,8 @@ class bugModel extends model } return $this->dao->select('*')->from(TABLE_BUG) - ->where('resolvedDate')->ge($minBegin) - ->andWhere('resolution')->ne('postponed') + ->where('resolution')->ne('postponed') + ->beginIF(!empty($minBegin))->andWhere('resolvedDate')->ge($minBegin)->fi() ->andWhere('product')->eq($productID) ->beginIF($linkedBugs)->andWhere('id')->notIN($linkedBugs)->fi() ->beginIF($branch)->andWhere('branch')->in("0,$branch")->fi() diff --git a/module/bug/test/bug.class.php b/module/bug/test/bug.class.php index bb6c799575..acd532c1b2 100644 --- a/module/bug/test/bug.class.php +++ b/module/bug/test/bug.class.php @@ -745,16 +745,17 @@ class bugTest } /** + * 测试通过版本 id 和产品 id 获取 bugs。 * Test get bugs according to buildID and productID. * * @param int $buildID * @param int $productID * @access public - * @return string + * @return string|array */ - public function getReleaseBugsTest($buildID, $productID) + public function getReleaseBugsTest(int $buildID, int $productID): string|array { - $array = $this->objectModel->getReleaseBugs($buildID, $productID); + $array = $this->objectModel->getReleaseBugs(array($buildID), $productID); $title = ''; foreach($array as $bug) $title .= ',' . $bug->title; diff --git a/module/bug/test/model/getreleasebugs.php b/module/bug/test/model/getreleasebugs.php index 4663dcfb1e..ae715df2e2 100755 --- a/module/bug/test/model/getreleasebugs.php +++ b/module/bug/test/model/getreleasebugs.php @@ -1,25 +1,21 @@ #!/usr/bin/env php gen(10); +zdTable('product')->gen(10); + /** title=bugModel->getReleaseBugs(); cid=1 pid=1 -测试获取buildID为11 productID为2的bug >> BUG4,BUG5,BUG6 -测试获取buildID为12 productID为2的bug >> 0 -测试获取buildID为13 productID为1的bug >> BUG1,BUG2,BUG3 -测试获取buildID为14 productID为2的bug >> BUG4,BUG5,BUG6 -测试获取buildID为15 productID为1的bug >> BUG1,BUG2,BUG3 -测试获取buildID为16 productID为2的bug >> BUG4,BUG5,BUG6 - */ -$buildIDList = array('11', '12', '13', '14', '15', '16'); -$productIDList = array('1', '2'); +$buildIDList = array(11, 12, 13, 14, 15, 16); +$productIDList = array(1, 2); $bug=new bugTest(); r($bug->getReleaseBugsTest($buildIDList[0], $productIDList[1])) && p('') && e('BUG4,BUG5,BUG6'); // 测试获取buildID为11 productID为2的bug @@ -27,4 +23,4 @@ r($bug->getReleaseBugsTest($buildIDList[1], $productIDList[1])) && p('') && e('0 r($bug->getReleaseBugsTest($buildIDList[2], $productIDList[0])) && p('') && e('BUG1,BUG2,BUG3'); // 测试获取buildID为13 productID为1的bug r($bug->getReleaseBugsTest($buildIDList[3], $productIDList[1])) && p('') && e('BUG4,BUG5,BUG6'); // 测试获取buildID为14 productID为2的bug r($bug->getReleaseBugsTest($buildIDList[4], $productIDList[0])) && p('') && e('BUG1,BUG2,BUG3'); // 测试获取buildID为15 productID为1的bug -r($bug->getReleaseBugsTest($buildIDList[5], $productIDList[1])) && p('') && e('BUG4,BUG5,BUG6'); // 测试获取buildID为16 productID为2的bug \ No newline at end of file +r($bug->getReleaseBugsTest($buildIDList[5], $productIDList[1])) && p('') && e('BUG4,BUG5,BUG6'); // 测试获取buildID为16 productID为2的bug