Skip to content

Commit e7c5e62

Browse files
authored
fix: break after finding ini comment (#536)
* fix: break after finding ini comment * tweak: added test
1 parent f329341 commit e7c5e62

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

src/CommentIni.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ private function findIniComment(iterable $walker):array {
7070

7171
$this->assertCommentIsLeadingNode($commentNode);
7272
$commentNodeToRemove = $commentNode;
73+
break;
7374
}
7475

7576
return [$commentNodeToRemove, $ini];

test/phpunit/CommentIniTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ public function testContainsIniData_emptyIfMalformedIniSyntax():void {
3535
self::assertStringContainsString("something: broken", $document->saveHTML());
3636
}
3737

38+
public function testContainsIniData_onlyFindsFirstComment():void {
39+
$document = new HTMLDocument(HTMLPageContent::HTML_COMMENT_WITH_INI_AND_ANOTHER_COMMENT);
40+
$sut = new CommentIni($document);
41+
self::assertTrue($sut->containsIniData());
42+
self::assertEquals("base-page", $sut->get("extends"));
43+
}
44+
3845
public function testGet_noMatchingData():void {
3946
$document = new HTMLDocument(HTMLPageContent::HTML_EXTENDS_PARTIAL_VIEW);
4047
$sut = new CommentIni($document);

test/phpunit/TestHelper/HTMLPageContent.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,16 @@ class HTMLPageContent {
934934
<article>
935935
<h1>Hello from within a sub-template!</h1>
936936
</article>
937+
HTML;
938+
939+
const HTML_COMMENT_WITH_INI_AND_ANOTHER_COMMENT = <<<HTML
940+
<!--
941+
extends=base-page
942+
-->
943+
<article>
944+
<!-- This is just another comment -->
945+
<h1>Hello from within a sub-template!</h1>
946+
</article>
937947
HTML;
938948

939949
const HTML_COMPONENT = <<<HTML

0 commit comments

Comments
 (0)