diff --git a/src/Tracy/Dumper/Dumper.php b/src/Tracy/Dumper/Dumper.php index 49ca5ca23..4598a4f7f 100644 --- a/src/Tracy/Dumper/Dumper.php +++ b/src/Tracy/Dumper/Dumper.php @@ -9,6 +9,7 @@ namespace Tracy; +use Dom; use Ds; use Tracy\Dumper\Describer; use Tracy\Dumper\Exposer; @@ -81,6 +82,11 @@ class Dumper \DOMNode::class => [Exposer::class, 'exposeDOMNode'], \DOMNodeList::class => [Exposer::class, 'exposeDOMNodeList'], \DOMNamedNodeMap::class => [Exposer::class, 'exposeDOMNodeList'], + Dom\Node::class => [Exposer::class, 'exposeDOMNode'], + Dom\NodeList::class => [Exposer::class, 'exposeDOMNodeList'], + Dom\NamedNodeMap::class => [Exposer::class, 'exposeDOMNodeList'], + Dom\TokenList::class => [Exposer::class, 'exposeDOMNodeList'], + Dom\HTMLCollection::class => [Exposer::class, 'exposeDOMNodeList'], Ds\Collection::class => [Exposer::class, 'exposeDsCollection'], Ds\Map::class => [Exposer::class, 'exposeDsMap'], \WeakMap::class => [Exposer::class, 'exposeWeakMap'], diff --git a/src/Tracy/Dumper/Exposer.php b/src/Tracy/Dumper/Exposer.php index aaa87bb0b..eb14a504a 100644 --- a/src/Tracy/Dumper/Exposer.php +++ b/src/Tracy/Dumper/Exposer.php @@ -8,6 +8,7 @@ declare(strict_types=1); namespace Tracy\Dumper; +use Dom; use Ds; @@ -141,7 +142,7 @@ public static function exposeArrayObject(\ArrayObject $obj, Value $value, Descri } - public static function exposeDOMNode(\DOMNode $obj, Value $value, Describer $describer): void + public static function exposeDOMNode(\DOMNode|Dom\Node $obj, Value $value, Describer $describer): void { $props = preg_match_all('#^\s*\[([^\]]+)\] =>#m', print_r($obj, return: true), $tmp) ? $tmp[1] : []; sort($props); @@ -152,7 +153,7 @@ public static function exposeDOMNode(\DOMNode $obj, Value $value, Describer $des public static function exposeDOMNodeList( - \DOMNodeList|\DOMNamedNodeMap $obj, + \DOMNodeList|\DOMNamedNodeMap|Dom\NodeList|Dom\NamedNodeMap|Dom\TokenList|Dom\HTMLCollection $obj, Value $value, Describer $describer, ): void diff --git a/tests/Tracy/Dumper.toText().specials.dom.php84.phpt b/tests/Tracy/Dumper.toText().specials.dom.php84.phpt new file mode 100644 index 000000000..2df18400d --- /dev/null +++ b/tests/Tracy/Dumper.toText().specials.dom.php84.phpt @@ -0,0 +1,110 @@ +', Dom\HTML_NO_DEFAULT_NS); +$xpath = new Dom\XPath($dom); +$nodeList = $xpath->query('//li'); +$namedNodeMap = $nodeList->item(0)->attributes; +$collection = $dom->getElementsByTagName('li'); +$element = $nodeList->item(0); + + +Assert::match( + <<<'XX' + Dom\HTMLDocument #%d% + URL: 'about:blank' + baseURI: 'about:blank' + %A% + doctype: Dom\DocumentType #%d% + | attributes: null + | baseURI: 'about:blank' + | childNodes: %a% + | entities: Dom\DtdNamedNodeMap #%d% ... + | firstChild: null + %A% + documentElement: Dom\Element #%d% + %A% + XX, + Dumper::toText($dom, [Dumper::DEPTH => 2]), +); + + +Assert::match( + <<<'XX' + Dom\NodeList #%d% + length: 1 + items: array (1) + | 0 => Dom\Element #%d% ... + XX, + Dumper::toText($nodeList, [Dumper::DEPTH => 2]), +); + + +Assert::match( + <<<'XX' + Dom\NamedNodeMap #%d% + length: 1 + items: array (1) + | 'class' => Dom\Attr #%d% + | | attributes: null + %A% + XX, + Dumper::toText($namedNodeMap, [Dumper::DEPTH => 3]), +); + + +Assert::match( + <<<'XX' + Dom\HTMLCollection #%d% + length: 1 + items: array (1) + | 'li' => Dom\Element #%d% ... + XX, + Dumper::toText($collection, [Dumper::DEPTH => 2]), +); + + +Assert::match( + <<<'XX' + Dom\Element #%d% + attributes: Dom\NamedNodeMap #%d% ... + baseURI: 'about:blank' + %A% + previousSibling: null + substitutedNodeValue: 'Ahoj' + tagName: 'li' + textContent: 'Ahoj' + XX, + Dumper::toText($element, [Dumper::DEPTH => 1]), +); + + +Assert::match( + <<<'XX' + Dom\TokenList #%d% + length: 1 + items: array (1) + | 0 => 'a' + XX, + Dumper::toText($element->classList, [Dumper::DEPTH => 2]), +); + + +Assert::match( + <<<'XX' + Dom\XPath #%d%%A% + XX, + Dumper::toText($xpath, [Dumper::DEPTH => 1]), +);