mirror of
https://gitee.com/zoujingli/WeChatDeveloper.git
synced 2026-09-04 23:12:09 +08:00
- 按 PHP-CS-Fixer 规则补齐核心契约、异常、缓存和 XML 工具文件头。 - 规范导入、PHPDoc 类型顺序与注释格式,保持项目头信息不丢失。 - 同步整理缓存键、缓存实现、XML 编解码相关测试和 bootstrap 格式。
59 lines
1.7 KiB
PHP
59 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
/**
|
|
* This file is part of HyperfAdmin.
|
|
*
|
|
* @Link https://thinkadmin.top
|
|
* @Author Anyon<zoujingli@qq.com>
|
|
*/
|
|
|
|
namespace We\Tests;
|
|
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
|
use PHPUnit\Framework\TestCase;
|
|
use We\Support\Xml;
|
|
|
|
/**
|
|
* 微信 XML 编解码工具测试用例。
|
|
* @internal
|
|
*/
|
|
#[CoversClass(Xml::class)]
|
|
final class XmlTest extends TestCase
|
|
{
|
|
/**
|
|
* 测试重复节点和嵌套节点可正确解码。
|
|
*/
|
|
public function testDecodeKeepsRepeatedAndNestedNodes(): void
|
|
{
|
|
$xml = '<xml><Articles><item><Title><![CDATA[A]]></Title></item><item><Title><![CDATA[B]]></Title></item></Articles><Tag><![CDATA[x]]></Tag><Tag><![CDATA[y]]></Tag></xml>';
|
|
|
|
$data = Xml::decode($xml);
|
|
|
|
$this->assertSame('A', $data['Articles']['item'][0]['Title']);
|
|
$this->assertSame('B', $data['Articles']['item'][1]['Title']);
|
|
$this->assertSame(['x', 'y'], $data['Tag']);
|
|
}
|
|
|
|
/**
|
|
* 测试嵌套数组、列表节点和包含 CDATA 结束标记的文本可正确编码。
|
|
*/
|
|
public function testEncodeSupportsNestedListsAndCdataEndMarker(): void
|
|
{
|
|
$xml = Xml::encode([
|
|
'Articles' => [
|
|
'item' => [
|
|
['Title' => 'A', 'Description' => 'hello ]]> world'],
|
|
['Title' => 'B', 'Description' => 'second'],
|
|
],
|
|
],
|
|
]);
|
|
|
|
$data = Xml::decode($xml);
|
|
|
|
$this->assertSame('A', $data['Articles']['item'][0]['Title']);
|
|
$this->assertSame('hello ]]> world', $data['Articles']['item'][0]['Description']);
|
|
$this->assertSame('B', $data['Articles']['item'][1]['Title']);
|
|
}
|
|
}
|