1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dgame\Soap\Test; |
4
|
|
|
|
5
|
|
|
use Dgame\Soap\Hydrator\ClassMapper; |
6
|
|
|
use Dgame\Soap\Hydrator\Hydrator; |
7
|
|
|
use Dgame\Soap\Test\Object\TestAddress; |
8
|
|
|
use Dgame\Soap\Test\Object\TestCar; |
9
|
|
|
use Dgame\Soap\Test\Object\TestPerson; |
10
|
|
|
use Dgame\Soap\Test\Object\TestPhone; |
11
|
|
|
use Dgame\Soap\Test\Object\TestRoot; |
12
|
|
|
use DOMDocument; |
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class DeHydrationTest |
17
|
|
|
* @package Dgame\Soap\Test |
18
|
|
|
*/ |
19
|
|
|
final class DeHydrationTest extends TestCase |
20
|
|
|
{ |
21
|
|
|
public function testDehydration() |
22
|
|
|
{ |
23
|
|
|
$doc = new DOMDocument('1.0', 'utf-8'); |
24
|
|
|
$doc->formatOutput = false; |
25
|
|
|
$doc->preserveWhiteSpace = false; |
26
|
|
|
$doc->load(__DIR__ . '/xml/test1.xml'); |
27
|
|
|
|
28
|
|
|
$mapper = new ClassMapper( |
29
|
|
|
[ |
30
|
|
|
'Root' => TestRoot::class, |
31
|
|
|
'Person' => TestPerson::class, |
32
|
|
|
'Car' => TestCar::class, |
33
|
|
|
'Phone' => TestPhone::class, |
34
|
|
|
'Address' => TestAddress::class |
35
|
|
|
] |
36
|
|
|
); |
37
|
|
|
$mapper->appendPattern('/^(?:soap\-?)?env(?:elope)?/iS', 'Root'); |
38
|
|
|
|
39
|
|
|
$hydrator = new Hydrator($mapper); |
40
|
|
|
$root = $hydrator->hydrate($doc); |
41
|
|
|
|
42
|
|
|
$this->assertNotNull($root); |
43
|
|
|
$this->assertInstanceOf(TestRoot::class, $root); |
44
|
|
|
|
45
|
|
|
$node = $hydrator->assemble($root); |
46
|
|
|
|
47
|
|
|
$this->assertEqualXMLStructure($doc->documentElement, $node->documentElement); |
48
|
|
|
} |
49
|
|
|
} |