mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Merge pull request #6000 from bdsl/ignore-line-endings-in-baseline
This commit is contained in:
commit
8c137527d4
@ -19,6 +19,7 @@ use function phpversion;
|
||||
use function preg_replace_callback;
|
||||
use function str_replace;
|
||||
use function strpos;
|
||||
use function trim;
|
||||
use function usort;
|
||||
|
||||
use const LIBXML_NOBLANKS;
|
||||
@ -115,7 +116,7 @@ class ErrorBaseline
|
||||
$codeSamples = $issue->getElementsByTagName('code');
|
||||
|
||||
foreach ($codeSamples as $codeSample) {
|
||||
$files[$fileName][$issueType]['s'][] = $codeSample->textContent;
|
||||
$files[$fileName][$issueType]['s'][] = trim($codeSample->textContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -273,6 +274,10 @@ class ErrorBaseline
|
||||
foreach ($existingIssueType['s'] as $selection) {
|
||||
$codeNode = $baselineDoc->createElement('code');
|
||||
|
||||
/** @todo in major version release (e.g. Psalm 5) replace $selection with trim($selection)
|
||||
* This will be a minor BC break as baselines generated will then not be compatible with Psalm
|
||||
* versions from before PR https://github.com/vimeo/psalm/pull/6000
|
||||
*/
|
||||
$codeNode->textContent = $selection;
|
||||
$issueNode->appendChild($codeNode);
|
||||
}
|
||||
|
@ -48,6 +48,7 @@ use function sha1;
|
||||
use function sprintf;
|
||||
use function str_repeat;
|
||||
use function str_replace;
|
||||
use function trim;
|
||||
use function usort;
|
||||
|
||||
use const DEBUG_BACKTRACE_IGNORE_ARGS;
|
||||
@ -518,7 +519,7 @@ class IssueBuffer
|
||||
if (isset($issue_baseline[$file][$type]) && $issue_baseline[$file][$type]['o'] > 0) {
|
||||
if ($issue_baseline[$file][$type]['o'] === count($issue_baseline[$file][$type]['s'])) {
|
||||
$position = array_search(
|
||||
$issue_data->selected_text,
|
||||
trim($issue_data->selected_text),
|
||||
$issue_baseline[$file][$type]['s'],
|
||||
true
|
||||
);
|
||||
|
@ -67,6 +67,34 @@ class ErrorBaselineTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testLoadShouldIgnoreLineEndingsInIssueSnippet(): void
|
||||
{
|
||||
$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\">
|
||||
<MixedAssignment occurrences=\"1\">
|
||||
<code>foo\r</code>
|
||||
</MixedAssignment>
|
||||
</file>
|
||||
</files>"
|
||||
);
|
||||
|
||||
$expectedParsedBaseline = [
|
||||
'sample/sample-file.php' => [
|
||||
'MixedAssignment' => ['o' => 1, 's' => ['foo']],
|
||||
],
|
||||
];
|
||||
|
||||
$this->assertSame(
|
||||
$expectedParsedBaseline,
|
||||
ErrorBaseline::read($this->fileProvider->reveal(), $baselineFilePath)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
|
@ -54,11 +54,31 @@ class IssueBufferTest extends TestCase
|
||||
0,
|
||||
0
|
||||
)
|
||||
]
|
||||
],
|
||||
'/path/three.php' => [
|
||||
new \Psalm\Internal\Analyzer\IssueData(
|
||||
"error",
|
||||
0,
|
||||
0,
|
||||
"MissingPropertyType",
|
||||
'Message',
|
||||
"three.php",
|
||||
"/path/three.php",
|
||||
"snippet-3-has-carriage-return\r",
|
||||
"snippet-3-has-carriage-return\r",
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
)
|
||||
],
|
||||
]);
|
||||
$baseline = [
|
||||
'one.php' => ['MissingPropertyType' => ['o' => 1, 's' => ['snippet-1']] ],
|
||||
'two.php' => ['MissingPropertyType' => ['o' => 1, 's' => ['snippet-2']] ],
|
||||
'three.php' => ['MissingPropertyType' => ['o' => 1, 's' => ['snippet-3-has-carriage-return']] ],
|
||||
];
|
||||
|
||||
$analyzer = $this->createMock(Analyzer::class);
|
||||
|
Loading…
x
Reference in New Issue
Block a user