+ [misc] Add unit tests for todoZen::getUserById() method
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@ class todoTest
|
||||
public function __construct()
|
||||
{
|
||||
$this->objectZen = initReference('todo');
|
||||
$this->todoZen = new todoZen();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1707,4 +1708,21 @@ class todoTest
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getUserById method.
|
||||
*
|
||||
* @param int $userID
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function getUserByIdTest(int $userID)
|
||||
{
|
||||
$method = $this->objectZen->getMethod('getUserById');
|
||||
$method->setAccessible(true);
|
||||
$result = $method->invoke($this->todoZen, $userID);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
Executable
+44
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/**
|
||||
|
||||
title=测试 todoZen::getUserById();
|
||||
timeout=0
|
||||
cid=0
|
||||
|
||||
- 步骤1:正常用户查询属性account @admin
|
||||
- 步骤2:边界值ID查询(ID为0) @0
|
||||
- 步骤3:负数ID查询 @0
|
||||
- 步骤4:不存在用户ID查询 @0
|
||||
- 步骤5:超大ID查询 @0
|
||||
|
||||
*/
|
||||
|
||||
// 1. 导入依赖(路径固定,不可修改)
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/todozen.unittest.class.php';
|
||||
|
||||
// 2. zendata数据准备(根据需要配置)
|
||||
$userTable = zenData('user');
|
||||
$userTable->id->range('1-10');
|
||||
$userTable->account->range('admin,user1,user2,user3,user4,user5,user6,user7,user8,user9');
|
||||
$userTable->password->range('123456{10}');
|
||||
$userTable->realname->range('管理员,用户1,用户2,用户3,用户4,用户5,用户6,用户7,用户8,用户9');
|
||||
$userTable->role->range('admin,dev,qa,pm,td,po,rd,ue,ui,user');
|
||||
$userTable->email->range('admin@test.com,user1@test.com,user2@test.com,user3@test.com,user4@test.com,user5@test.com,user6@test.com,user7@test.com,user8@test.com,user9@test.com');
|
||||
$userTable->deleted->range('0{9},1');
|
||||
$userTable->gen(10);
|
||||
|
||||
// 3. 用户登录(选择合适角色)
|
||||
su('admin');
|
||||
|
||||
// 4. 创建测试实例(变量名与模块名一致)
|
||||
$todoTest = new todoTest();
|
||||
|
||||
// 5. 强制要求:必须包含至少5个测试步骤
|
||||
r($todoTest->getUserByIdTest(1)) && p('account') && e('admin'); // 步骤1:正常用户查询
|
||||
r($todoTest->getUserByIdTest(0)) && p() && e('0'); // 步骤2:边界值ID查询(ID为0)
|
||||
r($todoTest->getUserByIdTest(-1)) && p() && e('0'); // 步骤3:负数ID查询
|
||||
r($todoTest->getUserByIdTest(999)) && p() && e('0'); // 步骤4:不存在用户ID查询
|
||||
r($todoTest->getUserByIdTest(9999)) && p() && e('0'); // 步骤5:超大ID查询
|
||||
@@ -0,0 +1,66 @@
|
||||
---
|
||||
title: getUserById方法测试数据
|
||||
desc: 用于测试todoZen::getUserById()方法的用户数据
|
||||
author: Claude
|
||||
version: 1.0
|
||||
|
||||
fields:
|
||||
- field: id
|
||||
note: 用户ID
|
||||
range: 1-10
|
||||
prefix: ""
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: account
|
||||
note: 用户账号
|
||||
range: admin,user1,user2,user3,user4,user5,user6,user7,user8,user9
|
||||
format: ""
|
||||
- field: password
|
||||
note: 用户密码
|
||||
range: 123456{10}
|
||||
format: ""
|
||||
- field: realname
|
||||
note: 真实姓名
|
||||
range: 管理员,用户1,用户2,用户3,用户4,用户5,用户6,用户7,用户8,用户9
|
||||
format: ""
|
||||
- field: role
|
||||
note: 用户角色
|
||||
range: admin,dev,qa,pm,td,po,rd,ue,ui,user
|
||||
format: ""
|
||||
- field: email
|
||||
note: 邮箱地址
|
||||
range: admin@test.com,user1@test.com,user2@test.com,user3@test.com,user4@test.com,user5@test.com,user6@test.com,user7@test.com,user8@test.com,user9@test.com
|
||||
format: ""
|
||||
- field: company
|
||||
note: 所属公司
|
||||
range: 1{10}
|
||||
format: ""
|
||||
- field: dept
|
||||
note: 所属部门
|
||||
range: 1-5
|
||||
format: ""
|
||||
- field: type
|
||||
note: 用户类型
|
||||
range: inside{10}
|
||||
format: ""
|
||||
- field: gender
|
||||
note: 性别
|
||||
range: '[f,m]'
|
||||
format: ""
|
||||
- field: deleted
|
||||
note: 删除状态
|
||||
range: 0{9},1
|
||||
format: ""
|
||||
- field: visions
|
||||
note: 产品视图
|
||||
range: rnd,lite{9}
|
||||
format: ""
|
||||
- field: last
|
||||
note: 最后登录时间
|
||||
range: 1000000000-1700000000
|
||||
format: ""
|
||||
- field: visits
|
||||
note: 访问次数
|
||||
range: 0-1000
|
||||
format: ""
|
||||
Reference in New Issue
Block a user