1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

do not corrupt internal state when a baseline is present (#2710)

this fixes #2709
This commit is contained in:
Philip Hofstetter 2020-01-29 14:53:58 +01:00 committed by GitHub
parent ecf85aef12
commit 8f8672dd6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 88 additions and 0 deletions

View File

@ -447,6 +447,7 @@ class IssueBuffer
return $d1['file_path'] > $d2['file_path'] ? 1 : -1; return $d1['file_path'] > $d2['file_path'] ? 1 : -1;
} }
); );
unset($file_issues);
} }
if (!empty($issue_baseline)) { if (!empty($issue_baseline)) {

87
tests/IssueBufferTest.php Normal file
View File

@ -0,0 +1,87 @@
<?php
namespace Psalm\Tests;
use Psalm\Codebase;
use Psalm\Config;
use Psalm\Internal\Analyzer\ProjectAnalyzer;
use Psalm\Internal\Codebase\Analyzer;
use Psalm\IssueBuffer;
use Psalm\Report\ReportOptions;
class IssueBufferTest extends TestCase
{
/**
* @return void
*/
public function testFinishDoesNotCorruptInternalState()
{
IssueBuffer::clear();
IssueBuffer::addIssues([
'/path/one.php' => [
[
"severity" => "error",
"type" => "MissingPropertyType",
"message" => 'Message',
"file_name" =>"one.php",
"file_path" => "/path/one.php",
"snippet" => "snippet-1",
"selected_text" => "snippet-1",
"from"=> 0,
"to"=> 0,
"snippet_from" => 0,
"snippet_to" => 0,
"column_from" => 0,
"column_to" => 0,
"line_from" => 0,
"line_to" => 0,
]
],
'/path/two.php' => [
[
"severity" => "error",
"type" => "MissingPropertyType",
"message" => 'Message',
"file_name" =>"two.php",
"file_path" => "/path/two.php",
"snippet" => "snippet-2",
"selected_text" => "snippet-2",
"from"=> 0,
"to"=> 0,
"snippet_from" => 0,
"snippet_to" => 0,
"column_from" => 0,
"column_to" => 0,
"line_from" => 0,
"line_to" => 0,
]
]
]);
$baseline = [
'one.php' => ['MissingPropertyType' => ['o' => 1, 's' => ['snippet-1']] ],
'two.php' => ['MissingPropertyType' => ['o' => 1, 's' => ['snippet-2']] ],
];
$analyzer = $this->createMock(Analyzer::class);
$analyzer->method('getTotalTypeCoverage')->willReturn([0, 0]);
$config = $this->createMock(Config::class);
$codebase = $this->createMock(Codebase::class);
$codebase->analyzer = $analyzer;
$codebase->config = $config;
$projectAnalzyer = $this->createMock(ProjectAnalyzer::class);
$projectAnalzyer->method('getCodebase')->willReturn($codebase);
$projectAnalzyer->stdout_report_options = new ReportOptions();
$projectAnalzyer->generated_report_options = [];
\ob_start();
IssueBuffer::finish($projectAnalzyer, false, \microtime(true), false, $baseline);
$output = \ob_get_clean();
$this->assertStringNotContainsString("ERROR", $output, "all issues baselined");
IssueBuffer::clear();
}
}