From 87afc0cfc996ff0e062f89614a05dc3a42264c85 Mon Sep 17 00:00:00 2001 From: daitingting Date: Wed, 13 Sep 2023 01:04:37 +0000 Subject: [PATCH] * Refactor getByProduct function. --- module/testcase/model.php | 8 ++--- module/testcase/test/model/getbyproduct.php | 36 +++++++++++++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) create mode 100755 module/testcase/test/model/getbyproduct.php diff --git a/module/testcase/model.php b/module/testcase/model.php index 11351ba3f1..061358bc90 100644 --- a/module/testcase/model.php +++ b/module/testcase/model.php @@ -415,18 +415,16 @@ class testcaseModel extends model } /** + * 根据产品获取用例。 * Get cases by product id. * * @param int $productID * @access public * @return array */ - public function getByProduct($productID) + public function getByProduct(int $productID): array { - return $this->dao->select('*')->from(TABLE_CASE) - ->where('deleted')->eq(0) - ->andWhere('product')->eq($productID) - ->fetchAll('id'); + return $this->dao->select('*')->from(TABLE_CASE)->where('deleted')->eq('0')->andWhere('product')->eq($productID)->fetchAll('id'); } /** diff --git a/module/testcase/test/model/getbyproduct.php b/module/testcase/test/model/getbyproduct.php new file mode 100755 index 0000000000..e7e203b242 --- /dev/null +++ b/module/testcase/test/model/getbyproduct.php @@ -0,0 +1,36 @@ +#!/usr/bin/env php +product->range('1{6},2{4}'); + + $caseData->gen(10); +} + +initData(); + +/** + +title=测试 testcaseModel->getBySuite(); +timeout=0 +cid=1 + +- 产品1用例有6个 @6 +- 产品2的用例有4个 @4 + +*/ + +$productIDList = array(1, 2); +$branch = 0; +$suiteIDList = array('1', '2', '3', '4'); + +global $tester; +$tester->loadModel('testcase'); + +r(count($tester->testcase->getByProduct($productIDList[0]))) && p() && e(6); // 产品1的用例有6个 +r(count($tester->testcase->getByProduct($productIDList[1]))) && p() && e(4); // 产品2的用例有4个