znt/module/pivot/test/model/getbyid.php

40 lines
1.5 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=测试 pivotModel::getByID();
timeout=0
cid=17373
- 步骤1正常情况-获取存在的透视表ID属性id @1001
- 步骤2正常情况-验证透视表分组属性group @85
- 步骤3获取另一个透视表并验证ID属性id @1003
- 步骤4边界值-不存在的ID返回false @0
- 步骤5异常输入-无效ID零返回false @0
*/
// 1. 导入依赖(路径固定,不可修改)
define('UNIT_TEST', true);
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/model.class.php';
// 2. 初始化pivot测试数据只加载pivot.sql
global $tester, $app;
$appPath = $app->getAppRoot();
$sqlFile = $appPath . 'test/data/pivot.sql';
$tester->dbh->exec(file_get_contents($sqlFile));
// 3. 用户登录(选择合适角色)
su('admin');
// 4. 创建测试实例(变量名与模块名一致)
$pivotTest = new pivotModelTest();
// 5. 🔴 强制要求必须包含至少5个测试步骤
r($pivotTest->getByIDTest(1001)) && p('id') && e('1001'); // 步骤1正常情况-获取存在的透视表ID
r($pivotTest->getByIDTest(1001)) && p('group') && e('85'); // 步骤2正常情况-验证透视表分组
r($pivotTest->getByIDTest(1003)) && p('id') && e('1003'); // 步骤3获取另一个透视表并验证ID
r($pivotTest->getByIDTest(9999)) && p('') && e('0'); // 步骤4边界值-不存在的ID返回false
r($pivotTest->getByIDTest(0)) && p('') && e('0'); // 步骤5异常输入-无效ID零返回false