From 5217156068761857a84938014d099126bb63081a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Baptiste=20Clavi=C3=A9?= Date: Thu, 7 Nov 2019 19:03:18 +0100 Subject: [PATCH] Support comments in ErrorBaseline (#2311) --- src/Psalm/ErrorBaseline.php | 5 ++++- tests/ErrorBaselineTest.php | 45 +++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/Psalm/ErrorBaseline.php b/src/Psalm/ErrorBaseline.php index b48dce760..8fc425f4c 100644 --- a/src/Psalm/ErrorBaseline.php +++ b/src/Psalm/ErrorBaseline.php @@ -104,8 +104,11 @@ class ErrorBaseline $files[$fileName] = []; - /** @var \DOMElement $issue */ foreach ($file->childNodes as $issue) { + if (!$issue instanceof \DOMElement) { + continue; + } + $issueType = $issue->tagName; $files[$fileName][$issueType] = [ diff --git a/tests/ErrorBaselineTest.php b/tests/ErrorBaselineTest.php index bc1363d47..0be466397 100644 --- a/tests/ErrorBaselineTest.php +++ b/tests/ErrorBaselineTest.php @@ -299,4 +299,49 @@ class ErrorBaselineTest extends TestCase ], ], $remainingBaseline); } + + /** + * @return void + */ + public function testAddingACommentInBaselineDoesntTriggerNotice() + { + $baselineFilePath = 'baseline.xml'; + + $this->fileProvider->fileExists($baselineFilePath)->willReturn(true); + $this->fileProvider->getContents($baselineFilePath)->willReturn( + ' + + + + + foo + bar + + + + + + + foo + bar + + + ' + ); + + $expectedParsedBaseline = [ + 'sample/sample-file.php' => [ + 'MixedAssignment' => ['o' => 2, 's' => ['foo', 'bar']], + 'InvalidReturnStatement' => ['o' => 1, 's' => []], + ], + 'sample/sample-file2.php' => [ + 'PossiblyUnusedMethod' => ['o' => 2, 's' => ['foo', 'bar']], + ], + ]; + + $this->assertSame( + $expectedParsedBaseline, + ErrorBaseline::read($this->fileProvider->reveal(), $baselineFilePath) + ); + } }