Skip to content

[VarDumper] Fix dumping ext-dom virtual properties #58245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
209 changes: 178 additions & 31 deletions src/Symfony/Component/VarDumper/Tests/Caster/DOMCasterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ public function testCastModernImplementation()
);
}

public function testCastNode()
/**
* @requires PHP < 8.4
*/
public function testCastNodePriorToPhp84()
{
$doc = new \DOMDocument();
$doc->loadXML('<foo><bar/></foo>');
Expand All @@ -67,6 +70,27 @@ public function testCastNode()
);
}

/**
* @requires PHP 8.4
*/
public function testCastNode()
{
$doc = new \DOMDocument();
$doc->loadXML('<foo><bar/></foo>');
$node = $doc->documentElement->firstChild;

$this->assertDumpMatchesFormat(<<<'EODUMP'
DOMElement {%A
+ownerDocument: ~ ?DOMDocument
+namespaceURI: ~ ?string
+prefix: ~ string
+localName: ~ ?string
%A}
EODUMP,
$node
);
}

/**
* @requires PHP 8.4
*/
Expand All @@ -77,9 +101,9 @@ public function testCastModernNode()

$this->assertDumpMatchesFormat(<<<'EODUMP'
Dom\Element {%A
+baseURI: ? string
+isConnected: ? bool
+ownerDocument: ? ?Dom\Document
+baseURI: ~ string
+isConnected: ~ bool
+ownerDocument: ~ ?Dom\Document
%A}
EODUMP,
$node
Expand Down Expand Up @@ -142,7 +166,10 @@ public function testCastHTMLDocument()
);
}

public function testCastText()
/**
* @requires PHP < 8.4
*/
public function testCastTextPriorToPhp84()
{
$doc = new \DOMText('foo');

Expand All @@ -155,6 +182,22 @@ public function testCastText()
);
}

/**
* @requires PHP 8.4
*/
public function testCastText()
{
$doc = new \DOMText('foo');

$this->assertDumpMatchesFormat(<<<'EODUMP'
DOMText {%A
+wholeText: ~ string
}
EODUMP,
$doc
);
}

/**
* @requires PHP 8.4
*/
Expand All @@ -163,7 +206,7 @@ public function testCastModernText()
$text = \Dom\HTMLDocument::createEmpty()->createTextNode('foo');
$this->assertDumpMatchesFormat(<<<'EODUMP'
Dom\Text {%A
+wholeText: ? string
+wholeText: ~ string
}
EODUMP,
$text
Expand Down Expand Up @@ -199,11 +242,31 @@ public function testCastAttr()

$this->assertDumpMatchesFormat(<<<'EODUMP'
DOMAttr {%A
+name: ? string
+specified: ? bool
+value: ? string
+ownerElement: ? ?DOMElement
+schemaTypeInfo: ? mixed
+name: ~ string
+specified: ~ bool
+value: ~ string
+ownerElement: ~ ?DOMElement
+schemaTypeInfo: ~ mixed
}
EODUMP,
$attr
);
}

/**
* @requires PHP 8.4
*/
public function testCastAttrPrior()
{
$attr = new \DOMAttr('attr', 'value');

$this->assertDumpMatchesFormat(<<<'EODUMP'
DOMAttr {%A
+name: ~ string
+specified: ~ bool
+value: ~ string
+ownerElement: ~ ?DOMElement
+schemaTypeInfo: ~ mixed
}
EODUMP,
$attr
Expand All @@ -219,17 +282,20 @@ public function testCastModernAttr()

$this->assertDumpMatchesFormat(<<<'EODUMP'
Dom\Attr {%A
+name: ? string
+value: ? string
+ownerElement: ? ?Dom\Element
+specified: ? bool
+name: ~ string
+value: ~ string
+ownerElement: ~ ?Dom\Element
+specified: ~ bool
}
EODUMP,
$attr
);
}

public function testCastElement()
/**
* @requires PHP < 8.4
*/
public function testCastElementPriorToPhp84()
{
$attr = new \DOMElement('foo');

Expand All @@ -242,6 +308,22 @@ public function testCastElement()
);
}

/**
* @requires PHP 8.4
*/
public function testCastElement()
{
$attr = new \DOMElement('foo');

$this->assertDumpMatchesFormat(<<<'EODUMP'
DOMElement {%A
+tagName: ~ string
%A}
EODUMP,
$attr
);
}

/**
* @requires PHP 8.4
*/
Expand All @@ -251,14 +333,17 @@ public function testCastModernElement()

$this->assertDumpMatchesFormat(<<<'EODUMP'
Dom\HTMLElement {%A
+tagName: ? string
+tagName: ~ string
%A}
EODUMP,
$attr
);
}

public function testCastDocumentType()
/**
* @requires PHP < 8.4
*/
public function testCastDocumentTypePriorToPhp84()
{
$implementation = new \DOMImplementation();
$type = $implementation->createDocumentType('html', 'publicId', 'systemId');
Expand All @@ -277,6 +362,28 @@ public function testCastDocumentType()
);
}

/**
* @requires PHP 8.4
*/
public function testCastDocumentType()
{
$implementation = new \DOMImplementation();
$type = $implementation->createDocumentType('html', 'publicId', 'systemId');

$this->assertDumpMatchesFormat(<<<'EODUMP'
DOMDocumentType {%A
+name: ~ string
+entities: ~ DOMNamedNodeMap
+notations: ~ DOMNamedNodeMap
+publicId: ~ string
+systemId: ~ string
+internalSubset: ~ ?string
}
EODUMP,
$type
);
}

/**
* @requires PHP 8.4
*/
Expand All @@ -287,19 +394,22 @@ public function testCastModernDocumentType()

$this->assertDumpMatchesFormat(<<<'EODUMP'
Dom\DocumentType {%A
+name: ? string
+entities: ? Dom\DtdNamedNodeMap
+notations: ? Dom\DtdNamedNodeMap
+publicId: ? string
+systemId: ? string
+internalSubset: ? ?string
+name: ~ string
+entities: ~ Dom\DtdNamedNodeMap
+notations: ~ Dom\DtdNamedNodeMap
+publicId: ~ string
+systemId: ~ string
+internalSubset: ~ ?string
}
EODUMP,
$type
);
}

public function testCastProcessingInstruction()
/**
* @requires PHP < 8.4
*/
public function testCastProcessingInstructionPriorToPhp84()
{
$entity = new \DOMProcessingInstruction('target', 'data');

Expand All @@ -313,6 +423,23 @@ public function testCastProcessingInstruction()
);
}

/**
* @requires PHP 8.4
*/
public function testCastProcessingInstruction()
{
$entity = new \DOMProcessingInstruction('target', 'data');

$this->assertDumpMatchesFormat(<<<'EODUMP'
DOMProcessingInstruction {%A
+target: ~ string
+data: ~ string
}
EODUMP,
$entity
);
}

/**
* @requires PHP 8.4
*/
Expand All @@ -322,16 +449,19 @@ public function testCastModernProcessingInstruction()

$this->assertDumpMatchesFormat(<<<'EODUMP'
Dom\ProcessingInstruction {%A
+data: ? string
+length: ? int
+target: ? string
+data: ~ string
+length: ~ int
+target: ~ string
}
EODUMP,
$entity
);
}

public function testCastXPath()
/**
* @requires PHP < 8.4
*/
public function testCastXPathPriorToPhp84()
{
$xpath = new \DOMXPath(new \DOMDocument());

Expand All @@ -345,6 +475,23 @@ public function testCastXPath()
);
}

/**
* @requires PHP 8.4
*/
public function testCastXPath()
{
$xpath = new \DOMXPath(new \DOMDocument());

$this->assertDumpEquals(<<<'EODUMP'
DOMXPath {
+document: ~ DOMDocument
+registerNodeNamespaces: ~ bool
}
EODUMP,
$xpath
);
}

/**
* @requires PHP 8.4
*/
Expand All @@ -354,8 +501,8 @@ public function testCastModernXPath()

$this->assertDumpEquals(<<<'EODUMP'
Dom\XPath {
+document: ? Dom\Document
+registerNodeNamespaces: ? bool
+document: ~ Dom\Document
+registerNodeNamespaces: ~ bool
}
EODUMP,
$entity
Expand Down
Loading