+ [misc] Add unit tests for webhookTao::getWeixinSecret() 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:09:46 +08:00
co-authored by Claude
parent ef35543376
commit fbc3d3a204
3 changed files with 194 additions and 0 deletions
@@ -484,4 +484,23 @@ class webhookTest
return $result;
}
/**
* Test getWeixinSecret method.
*
* @param object $webhook
* @access public
* @return object|false
*/
public function getWeixinSecretTest($webhook)
{
$reflection = new ReflectionClass($this->objectTao);
$method = $reflection->getMethod('getWeixinSecret');
$method->setAccessible(true);
$result = $method->invoke($this->objectTao, $webhook);
if(dao::isError()) return dao::getError();
return $result;
}
}
+63
View File
@@ -0,0 +1,63 @@
#!/usr/bin/env php
<?php
/**
title=测试 webhookTao::getWeixinSecret();
timeout=0
cid=0
- 执行webhookTest模块的getWeixinSecretTest方法,参数是$normalWebhook 属性url @https://qyapi.weixin.qq.com/cgi-bin/
- 执行webhookTest模块的getWeixinSecretTest方法,参数是$missingCorpId 属性wechatCorpId @『企业ID』不能为空。
- 执行webhookTest模块的getWeixinSecretTest方法,参数是$missingCorpSecret 属性wechatCorpSecret @『应用的凭证密钥』不能为空。
- 执行webhookTest模块的getWeixinSecretTest方法,参数是$missingAgentId 属性wechatAgentId @『企业应用的ID』不能为空。
- 执行webhookTest模块的getWeixinSecretTest方法,参数是$emptyWebhook 属性wechatCorpId @『企业ID』不能为空。
*/
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/webhook.unittest.class.php';
su('admin');
$webhookTest = new webhookTest();
// 创建完整的正常webhook对象
$normalWebhook = new stdClass();
$normalWebhook->wechatCorpId = 'wxcorp123456789';
$normalWebhook->wechatCorpSecret = 'wechat_secret_123456789';
$normalWebhook->wechatAgentId = '1000001';
r($webhookTest->getWeixinSecretTest($normalWebhook)) && p('url') && e('https://qyapi.weixin.qq.com/cgi-bin/');
// 缺少企业ID
$missingCorpId = new stdClass();
$missingCorpId->wechatCorpId = '';
$missingCorpId->wechatCorpSecret = 'wechat_secret_123456789';
$missingCorpId->wechatAgentId = '1000001';
r($webhookTest->getWeixinSecretTest($missingCorpId)) && p('wechatCorpId') && e('『企业ID』不能为空。');
// 缺少企业秘钥
$missingCorpSecret = new stdClass();
$missingCorpSecret->wechatCorpId = 'wxcorp123456789';
$missingCorpSecret->wechatCorpSecret = '';
$missingCorpSecret->wechatAgentId = '1000001';
r($webhookTest->getWeixinSecretTest($missingCorpSecret)) && p('wechatCorpSecret') && e('『应用的凭证密钥』不能为空。');
// 缺少应用ID
$missingAgentId = new stdClass();
$missingAgentId->wechatCorpId = 'wxcorp123456789';
$missingAgentId->wechatCorpSecret = 'wechat_secret_123456789';
$missingAgentId->wechatAgentId = '';
r($webhookTest->getWeixinSecretTest($missingAgentId)) && p('wechatAgentId') && e('『企业应用的ID』不能为空。');
// 所有参数都为空
$emptyWebhook = new stdClass();
$emptyWebhook->wechatCorpId = '';
$emptyWebhook->wechatCorpSecret = '';
$emptyWebhook->wechatAgentId = '';
r($webhookTest->getWeixinSecretTest($emptyWebhook)) && p('wechatCorpId') && e('『企业ID』不能为空。');
@@ -0,0 +1,112 @@
---
title: webhook表数据定义
desc: 为getWeixinSecret方法测试准备webhook表数据
author: Claude
version: 1.0
fields:
- field: id
note: Webhook ID
range: 1-5
prefix: ""
postfix: ""
- field: type
note: Webhook类型
range: weixin{5}
format: ""
- field: name
note: Webhook名称
range: 微信测试{5}
format: ""
- field: url
note: Webhook URL地址
range: https://qyapi.weixin.qq.com/cgi-bin/webhook/send{5}
format: ""
- field: domain
note: 域名
range: qyapi.weixin.qq.com{5}
format: ""
- field: secret
note: 加密信息
range: '{}'{5}
format: ""
- field: contentType
note: 内容类型
range: application/json{5}
format: ""
- field: sendType
note: 发送类型
range: sync{3},async{2}
format: ""
- field: products
note: 产品列表
range: '[]'{5}
format: ""
- field: executions
note: 执行列表
range: '[]'{5}
format: ""
- field: params
note: 参数
range: wechatCorpId,wechatCorpSecret,wechatAgentId{5}
format: ""
- field: actions
note: 动作列表
range: 'all'{5}
format: ""
- field: desc
note: 描述
range: 微信Webhook测试{5}
format: ""
- field: createdBy
note: 创建者
range: admin{5}
format: ""
- field: createdDate
note: 创建时间
range: 2024-01-01 10:00:00{5}
format: ""
- field: editedBy
note: 编辑者
range: admin{3},user{2}
format: ""
- field: editedDate
note: 编辑时间
range: 2024-01-01 11:00:00{5}
format: ""
- field: deleted
note: 删除标记
range: '0'{5}
format: ""
- field: wechatCorpId
note: 微信企业ID
range: wxcorp123456789{3},wxcorp987654321{1},{}{1}
format: ""
- field: wechatCorpSecret
note: 微信企业秘钥
range: wechat_secret_123456789{3},wechat_secret_987654321{1},{}{1}
format: ""
- field: wechatAgentId
note: 微信应用ID
range: 1000001{3},1000002{1},{}{1}
format: ""