+ [misc] Add unit tests for adminZen::sendCodeByAPI() method
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -343,4 +343,31 @@ class adminTest
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test sendCodeByAPI method.
|
||||
*
|
||||
* @param string $type
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function sendCodeByAPITest(string $type = 'mobile')
|
||||
{
|
||||
// 为adminZen对象设置必要的属性
|
||||
$this->objectZen->admin = $this->objectModel;
|
||||
|
||||
$reflection = new ReflectionClass($this->objectZen);
|
||||
$method = $reflection->getMethod('sendCodeByAPI');
|
||||
$method->setAccessible(true);
|
||||
|
||||
// 使用try-catch来捕获可能的网络错误
|
||||
try {
|
||||
$result = $method->invoke($this->objectZen, $type);
|
||||
if(dao::isError()) return dao::getError();
|
||||
return is_string($result) ? (strlen($result) > 0 ? '1' : '0') : '0';
|
||||
} catch (Exception $e) {
|
||||
// 网络请求失败时返回特定标识
|
||||
return '0';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/**
|
||||
|
||||
title=测试 adminZen::sendCodeByAPI();
|
||||
timeout=0
|
||||
cid=0
|
||||
|
||||
- 步骤1:mobile类型 @1
|
||||
- 步骤2:email类型 @1
|
||||
- 步骤3:空字符串 @1
|
||||
- 步骤4:无效类型 @1
|
||||
- 步骤5:sms类型 @1
|
||||
|
||||
*/
|
||||
|
||||
// 1. 导入依赖(路径固定,不可修改)
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/admin.unittest.class.php';
|
||||
|
||||
// 2. 用户登录(选择合适角色)
|
||||
su('admin');
|
||||
|
||||
// 3. 创建测试实例(变量名与模块名一致)
|
||||
$adminTest = new adminTest();
|
||||
|
||||
// 4. 🔴 强制要求:必须包含至少5个测试步骤
|
||||
r($adminTest->sendCodeByAPITest('mobile')) && p() && e('1'); // 步骤1:mobile类型
|
||||
r($adminTest->sendCodeByAPITest('email')) && p() && e('1'); // 步骤2:email类型
|
||||
r($adminTest->sendCodeByAPITest('')) && p() && e('1'); // 步骤3:空字符串
|
||||
r($adminTest->sendCodeByAPITest('invalid')) && p() && e('1'); // 步骤4:无效类型
|
||||
r($adminTest->sendCodeByAPITest('sms')) && p() && e('1'); // 步骤5:sms类型
|
||||
Reference in New Issue
Block a user