mirror of
http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore.git
synced 2026-01-15 07:15:06 +08:00
131 lines
3.4 KiB
PHP
131 lines
3.4 KiB
PHP
<?php
|
|
/**
|
|
* XmlServiceTest.php@LuxOP
|
|
*
|
|
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
|
|
* Powered by PhpStorm
|
|
* Created on 2023/4/10
|
|
*/
|
|
|
|
namespace HyperfTest\Unit\Common;
|
|
|
|
use Singularity\HDK\Core\Service\XmlService;
|
|
use Symfony\Component\Serializer\Encoder\XmlEncoder;
|
|
|
|
use function Hyperf\Support\make;
|
|
|
|
/** @var XmlService $service */
|
|
$service = make(
|
|
XmlService::class,
|
|
['encoder' => make(XmlEncoder::class)]
|
|
);
|
|
|
|
test(
|
|
'assert Xml can be encoded',
|
|
function (array $data, string $expect, string $rootNodeName) use ($service) {
|
|
$result = $service->encode($data, $rootNodeName);
|
|
|
|
expect($result)->toBe($expect);
|
|
}
|
|
)->with([
|
|
'normal' => [
|
|
'data' => [
|
|
'@version' => '1.0',
|
|
'@descripe' => 'Luxcreo',
|
|
'UserName' => 'zhm',
|
|
'Email' => 'haimei.zheng@luxcreo.ai',
|
|
'BiosId' => '420036H32020120279',
|
|
'validTime' => '2099/03/27',
|
|
],
|
|
'expect' => <<<'XML'
|
|
<?xml version="1.0" encoding="utf-8"?>
|
|
<ClientInfo version="1.0" descripe="Luxcreo">
|
|
<UserName>zhm</UserName>
|
|
<Email>haimei.zheng@luxcreo.ai</Email>
|
|
<BiosId>420036H32020120279</BiosId>
|
|
<validTime>2099/03/27</validTime>
|
|
</ClientInfo>
|
|
|
|
XML,
|
|
'xmlRootNodeName' => 'ClientInfo',
|
|
],
|
|
'normal attribute' => [
|
|
'data' => [
|
|
'@version' => '1.0',
|
|
'@descripe' => 'Luxcreo',
|
|
'UserName' => 'zhm',
|
|
'Email' => [
|
|
'@type' => 'Business',
|
|
'#' => 'haimei.zheng@luxcreo.ai',
|
|
],
|
|
'BiosId' => '420036H32020120279',
|
|
'validTime' => '2099/03/27',
|
|
],
|
|
'expect' => <<<'XML'
|
|
<?xml version="1.0" encoding="utf-8"?>
|
|
<ClientInfo version="1.0" descripe="Luxcreo">
|
|
<UserName>zhm</UserName>
|
|
<Email type="Business">haimei.zheng@luxcreo.ai</Email>
|
|
<BiosId>420036H32020120279</BiosId>
|
|
<validTime>2099/03/27</validTime>
|
|
</ClientInfo>
|
|
|
|
XML
|
|
,
|
|
'ClientInfo',
|
|
],
|
|
'normal comment' => [
|
|
'data' => [
|
|
'@version' => '1.0',
|
|
'@descripe' => 'Luxcreo',
|
|
'UserName' => 'zhm',
|
|
'Email' => [
|
|
'@type' => 'Business',
|
|
'#' => 'haimei.zheng@luxcreo.ai',
|
|
],
|
|
'BiosId' => '420036H32020120279',
|
|
'validTime' => [
|
|
'#comment' => '到期时间',
|
|
],
|
|
],
|
|
'expect' => <<<'XML'
|
|
<?xml version="1.0" encoding="utf-8"?>
|
|
<ClientInfo version="1.0" descripe="Luxcreo">
|
|
<UserName>zhm</UserName>
|
|
<Email type="Business">haimei.zheng@luxcreo.ai</Email>
|
|
<BiosId>420036H32020120279</BiosId>
|
|
<validTime>
|
|
<!--到期时间-->
|
|
</validTime>
|
|
</ClientInfo>
|
|
|
|
XML
|
|
,
|
|
'ClientInfo',
|
|
],
|
|
]);
|
|
|
|
test('assert Xml can be parsed', function (string $xml, array $expected) use ($service) {
|
|
$data = $service->decode($xml);
|
|
expect($data)->toBe($expected);
|
|
})->with([
|
|
'normal' => [
|
|
'xml' => <<<XML
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<ClientInfo version="1.0" descripe="LuxAlignAuthentication">
|
|
<UserName>zhm</UserName>
|
|
<Email>haimei.zheng@luxcreo.ai</Email>
|
|
<BiosId>420036H32020120279</BiosId>
|
|
</ClientInfo>
|
|
|
|
XML,
|
|
'expected' => [
|
|
'@version' => 1.0,
|
|
'@descripe' => 'LuxAlignAuthentication',
|
|
'UserName' => 'zhm',
|
|
'Email' => 'haimei.zheng@luxcreo.ai',
|
|
'BiosId' => '420036H32020120279',
|
|
],
|
|
],
|
|
]);
|