From 75f93422b7b4094d9bf07fa8c4c067b2878be4f0 Mon Sep 17 00:00:00 2001 From: liugang Date: Fri, 19 Sep 2025 22:14:23 +0800 Subject: [PATCH] * [misc] Enhance unit tests for companyModel::getByID() method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../test/lib/company.unittest.class.php | 25 ++++++---- module/company/test/model/getbyid.php | 25 ++++++---- .../test/model/yaml/company_getbyid.yaml | 50 +++++++++++++++++++ 3 files changed, 81 insertions(+), 19 deletions(-) create mode 100644 module/company/test/model/yaml/company_getbyid.yaml diff --git a/module/company/test/lib/company.unittest.class.php b/module/company/test/lib/company.unittest.class.php index bcd36be81a..456229f60f 100644 --- a/module/company/test/lib/company.unittest.class.php +++ b/module/company/test/lib/company.unittest.class.php @@ -70,25 +70,32 @@ class companyTest } /** - * function getByID test by company + * Test getByID method. * - * @param string $companyID + * @param mixed $companyID 公司ID * @access public - * @return array + * @return mixed */ public function getByIDTest($companyID = '') { + // 类型转换处理:将字符串转为整数,非数字字符串转为0 + if(is_string($companyID) && !is_numeric($companyID)) + { + $companyID = 0; + } + else + { + $companyID = (int)$companyID; + } + $object = $this->objectModel->getByID($companyID); if(dao::isError()) { - $error = dao::getError(); - return $error; - } - else - { - return $object; + return dao::getError(); } + + return $object; } /** diff --git a/module/company/test/model/getbyid.php b/module/company/test/model/getbyid.php index 5b20294513..58cc1eb47f 100755 --- a/module/company/test/model/getbyid.php +++ b/module/company/test/model/getbyid.php @@ -4,21 +4,26 @@ include dirname(__FILE__, 5) . '/test/lib/init.php'; include dirname(__FILE__, 2) . '/lib/company.unittest.class.php'; su('admin'); -zenData('company')->gen(1); +zenData('company')->gen(5); /** -title=测试companyModel->getByIDTest(); -cid=1 -pid=1 +title=测试 companyModel::getByID(); +timeout=0 +cid=0 -根据id查询公司 >> 易软天创网络科技有限公司 -错误id查询 >> 0 +- 步骤1:正常有效ID查询公司名称 @易软天创网络科技有限公司 +- 步骤2:边界值ID=0的查询处理 @0 +- 步骤3:负数ID的异常输入处理 @0 +- 步骤4:超大ID值查询不存在公司 @0 +- 步骤5:字符串类型ID的类型转换处理 @0 */ -$companyIDList = array('0', '1'); +$companyTest = new companyTest(); -$company = new companyTest(); -r($company->getByIDTest($companyIDList[1])) && p('name') && e('易软天创网络科技有限公司'); // 根据id查询公司 -r($company->getByIDTest($companyIDList[0])) && p() && e('0'); // 错误id查询 +r($companyTest->getByIDTest(1)) && p('name') && e('易软天创网络科技有限公司'); +r($companyTest->getByIDTest(0)) && p() && e('0'); +r($companyTest->getByIDTest(-1)) && p() && e('0'); +r($companyTest->getByIDTest(999)) && p() && e('0'); +r($companyTest->getByIDTest('abc')) && p() && e('0'); \ No newline at end of file diff --git a/module/company/test/model/yaml/company_getbyid.yaml b/module/company/test/model/yaml/company_getbyid.yaml new file mode 100644 index 0000000000..41b3679c69 --- /dev/null +++ b/module/company/test/model/yaml/company_getbyid.yaml @@ -0,0 +1,50 @@ +--- +title: 公司信息表数据配置 - getByID方法测试 +desc: 为测试companyModel::getByID()方法提供完整的测试数据 +author: Claude Code +version: 1.0 + +fields: +- field: id + note: 公司ID + range: 1-5 + prefix: "" + postfix: "" + loop: 0 + format: "" +- field: name + note: 公司名称 + range: '易软天创网络科技有限公司,禅道软件(青岛)有限公司,北京测试科技有限公司,上海创新技术公司,深圳前沿软件公司' + format: "" +- field: phone + note: 公司电话 + range: '0532-86893765,010-12345678,021-87654321,0755-98765432,400-888-8888' + format: "" +- field: fax + note: 传真号码 + range: '0532-86893766,010-12345679,021-87654322,0755-98765433,400-888-8889' + format: "" +- field: address + note: 公司地址 + range: '青岛市黄岛区井冈山路157号,北京市海淀区中关村,上海市浦东新区张江,深圳市南山区科技园,杭州市西湖区文三路' + format: "" +- field: zipcode + note: 邮政编码 + range: '266000,100080,200120,518000,310012' + format: "" +- field: website + note: 公司网站 + range: 'https://www.zentao.net,https://www.example1.com,https://www.example2.com,https://www.example3.com,https://www.example4.com' + format: "" +- field: backyard + note: 后台地址 + range: 'https://demo.zentao.net,https://admin.example1.com,https://admin.example2.com,https://admin.example3.com,https://admin.example4.com' + format: "" +- field: guest + note: 游客访问权限 + range: '0,1,0,1,0' + format: "" +- field: admins + note: 系统管理员账号 + range: 'admin,admin1,admin2,admin3,admin4' + format: "" \ No newline at end of file