chore(addon/huaweipay): 变更华为支付的测试方法内容

This commit is contained in:
2025-12-03 15:34:19 +08:00
parent ae5f56c16f
commit 98d2eb8a2a
6 changed files with 372 additions and 279 deletions

View File

@@ -16,6 +16,89 @@ class PayModelTest
* @var int
*/
protected $siteId = 1;
/**
* 测试配置数据
* @var array
*/
protected $configData;
/**
* 构造函数,加载配置文件
*/
public function __construct()
{
// 加载配置文件
$yamlPath = __DIR__ . '/mock/data.yml';
if (file_exists($yamlPath)) {
if (function_exists('yaml_parse_file')) {
$this->configData = yaml_parse_file($yamlPath);
} else {
// 如果没有yaml_parse_file函数手动解析
$this->configData = $this->parseYamlFile($yamlPath);
}
} else {
throw new Exception("配置文件不存在: {$yamlPath}");
}
}
/**
* 手动解析YAML文件
* @param string $filePath
* @return array
*/
private function parseYamlFile($filePath)
{
$content = file_get_contents($filePath);
$lines = explode("\n", $content);
$result = [];
$currentKey = '';
$isMultiline = false;
$multilineValue = '';
foreach ($lines as $line) {
$line = trim($line);
// 跳过注释和空行
if (empty($line) || strpos($line, '#') === 0) {
continue;
}
// 处理多行值
if ($isMultiline) {
if (strpos($line, '-----END') === 0) {
$multilineValue .= $line . "\n";
$result[$currentKey] = rtrim($multilineValue);
$isMultiline = false;
$multilineValue = '';
} else {
$multilineValue .= $line . "\n";
}
continue;
}
// 处理单行键值对
if (strpos($line, ':') !== false) {
list($key, $value) = explode(':', $line, 2);
$key = trim($key);
$value = trim($value);
// 处理多行值开始
if ($value === '|') {
$isMultiline = true;
$currentKey = $key;
continue;
}
// 处理普通值
if (!empty($value)) {
$result[$key] = $value;
}
}
}
return $result;
}
/**
* 运行所有测试
@@ -56,8 +139,8 @@ class PayModelTest
'out_trade_no' => 'test_order_' . time(),
'total_amount' => 100,
'subject' => '测试商品',
'notify_url' => 'https://example.com/notify',
'return_url' => 'https://example.com/return',
'notify_url' => $this->configData['notifyUrl'],
'return_url' => $this->configData['returnUrl'],
'buyer_id' => '1',
'type' => 'h5'
];
@@ -85,8 +168,8 @@ class PayModelTest
// 创建模拟通知数据
$notifyData = [
'app_id' => 'test_app_id',
'merc_no' => 'test_merc_no',
'app_id' => $this->configData['app_id'],
'merc_no' => $this->configData['mch_id'],
'order_id' => 'test_order_001',
'trade_status' => 'SUCCESS',
'sign' => 'mock_signature'
@@ -166,8 +249,12 @@ class PayModelTest
*/
private function mockConfig()
{
// 在实际测试中,可以使用更高级的模拟技术
// 这里仅提供基础框架
// 这里可以添加更高级的模拟技术例如使用PHPUnit的mock对象
// 目前我们只需要确保配置数据能正确加载
echo "\n使用配置数据:\n";
echo "App ID: {$this->configData['app_id']}\n";
echo "商户号: {$this->configData['mch_id']}\n";
echo "证书ID: {$this->configData['mch_auth_id']}\n";
}
}