8000 [VarDumper] Fix dumping ext-dom virtual properties · symfony/symfony@ad55bb2 · GitHub
[go: up one dir, main page]

Skip to content

Commit ad55bb2

Browse files
[VarDumper] Fix dumping ext-dom virtual properties
1 parent 44395ab commit ad55bb2

File tree

2 files changed

+230
-29
lines changed

2 files changed

+230
-29
lines changed

src/Symfony/Component/VarDumper/Tests/Caster/DOMCasterTest.php

Lines changed: 177 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ public function testCastModernImplementation()
4949
);
5050
}
5151

52-
public function testCastNode()
52+
/**
53+
* @requires PHP < 8.4
54+
*/
55+
public function testCastNodePriorToPhp84()
5356
{
5457
$doc = new \DOMDocument();
5558
$doc->loadXML('<foo><bar/></foo>');
@@ -67,6 +70,27 @@ public function testCastNode()
6770
);
6871
}
6972

73+
/**
74+
* @requires PHP 8.4
75+
*/
76+
public function testCastNode()
77+
{
78+
$doc = new \DOMDocument();
79+
$doc->loadXML('<foo><bar/></foo>');
80+
$node = $doc->documentElement->firstChild;
81+
82+
$this->assertDumpMatchesFormat(<<<'EODUMP'
83+
DOMElement {%A
84+
+ownerDocument: ~ ?DOMDocument
85+
+namespaceURI: ~ ?string
86+
+prefix: ~ string
87+
+localName: ~ ?string
88+
%A}
89+
EODUMP,
90+
$node
91+
);
92+
}
93+
7094
/**
7195
* @requires PHP 8.4
7296
*/
@@ -77,9 +101,9 @@ public function testCastModernNode()
77101

78102
$this->assertDumpMatchesFormat(<<<'EODUMP'
79103
Dom\Element {%A
80-
+baseURI: ? string
81-
+isConnected: ? bool
82-
+ownerDocument: ? ?Dom\Document
104+
+baseURI: ~ string
105+
+isConnected: ~ bool
106+
+ownerDocument: ~ ?Dom\Document
83107
%A}
84108
EODUMP,
85109
$node
@@ -142,7 +166,10 @@ public function testCastHTMLDocument()
142166
);
143167
}
144168

145-
public function testCastText()
169+
/**
170+
* @requires PHP < 8.4
171+
*/
172+
public function testCastTextPriorToPhp84()
146173
{
147174
$doc = new \DOMText('foo');
148175

@@ -155,6 +182,22 @@ public function testCastText()
155182
);
156183
}
157184

185+
/**
186+
* @requires PHP 8.4
187+
*/
188+
public function testCastText()
189+
{
190+
$doc = new \DOMText('foo');
191+
192+
$this->assertDumpMatchesFormat(<<<'EODUMP'
193+
DOMText {%A
194+
+wholeText: ~ string
195+
}
196+
EODUMP,
197+
$doc
198+
);
199+
}
200+
158201
/**
159202
* @requires PHP 8.4
160203
*/
@@ -163,14 +206,17 @@ public function testCastModernText()
163206
$text = \Dom\HTMLDocument::createEmpty()->createTextNode('foo');
164207
$this->assertDumpMatchesFormat(<<<'EODUMP'
165208
Dom\Text {%A
166-
+wholeText: ? string
209+
+wholeText: ~ string
167210
}
168211
EODUMP,
169212
$text
170213
);
171214
}
172215

173-
public function testCastAttr()
216+
/**
217+
* @requires PHP < 8.4
218+
*/
219+
public function testCastAttrPriorToPhp84()
174220
{
175221
$attr = new \DOMAttr('attr', 'value');
176222

@@ -187,6 +233,26 @@ public function testCastAttr()
187233
);
188234
}
189235

236+
/**
237+
* @requires PHP 8.4
238+
*/
239+
public function testCastAttrPrior()
240+
{
241+
$attr = new \DOMAttr('attr', 'value');
242+
243+
$this->assertDumpMatchesFormat(<<<'EODUMP'
244+
DOMAttr {%A
245+
+name: ~ string
246+
+specified: ~ bool
247+
+value: ~ string
248+
+ownerElement: ~ ?DOMElement
249+
+schemaTypeInfo: ~ mixed
250+
}
251+
EODUMP,
252+
$attr
253+
);
254+
}
255+
190256
/**
191257
* @requires PHP 8.4
192258
*/
@@ -196,17 +262,20 @@ public function testCastModernAttr()
196262

197263
$this->assertDumpMatchesFormat(<<<'EODUMP'
198264
Dom\Attr {%A
199-
+name: ? string
200-
+value: ? string
201-
+ownerElement: ? ?Dom\Element
202-
+specified: true
265+
+name: ~ string
266+
+value: ~ string
267+
+ownerElement: ~ ?Dom\Element
268+
+specified: ~ bool
203269
}
204270
EODUMP,
205271
$attr
206272
);
207273
}
208274

209-
public function testCastElement()
275+
/**
276+
* @requires PHP < 8.4
277+
*/
278+
public function testCastElementPriorToPhp84()
210279
{
211280
$attr = new \DOMElement('foo');
212281

@@ -219,6 +288,22 @@ public function testCastElement()
219288
);
220289
}
221290

291+
/**
292+
* @requires PHP 8.4
293+
*/
294+
public function testCastElement()
295+
{
296+
$attr = new \DOMElement('foo');
297+
298+
$this->assertDumpMatchesFormat(<<<'EODUMP'
299+
DOMElement {%A
300+
+tagName: ~ string
301+
%A}
302+
EODUMP,
303+
$attr
304+
);
305+
}
306+
222307
/**
223308
* @requires PHP 8.4
224309
*/
@@ -228,14 +313,17 @@ public function testCastModernElement()
228313

229314
$this->assertDumpMatchesFormat(<<<'EODUMP'
230315
Dom\HTMLElement {%A
231-
+tagName: ? string
316+
+tagName: ~ string
232317
%A}
233318
EODUMP,
234319
$attr
235320
);
236321
}
237322

238-
public function testCastDocumentType()
323+
/**
324+
* @requires PHP < 8.4
325+
*/
326+
public function testCastDocumentTypePriorToPhp84()
239327
{
240328
$implementation = new \DOMImplementation();
241329
$type = $implementation->createDocumentType('html', 'publicId', 'systemId');
@@ -254,6 +342,28 @@ public function testCastDocumentType()
254342
);
255343
}
256344

345+
/**
346+
* @requires PHP 8.4
347+
*/
348+
public function testCastDocumentType()
349+
{
350+
$implementation = new \DOMImplementation();
351+
$type = $implementation->createDocumentType('html', 'publicId', 'systemId');
352+
353+
$this->assertDumpMatchesFormat(<<<'EODUMP'
354+
DOMDocumentType {%A
355+
+name: ~ string
356+
+entities: ~ DOMNamedNodeMap
357+
+notations: ~ DOMNamedNodeMap
358+
+publicId: ~ string
359+
+systemId: ~ string
360+
+internalSubset: ~ ?string
361+
}
362+
EODUMP,
363+
$type
364+
);
365+
}
366+
257367
/**
258368
* @requires PHP 8.4
259369
*/
@@ -264,19 +374,22 @@ public function testCastModernDocumentType()
264374

265375
$this->assertDumpMatchesFormat(<<<'EODUMP'
266376
Dom\DocumentType {%A
267-
+name: ? string
268-
+entities: ? Dom\DtdNamedNodeMap
269-
+notations: ? Dom\DtdNamedNodeMap
270-
+publicId: ? string
271-
+systemId: ? string
272-
+internalSubset: ? ?string
377+
+name: ~ string
378+
+entities: ~ Dom\DtdNamedNodeMap
379+
+notations: ~ Dom\DtdNamedNodeMap
380+
+publicId: ~ string
381+
+systemId: ~ string
382+
+internalSubset: ~ ?string
273383
}
274384
EODUMP,
275385
$type
276386
);
277387
}
278388

279-
public function testCastProcessingInstruction()
389+
/**
390+
* @requires PHP < 8.4
391+
*/
392+
public function testCastProcessingInstructionPriorToPhp84()
280393
{
281394
$entity = new \DOMProcessingInstruction('target', 'data');
282395

@@ -290,6 +403,23 @@ public function testCastProcessingInstruction()
290403
);
291404
}
292405

406+
/**
407+
* @requires PHP 8.4
408+
*/
409+
public function testCastProcessingInstruction()
410+
{
411+
$entity = new \DOMProcessingInstruction('target', 'data');
412+
413+
$this->assertDumpMatchesFormat(<<<'EODUMP'
414+
DOMProcessingInstruction {%A
415+
+target: ~ string
416+
+data: ~ string
417+
}
418+
EODUMP,
419+
$entity
420+
);
421+
}
422+
293423
/**
294424
* @requires PHP 8.4
295425
*/
@@ -299,16 +429,19 @@ public function testCastModernProcessingInstruction()
299429

300430
$this->assertDumpMatchesFormat(<<<'EODUMP'
301431
Dom\ProcessingInstruction {%A
302-
+data: ? string
303-
+length: ? int
304-
+target: ? string
432+
+data: ~ string
433+
+length: ~ int
434+
+target: ~ string
305435
}
306436
EODUMP,
307437
$entity
308438
);
309439
}
310440

311-
public function testCastXPath()
441+
/**
442+
* @requires PHP < 8.4
443+
*/
444+
public function testCastXPathPriorToPhp84()
312445
{
313446
$xpath = new \DOMXPath(new \DOMDocument());
314447

@@ -322,6 +455,23 @@ public function testCastXPath()
322455
);
323456
}
324457

458+
/**
459+
* @requires PHP 8.4
460+
*/
461+
public function testCastXPath()
462+
{
463+
$xpath = new \DOMXPath(new \DOMDocument());
464+
465+
$this->assertDumpEquals(<<<'EODUMP'
466+
DOMXPath {
467+
+document: ~ DOMDocument
468+
+registerNodeNamespaces: ~ bool
469+
}
470+
EODUMP,
471+
$xpath
472+
);
473+
}
474+
325475
/**
326476
* @requires PHP 8.4
327477
*/
@@ -331,8 +481,8 @@ public function testCastModernXPath()
331481

332482
$this->assertDumpEquals(<<<'EODUMP'
333483
Dom\XPath {
334-
+document: ? Dom\Document
335-
+registerNodeNamespaces: ? bool
484+
+document: ~ Dom\Document
485+
+registerNodeNamespaces: ~ bool
336486
}
337487
EODUMP,
338488
$entity

0 commit comments

Comments
 (0)
0