1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Support comments in ErrorBaseline (#2311)

This commit is contained in:
Baptiste Clavié 2019-11-07 19:03:18 +01:00 committed by Matthew Brown
parent 3d7b34e7f6
commit 5217156068
2 changed files with 49 additions and 1 deletions

View File

@ -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] = [

View File

@ -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(
'<?xml version="1.0" encoding="UTF-8"?>
<files>
<file src="sample/sample-file.php">
<!-- here is a comment ! //-->
<MixedAssignment occurrences="2">
<code>foo</code>
<code>bar</code>
</MixedAssignment>
<InvalidReturnStatement occurrences="1"/>
</file>
<!-- And another one ! //-->
<file src="sample\sample-file2.php">
<PossiblyUnusedMethod occurrences="2">
<code>foo</code>
<code>bar</code>
</PossiblyUnusedMethod>
</file>
</files>'
);
$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)
);
}
}