Skip to content
This repository was archived by the owner on Nov 21, 2019. It is now read-only.

Commit 65fcea2

Browse files
Ignore comments (#62)
1 parent 4ad8ca3 commit 65fcea2

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

phpstan.neon.dist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
parameters:
22
ignoreErrors:
33
- '~^Call to an undefined method FluentDOM\\DOM\\Node\\.+?::getNodePath\(\)\.$~'
4-
- '~^Cannot cast FluentDOM\\DOM\\Node\\.+? to string\.$~'
54
- '~^Cannot call method (end|([a-z]+)Node)\(\) on Symfony\\Component\\Config\\Definition\\Builder\\NodeParentInterface\|null\.$~'
65
- '~^Service "csa_guzzle\.mock\.storage" is not registered in the container\.$~'
76
level: max

vendor-extra/LiberoPageBundle/tests/XmlTestCase.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use FluentDOM;
88
use FluentDOM\DOM\Document;
99
use FluentDOM\DOM\Element;
10+
use FluentDOM\DOM\Node\NonDocumentTypeChildNode;
1011

1112
trait XmlTestCase
1213
{
@@ -23,4 +24,9 @@ final protected function loadElement(string $xml) : Element
2324
{
2425
return $this->loadDocument($xml)->documentElement;
2526
}
27+
28+
final protected function loadNode(string $xml) : NonDocumentTypeChildNode
29+
{
30+
return $this->loadElement("<root>$xml</root>")[0];
31+
}
2632
}

vendor-extra/ViewsBundle/src/Views/EventDispatchingViewConverter.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
namespace Libero\ViewsBundle\Views;
66

7+
use FluentDOM\DOM\CdataSection;
78
use FluentDOM\DOM\Element;
89
use FluentDOM\DOM\Node\NonDocumentTypeChildNode;
10+
use FluentDOM\DOM\Text;
911
use Libero\ViewsBundle\Event\BuildViewEvent;
1012
use LogicException;
1113
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -29,6 +31,10 @@ public function convert(NonDocumentTypeChildNode $node, ?string $template = null
2931
);
3032
}
3133

34+
if (!$node instanceof Text && !$node instanceof CdataSection) {
35+
return new View('@LiberoPatterns/text.html.twig', ['nodes' => ''], $context);
36+
}
37+
3238
return new View('@LiberoPatterns/text.html.twig', ['nodes' => (string) $node], $context);
3339
}
3440

vendor-extra/ViewsBundle/tests/Views/EventDispatchingViewConverterTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,29 @@ public function it_returns_text_by_default() : void
4646
$this->assertEquals($expected, $handler->convert($node));
4747
}
4848

49+
/**
50+
* @test
51+
* @dataProvider nonElementProvider
52+
*/
53+
public function it_handles_non_elements(string $node, $expected = '') : void
54+
{
55+
$handler = new EventDispatchingViewConverter(new EventDispatcher());
56+
57+
$node = $this->loadNode($node);
58+
59+
$expected = new View('@LiberoPatterns/text.html.twig', ['nodes' => $expected]);
60+
61+
$this->assertEquals($expected, $handler->convert($node));
62+
}
63+
64+
public function nonElementProvider() : iterable
65+
{
66+
yield 'cdata' => ['<![CDATA[<cdata>]]>', '<cdata>'];
67+
yield 'comment' => ['<!--comment-->'];
68+
yield 'processing instruction' => ['<?processing instruction?>'];
69+
yield 'text' => ['text', 'text'];
70+
}
71+
4972
/**
5073
* @test
5174
*/

0 commit comments

Comments
 (0)