+ [misc] Add unit tests for metricModel::getDAO() 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:17 +08:00
co-authored by Claude
parent 0100adbb79
commit aaad7003df
2 changed files with 66 additions and 0 deletions
@@ -89,4 +89,18 @@ class metricTest
return $result;
}
/**
* Test getDAO method.
*
* @access public
* @return mixed
*/
public function getDAOTest()
{
$result = $this->objectModel->getDAO();
if(dao::isError()) return dao::getError();
return $result;
}
}
+52
View File
@@ -0,0 +1,52 @@
#!/usr/bin/env php
<?php
/**
title=测试 metricModel::getDAO();
timeout=0
cid=0
- 执行metricTest模块的getDAOTest方法 属性driver @mysql
- 执行metricTest模块的getDAOTest方法 属性driver @mysql
- 执行metricTest模块的getDAOTest方法 属性driver @mysql
- 执行metricTest模块的getDAOTest方法 属性driver @mysql
- 执行metricTest模块的getDAOTest方法 属性driver @mysql
*/
// 1. 导入依赖(路径固定,不可修改)
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/metric.unittest.class.php';
// 2. 用户登录(选择合适角色)
su('admin');
// 3. 创建测试实例(变量名与模块名一致)
$metricTest = new metricTest();
global $config;
$originalType = isset($config->metricDB->type) ? $config->metricDB->type : 'mysql';
// 4. 🔴 强制要求:必须包含至少5个测试步骤
// 步骤1:正常情况获取DAO对象
r($metricTest->getDAOTest()) && p('driver') && e('mysql');
// 步骤2:设置为mysql类型测试
if(!isset($config->metricDB)) $config->metricDB = new stdClass();
$config->metricDB->type = 'mysql';
r($metricTest->getDAOTest()) && p('driver') && e('mysql');
// 步骤3:测试默认情况返回原始dao
$config->metricDB->type = 'other';
r($metricTest->getDAOTest()) && p('driver') && e('mysql');
// 步骤4:测试配置为空字符串时的默认行为
$config->metricDB = new stdClass();
$config->metricDB->type = '';
r($metricTest->getDAOTest()) && p('driver') && e('mysql');
// 步骤5:恢复原始配置并再次测试
$config->metricDB = new stdClass();
$config->metricDB->type = $originalType;
r($metricTest->getDAOTest()) && p('driver') && e('mysql');