+ [misc] Add unit tests for commonModel::printDuration() method

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
liugang
2025-09-15 15:06:13 +08:00
co-authored by Claude
parent 49b34223a0
commit f4cb6e4098
2 changed files with 49 additions and 0 deletions
@@ -1366,4 +1366,20 @@ class commonTest
return array();
}
}
/**
* Test printDuration method.
*
* @param int $seconds
* @param string $format
* @access public
* @return string
*/
public function printDurationTest(int $seconds, string $format = 'y-m-d-h-i-s'): string
{
$result = commonModel::printDuration($seconds, $format);
if(dao::isError()) return dao::getError();
return $result;
}
}
+33
View File
@@ -0,0 +1,33 @@
#!/usr/bin/env php
<?php
/**
title=测试 commonModel::printDuration();
timeout=0
cid=0
- 步骤1:标准完整时间格式 @1年2月3天4小时5分6秒
- 步骤2:小时分钟秒格式 @1小时1分1秒
- 步骤3:仅显示天数格式 @1天
- 步骤4:零秒输入测试 @
- 步骤5:大数值多年测试 @2年
*/
// 1. 导入依赖(路径固定,不可修改)
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/common.unittest.class.php';
// 2. 用户登录(选择合适角色)
su('admin');
// 3. 创建测试实例(变量名与模块名一致)
$commonTest = new commonTest();
// 4. 强制要求:必须包含至少5个测试步骤
r($commonTest->printDurationTest(36993906, 'y-m-d-h-i-s')) && p() && e('1年2月3天4小时5分6秒'); // 步骤1:标准完整时间格式
r($commonTest->printDurationTest(3661, 'h-i-s')) && p() && e('1小时1分1秒'); // 步骤2:小时分钟秒格式
r($commonTest->printDurationTest(86400, 'd')) && p() && e('1天'); // 步骤3:仅显示天数格式
r($commonTest->printDurationTest(0, 'y-m-d-h-i-s')) && p() && e(''); // 步骤4:零秒输入测试
r($commonTest->printDurationTest(63072000, 'y-m')) && p() && e('2年'); // 步骤5:大数值多年测试