WeChatDeveloper/tests/ConfigInterfaceTest.php
Anyon 27c6d03cbd test: 迁移测试目录并补充协议层用例
- 将 src/Tests 迁移到根目录 tests,并同步 composer autoload-dev 与 phpunit 配置。

- 补充 raw/download/upload、微信支付签名下载、XML 嵌套重复节点和消息加解密异常用例。

- 保持测试命名空间 We\Tests,统一通过 tests/bootstrap.php 引导 Composer 自动加载。
2026-05-08 00:29:23 +08:00

80 lines
2.3 KiB
PHP

<?php
declare(strict_types=1);
/**
* 平台配置契约与配置对象测试。
*/
namespace We\Tests;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use We\Config\AlipayPaymentConfig;
use We\Config\AlipayPlatformConfig;
use We\Config\WechatPaymentConfig;
use We\Config\WechatPlatformConfig;
use We\Config\WechatServiceConfig;
use We\Config\WechatWxappConfig;
use We\Contract\ConfigInterface;
use We\Exception\WechatException;
/**
* 平台配置契约与配置对象测试用例。
*/
#[CoversClass(ConfigInterface::class)]
final class ConfigInterfaceTest extends TestCase
{
/**
* 测试所有配置对象都实现配置契约。
*/
public function testAllConfigClassesImplementContract(): void
{
foreach ([
new WechatPlatformConfig('wx_app', 'secret'),
new WechatWxappConfig('wx_wxapp', 'secret'),
new WechatServiceConfig('wx_component', 'secret', 'token', 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFG'),
new WechatPaymentConfig('wx_app', 'mch', str_repeat('k', 32), 'serial', 'private-key'),
new AlipayPlatformConfig('ali_app', 'private-key'),
new AlipayPaymentConfig('ali_pay', 'private-key'),
] as $config) {
$this->assertInstanceOf(ConfigInterface::class, $config);
}
}
/**
* 测试构造配置对象时会校验必填字段。
*/
public function testConfigValidateRequiredFieldsOnConstruct(): void
{
$this->expectException(WechatException::class);
$this->expectExceptionMessage('不能为空');
new WechatPlatformConfig('', 'secret');
}
/**
* 测试通过数组构造配置对象时会校验必填字段。
*/
public function testConfigValidateRequiredFieldsFromArray(): void
{
$this->expectException(WechatException::class);
$this->expectExceptionMessage('不能为空');
WechatPaymentConfig::fromArray(['appid' => 'wx_app']);
}
/**
* 测试支付宝支付配置 fromArray 返回子类实例。
*/
public function testAlipayPaymentFromArrayReturnsChildClass(): void
{
$config = AlipayPaymentConfig::fromArray([
'appid' => 'ali_pay',
'private_key' => 'private-key',
]);
$this->assertInstanceOf(AlipayPaymentConfig::class, $config);
}
}