Skip to content

Commit

Permalink
More stable node loading
Browse files Browse the repository at this point in the history
  • Loading branch information
veewee committed Nov 9, 2023
1 parent c1978d9 commit f059e2c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/Xml/Dom/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use function Psl\Vec\map;
use function VeeWee\Xml\Dom\Configurator\loader;
use function VeeWee\Xml\Dom\Loader\xml_file_loader;
use function VeeWee\Xml\Dom\Loader\xml_node_loader;
use function VeeWee\Xml\Dom\Loader\xml_string_loader;
use function VeeWee\Xml\Dom\Locator\document_element;
use function VeeWee\Xml\Dom\Mapper\xml_string;
Expand Down Expand Up @@ -80,7 +79,9 @@ public static function fromXmlString(string $xml, callable ...$configurators): s
public static function fromXmlNode(DOMNode $node, callable ...$configurators): self
{
return self::configure(
loader(xml_node_loader($node)),
loader(xml_string_loader(
xml_string()($node)
)),
...$configurators
);
}
Expand Down
21 changes: 20 additions & 1 deletion tests/Xml/Dom/DocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
use VeeWee\Xml\Dom\Document;
use VeeWee\Xml\Dom\Traverser\Action;
use VeeWee\Xml\Dom\Traverser\Visitor\AbstractVisitor;
use VeeWee\Xml\Dom\Traverser\Visitor\RemoveNamespaces;
use function Psl\Fun\identity;
use function VeeWee\Xml\Dom\Configurator\traverse;
use function VeeWee\Xml\Dom\Configurator\trim_spaces;
use function VeeWee\Xml\Dom\Configurator\utf8;
use function VeeWee\Xml\Dom\Locator\document_element;
Expand Down Expand Up @@ -65,7 +67,7 @@ public function test_it_can_add_various_configurators(): void
}


public function test_it_can_create_a_document_from_xml_nod(): void
public function test_it_can_create_a_document_from_xml_node(): void
{
$source = new DOMDocument();
$source->loadXML($xml = '<hello />');
Expand All @@ -78,6 +80,23 @@ public function test_it_can_create_a_document_from_xml_nod(): void
static::assertXmlStringEqualsXmlString($xml, $doc->toXmlString());
}

/**
* @see https://github.com/php/php-src/issues/12616
*/
public function test_it_can_create_a_document_from_xml_node_with_removed_namespaces(): void
{
$source = Document::fromXmlString(
'<hello xmlns="https://hello" />',
traverse(RemoveNamespaces::all())
);

$doc = Document::fromXmlNode(
$source->map(document_element()),
identity()
);

static::assertXmlStringEqualsXmlString('<hello />', $doc->toXmlString());
}

public function test_it_can_create_a_document_from_xml_file(): void
{
Expand Down

0 comments on commit f059e2c

Please sign in to comment.