Skip to content

Commit d93e938

Browse files
committed
Improve parsing of ComplexTypeSimpleContent according to XSD rules.
1 parent 5bd6663 commit d93e938

File tree

3 files changed

+104
-2
lines changed

3 files changed

+104
-2
lines changed

src/Xml/Reader/DocumentToLookupArrayReader.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use DOMNode;
88
use Soap\Encoding\Xml\Node\Element;
99
use Soap\Encoding\Xml\Node\ElementList;
10+
use VeeWee\Xml\Xmlns\Xmlns;
1011
use function VeeWee\Xml\Dom\Predicate\is_element;
1112

1213
/**
@@ -50,8 +51,11 @@ public function __invoke(Element $xml): array
5051

5152
// It might be possible that the child is a regular textNode.
5253
// In that case, we use '_' as the key and the value of the textNode as value.
53-
if (!$nodes && $content = trim($root->textContent)) {
54-
$nodes['_'] = $content;
54+
if (!$nodes) {
55+
$nodes['_'] = match(true) {
56+
$root->getAttributeNS(Xmlns::xsi()->value(), 'nil') === 'true' => null,
57+
default => $root->textContent,
58+
};
5559
}
5660

5761
// All attributes also need to be added as key => value pairs.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Soap\Encoding\Test\PhpCompatibility;
5+
6+
use PHPUnit\Framework\Attributes\CoversClass;
7+
use Soap\Encoding\Decoder;
8+
use Soap\Encoding\Driver;
9+
use Soap\Encoding\Encoder;
10+
11+
#[CoversClass(Driver::class)]
12+
#[CoversClass(Encoder::class)]
13+
#[CoversClass(Decoder::class)]
14+
final class Schema062Variant1Test extends AbstractCompatibilityTests
15+
{
16+
protected string $schema = <<<EOXML
17+
<complexType name="testType">
18+
<simpleContent>
19+
<restriction base="string">
20+
<attribute name="int" type="int"/>
21+
</restriction>
22+
</simpleContent>
23+
</complexType>
24+
EOXML;
25+
protected string $type = 'type="testType"';
26+
27+
protected function calculateParam(): mixed
28+
{
29+
return (object)[
30+
'_' => '',
31+
'int' => 123
32+
];
33+
}
34+
35+
protected function expectXml(): string
36+
{
37+
return <<<XML
38+
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://test-uri/"
39+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
40+
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
41+
<SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
42+
<tns:test>
43+
<testParam int="123" xsi:type="tns:testType"/>
44+
</tns:test>
45+
</SOAP-ENV:Body>
46+
</SOAP-ENV:Envelope>
47+
XML;
48+
}
49+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Soap\Encoding\Test\PhpCompatibility;
5+
6+
use PHPUnit\Framework\Attributes\CoversClass;
7+
use Soap\Encoding\Decoder;
8+
use Soap\Encoding\Driver;
9+
use Soap\Encoding\Encoder;
10+
11+
#[CoversClass(Driver::class)]
12+
#[CoversClass(Encoder::class)]
13+
#[CoversClass(Decoder::class)]
14+
final class Schema062Variant2Test extends AbstractCompatibilityTests
15+
{
16+
protected string $schema = <<<EOXML
17+
<complexType name="testType">
18+
<simpleContent>
19+
<restriction base="string">
20+
<attribute name="int" type="int"/>
21+
</restriction>
22+
</simpleContent>
23+
</complexType>
24+
EOXML;
25+
protected string $type = 'type="testType"';
26+
27+
protected function calculateParam(): mixed
28+
{
29+
return (object)[
30+
'_' => null,
31+
'int' => 123
32+
];
33+
}
34+
35+
protected function expectXml(): string
36+
{
37+
return <<<XML
38+
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://test-uri/"
39+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
40+
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
41+
<SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
42+
<tns:test>
43+
<testParam xsi:nil="true" int="123" xsi:type="tns:testType"/>
44+
</tns:test>
45+
</SOAP-ENV:Body>
46+
</SOAP-ENV:Envelope>
47+
XML;
48+
}
49+
}

0 commit comments

Comments
 (0)