Repository navigation
Expand file tree
/
Copy pathXmlTest.php
More file actions
64 lines (57 loc) · 1.74 KB
/
Copy pathXmlTest.php
File metadata and controls
64 lines (57 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace HyperfTest\Codec;
use Hyperf\Codec\Exception\InvalidArgumentException;
use Hyperf\Codec\Xml;
use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\TestCase;
/**
* @internal
* @coversNothing
*/
#[CoversNothing]
class XmlTest extends TestCase
{
public function testToArray()
{
$xml = '<?xml version="1.0" encoding="utf-8"?><xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
$data = [
'return_code' => 'SUCCESS',
'return_msg' => 'OK',
];
$this->assertSame($data, Xml::toArray($xml));
}
public function testToArrayException()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Syntax error.');
$xml = 'xxxxx';
$data = [
'return_code' => 'SUCCESS',
'return_msg' => 'OK',
];
$this->assertSame($data, Xml::toArray($xml));
}
public function testToXml()
{
$xml = '<?xml version="1.0" encoding="utf-8"?><xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
$data = [
'return_code' => 'SUCCESS',
'return_msg' => 'OK',
];
$this->assertSame(Xml::toXml(Xml::toArray($xml), null, 'xml'), Xml::toXml($data, null, 'xml'));
}
public function testXmlFailed()
{
$this->expectException(InvalidArgumentException::class);
Xml::toArray('{"hype');
}
}