znt/module/metric/test/model/getdao.php

52 lines
1.7 KiB
PHP
Executable file
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env php
<?php
/**
title=测试 metricModel::getDAO();
timeout=0
cid=17086
- 执行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/model.class.php';
// 2. 用户登录(选择合适角色)
su('admin');
// 3. 创建测试实例(变量名与模块名一致)
$metricTest = new metricModelTest();
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');