* [misc] Enhance unit tests for todoTao::getListBy() method
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -653,4 +653,30 @@ class todoTest
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getListBy method.
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $account
|
||||
* @param string|array $status
|
||||
* @param string $begin
|
||||
* @param string $end
|
||||
* @param int $limit
|
||||
* @param string $orderBy
|
||||
* @param object $pager
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getListByTest(string $type, string $account, array|string $status, string $begin, string $end, int $limit, string $orderBy, ?object $pager = null): array
|
||||
{
|
||||
$reflection = new ReflectionClass($this->objectTao);
|
||||
$method = $reflection->getMethod('getListBy');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($this->objectTao, $type, $account, $status, $begin, $end, $limit, $orderBy, $pager);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
Regular → Executable
+28
-20
@@ -1,32 +1,40 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
include dirname(__FILE__, 5). '/test/lib/init.php';
|
||||
su('admin');
|
||||
|
||||
zenData('todo')->loadYaml('getlistby')->gen(5);
|
||||
|
||||
/**
|
||||
|
||||
title=测试 todoModel->getListBy();
|
||||
cid=1
|
||||
pid=0
|
||||
title=测试 todoTao::getListBy();
|
||||
timeout=0
|
||||
cid=0
|
||||
|
||||
- 步骤1:正常获取today类型待办列表 @1
|
||||
- 步骤2:获取指派给其他人的待办 @0
|
||||
- 步骤3:获取user1的待办 @1
|
||||
- 步骤4:按日期范围获取待办 @1
|
||||
- 步骤5:获取未完成状态待办 @1
|
||||
- 步骤6:限制返回数量为1 @1
|
||||
- 步骤7:测试其他用户的待办列表 @1
|
||||
|
||||
*/
|
||||
|
||||
global $tester;
|
||||
$tester->loadModel('todo')->todoTao;
|
||||
// 1. 导入依赖
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/todo.unittest.class.php';
|
||||
|
||||
// 2. zendata数据准备
|
||||
zenData('todo')->loadYaml('todo', false, 2)->gen(10);
|
||||
|
||||
$type = 'before'; // assignedtoother, cycle
|
||||
$account = 'admin';
|
||||
$status = 'all'; // done,closed,wait,doing
|
||||
$begin = '2021-02-03';
|
||||
$end = '2024-04-04';
|
||||
$limit = 5;
|
||||
$orderBy = 'date_desc';
|
||||
// 3. 用户登录
|
||||
su('admin');
|
||||
|
||||
$result = $tester->todo->getListBy($type, $account, $status, $begin, $end, $limit, $orderBy);
|
||||
// 4. 创建测试实例
|
||||
$todoTest = new todoTest();
|
||||
|
||||
r(count($result)) && p() && e('5'); //获取待办列表数量
|
||||
r($result[0]) && p('name,status') && e('待办5,doing'); //获取待办列表第1条的name和status
|
||||
// 5. 测试步骤
|
||||
r(count($todoTest->getListByTest('today', 'admin', 'all', '2025-08-24', '2025-08-24', 0, 'date_desc'))) && p() && e('1'); // 步骤1:正常获取today类型待办列表
|
||||
r(count($todoTest->getListByTest('assignedtoother', 'admin', 'all', '', '', 0, 'date_desc'))) && p() && e('0'); // 步骤2:获取指派给其他人的待办
|
||||
r(count($todoTest->getListByTest('today', 'user1', 'all', '2025-08-25', '2025-08-25', 0, 'date_desc'))) && p() && e('1'); // 步骤3:获取user1的待办
|
||||
r(count($todoTest->getListByTest('today', 'admin', 'all', '2025-08-01', '2025-09-30', 0, 'date_desc'))) && p() && e('1'); // 步骤4:按日期范围获取待办
|
||||
r(count($todoTest->getListByTest('today', 'user1', 'undone', '2025-08-25', '2025-08-25', 0, 'date_desc'))) && p() && e('1'); // 步骤5:获取未完成状态待办
|
||||
r(count($todoTest->getListByTest('today', 'admin', 'all', '2025-08-01', '2025-09-30', 1, 'date_desc'))) && p() && e('1'); // 步骤6:限制返回数量为1
|
||||
r(count($todoTest->getListByTest('today', 'user2', 'all', '2025-08-26', '2025-08-26', 0, 'id_asc'))) && p() && e('1'); // 步骤7:测试其他用户的待办列表
|
||||
Reference in New Issue
Block a user