2020-01-29 14:53:58 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Psalm\Tests;
|
|
|
|
|
|
|
|
use Psalm\Codebase;
|
|
|
|
use Psalm\Config;
|
2021-12-03 20:11:20 +01:00
|
|
|
use Psalm\Internal\Analyzer\IssueData;
|
2020-01-29 14:53:58 +01:00
|
|
|
use Psalm\Internal\Analyzer\ProjectAnalyzer;
|
|
|
|
use Psalm\Internal\Codebase\Analyzer;
|
2021-01-06 15:05:53 +01:00
|
|
|
use Psalm\Internal\EventDispatcher;
|
2020-01-29 14:53:58 +01:00
|
|
|
use Psalm\IssueBuffer;
|
|
|
|
use Psalm\Report\ReportOptions;
|
|
|
|
|
2021-12-03 21:07:25 +01:00
|
|
|
use function microtime;
|
|
|
|
use function ob_get_clean;
|
|
|
|
use function ob_start;
|
|
|
|
|
2020-01-29 14:53:58 +01:00
|
|
|
class IssueBufferTest extends TestCase
|
|
|
|
{
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testFinishDoesNotCorruptInternalState(): void
|
2020-01-29 14:53:58 +01:00
|
|
|
{
|
|
|
|
IssueBuffer::clear();
|
|
|
|
IssueBuffer::addIssues([
|
|
|
|
'/path/one.php' => [
|
2021-12-03 20:11:20 +01:00
|
|
|
new IssueData(
|
2023-05-31 12:38:15 +02:00
|
|
|
IssueData::SEVERITY_ERROR,
|
2020-02-17 00:24:40 +01:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
"MissingPropertyType",
|
|
|
|
'Message',
|
|
|
|
"one.php",
|
|
|
|
"/path/one.php",
|
|
|
|
"snippet-1",
|
|
|
|
"snippet-1",
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
2022-12-18 17:15:15 +01:00
|
|
|
0,
|
|
|
|
),
|
2020-01-29 14:53:58 +01:00
|
|
|
],
|
|
|
|
'/path/two.php' => [
|
2021-12-03 20:11:20 +01:00
|
|
|
new IssueData(
|
2023-05-31 12:38:15 +02:00
|
|
|
IssueData::SEVERITY_ERROR,
|
2020-02-17 00:24:40 +01:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
"MissingPropertyType",
|
|
|
|
'Message',
|
|
|
|
"two.php",
|
|
|
|
"/path/two.php",
|
|
|
|
"snippet-2",
|
|
|
|
"snippet-2",
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
2022-12-18 17:15:15 +01:00
|
|
|
0,
|
|
|
|
),
|
2021-06-26 22:59:40 +02:00
|
|
|
],
|
|
|
|
'/path/three.php' => [
|
2021-12-03 20:11:20 +01:00
|
|
|
new IssueData(
|
2023-05-31 12:38:15 +02:00
|
|
|
IssueData::SEVERITY_ERROR,
|
2021-06-26 22:59:40 +02:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
"MissingPropertyType",
|
|
|
|
'Message',
|
|
|
|
"three.php",
|
|
|
|
"/path/three.php",
|
2021-06-27 01:08:03 +02:00
|
|
|
"snippet-3-has-carriage-return\r",
|
|
|
|
"snippet-3-has-carriage-return\r",
|
2021-06-26 22:59:40 +02:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
2022-12-18 17:15:15 +01:00
|
|
|
0,
|
|
|
|
),
|
2021-06-26 22:59:40 +02:00
|
|
|
],
|
2023-03-24 10:48:03 +01:00
|
|
|
'/path/four.php' => [
|
|
|
|
new IssueData(
|
2023-05-31 12:38:15 +02:00
|
|
|
IssueData::SEVERITY_ERROR,
|
2023-03-24 10:48:03 +01:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
"MissingPropertyType",
|
|
|
|
'Message',
|
|
|
|
"four.php",
|
|
|
|
"/path/four.php",
|
|
|
|
"snippet-4-multiline\r\nwith-carriage-return\r",
|
|
|
|
"snippet-4-multiline\r\nwith-carriage-return\r",
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
),
|
|
|
|
],
|
2020-01-29 14:53:58 +01:00
|
|
|
]);
|
|
|
|
$baseline = [
|
|
|
|
'one.php' => ['MissingPropertyType' => ['o' => 1, 's' => ['snippet-1']] ],
|
|
|
|
'two.php' => ['MissingPropertyType' => ['o' => 1, 's' => ['snippet-2']] ],
|
2021-06-26 22:59:40 +02:00
|
|
|
'three.php' => ['MissingPropertyType' => ['o' => 1, 's' => ['snippet-3-has-carriage-return']] ],
|
2023-03-24 10:48:03 +01:00
|
|
|
'four.php' => ['MissingPropertyType' => ['o' => 1, 's' => ["snippet-4-multiline\nwith-carriage-return"]] ],
|
2020-01-29 14:53:58 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
$analyzer = $this->createMock(Analyzer::class);
|
|
|
|
$analyzer->method('getTotalTypeCoverage')->willReturn([0, 0]);
|
|
|
|
|
2021-01-06 15:05:53 +01:00
|
|
|
$eventDispatcher = $this->createMock(EventDispatcher::class);
|
|
|
|
|
2020-01-29 14:53:58 +01:00
|
|
|
$config = $this->createMock(Config::class);
|
2021-01-06 15:05:53 +01:00
|
|
|
$config->eventDispatcher = $eventDispatcher;
|
2020-01-29 14:53:58 +01:00
|
|
|
|
|
|
|
$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 = [];
|
|
|
|
|
2021-12-03 21:07:25 +01:00
|
|
|
ob_start();
|
|
|
|
IssueBuffer::finish($projectAnalzyer, false, microtime(true), false, $baseline);
|
2023-10-09 22:44:31 +02:00
|
|
|
$output = (string) ob_get_clean();
|
2020-01-29 14:53:58 +01:00
|
|
|
$this->assertStringNotContainsString("ERROR", $output, "all issues baselined");
|
|
|
|
IssueBuffer::clear();
|
|
|
|
}
|
2021-12-13 19:09:32 +01:00
|
|
|
|
|
|
|
public function testPrintSuccessMessageWorks(): void
|
|
|
|
{
|
2022-02-09 14:35:40 +01:00
|
|
|
$project_analyzer = $this->createMock(ProjectAnalyzer::class);
|
|
|
|
$project_analyzer->stdout_report_options = new ReportOptions;
|
2021-12-13 19:09:32 +01:00
|
|
|
ob_start();
|
2022-02-09 14:35:40 +01:00
|
|
|
IssueBuffer::printSuccessMessage($project_analyzer);
|
2023-10-09 22:44:31 +02:00
|
|
|
$output = (string) ob_get_clean();
|
2021-12-13 19:09:32 +01:00
|
|
|
|
|
|
|
$this->assertStringContainsString('No errors found!', $output);
|
|
|
|
}
|
2020-01-29 14:53:58 +01:00
|
|
|
}
|