+ [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:
@@ -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;
|
||||
}
|
||||
}
|
||||
Executable
+52
@@ -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');
|
||||
Reference in New Issue
Block a user