2018-10-30 15:32:20 +01:00
|
|
|
<?php
|
2021-12-15 04:58:32 +01:00
|
|
|
|
2018-10-30 15:32:20 +01:00
|
|
|
namespace Psalm\Tests;
|
|
|
|
|
2021-12-03 21:40:18 +01:00
|
|
|
use DOMDocument;
|
2022-12-21 04:59:35 +01:00
|
|
|
use DOMElement;
|
2022-11-25 02:20:21 +01:00
|
|
|
use Mockery;
|
|
|
|
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
|
|
|
|
use Mockery\MockInterface;
|
2018-10-30 15:32:20 +01:00
|
|
|
use Psalm\ErrorBaseline;
|
|
|
|
use Psalm\Exception\ConfigException;
|
2021-12-03 20:11:20 +01:00
|
|
|
use Psalm\Internal\Analyzer\IssueData;
|
2018-11-06 03:57:36 +01:00
|
|
|
use Psalm\Internal\Provider\FileProvider;
|
2020-08-23 16:32:07 +02:00
|
|
|
use Psalm\Internal\RuntimeCaches;
|
2018-10-30 15:32:20 +01:00
|
|
|
|
2022-12-21 04:59:35 +01:00
|
|
|
use function count;
|
|
|
|
|
2020-08-25 00:02:39 +02:00
|
|
|
use const LIBXML_NOBLANKS;
|
|
|
|
|
2018-10-30 15:32:20 +01:00
|
|
|
class ErrorBaselineTest extends TestCase
|
|
|
|
{
|
2022-11-25 02:20:21 +01:00
|
|
|
use MockeryPHPUnitIntegration;
|
2020-08-25 00:02:39 +02:00
|
|
|
|
2022-11-25 02:20:21 +01:00
|
|
|
/** @var FileProvider&MockInterface */
|
2018-10-30 15:32:20 +01:00
|
|
|
private $fileProvider;
|
|
|
|
|
2021-12-05 18:51:26 +01:00
|
|
|
public function setUp(): void
|
2018-10-30 15:32:20 +01:00
|
|
|
{
|
2020-08-23 16:32:07 +02:00
|
|
|
RuntimeCaches::clearAll();
|
2022-11-25 02:20:21 +01:00
|
|
|
$this->fileProvider = Mockery::mock(FileProvider::class);
|
2018-10-30 15:32:20 +01:00
|
|
|
}
|
|
|
|
|
2021-11-26 20:59:41 +01:00
|
|
|
public function testLoadShouldParseXmlBaselineToPhpArray(): void
|
2018-10-30 15:32:20 +01:00
|
|
|
{
|
|
|
|
$baselineFilePath = 'baseline.xml';
|
|
|
|
|
2022-11-25 02:20:21 +01:00
|
|
|
$this->fileProvider->allows()->fileExists($baselineFilePath)->andReturns(true);
|
|
|
|
$this->fileProvider->allows()->getContents($baselineFilePath)->andReturns(
|
2018-10-30 15:32:20 +01:00
|
|
|
'<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<files>
|
|
|
|
<file src="sample/sample-file.php">
|
2022-12-21 04:59:35 +01:00
|
|
|
<MixedAssignment>
|
2018-11-09 06:46:13 +01:00
|
|
|
<code>foo</code>
|
|
|
|
<code>bar</code>
|
|
|
|
</MixedAssignment>
|
2018-10-30 15:32:20 +01:00
|
|
|
<InvalidReturnStatement occurrences="1"/>
|
|
|
|
</file>
|
2019-01-10 06:10:09 +01:00
|
|
|
<file src="sample\sample-file2.php">
|
2022-12-21 04:59:35 +01:00
|
|
|
<PossiblyUnusedMethod>
|
2018-11-09 06:46:13 +01:00
|
|
|
<code>foo</code>
|
|
|
|
<code>bar</code>
|
|
|
|
</PossiblyUnusedMethod>
|
2018-10-30 15:32:20 +01:00
|
|
|
</file>
|
2022-12-18 17:15:15 +01:00
|
|
|
</files>',
|
2018-10-30 15:32:20 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$expectedParsedBaseline = [
|
|
|
|
'sample/sample-file.php' => [
|
2018-11-09 06:46:13 +01:00
|
|
|
'MixedAssignment' => ['o' => 2, 's' => ['foo', 'bar']],
|
|
|
|
'InvalidReturnStatement' => ['o' => 1, 's' => []],
|
2018-10-30 15:32:20 +01:00
|
|
|
],
|
|
|
|
'sample/sample-file2.php' => [
|
2018-11-09 06:46:13 +01:00
|
|
|
'PossiblyUnusedMethod' => ['o' => 2, 's' => ['foo', 'bar']],
|
2018-10-30 15:32:20 +01:00
|
|
|
],
|
|
|
|
];
|
|
|
|
|
2019-03-23 19:27:54 +01:00
|
|
|
$this->assertSame(
|
2018-10-30 15:32:20 +01:00
|
|
|
$expectedParsedBaseline,
|
2022-12-18 17:15:15 +01:00
|
|
|
ErrorBaseline::read($this->fileProvider, $baselineFilePath),
|
2018-10-30 15:32:20 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-06-26 22:59:40 +02:00
|
|
|
public function testLoadShouldIgnoreLineEndingsInIssueSnippet(): void
|
|
|
|
{
|
|
|
|
$baselineFilePath = 'baseline.xml';
|
|
|
|
|
2022-11-25 02:20:21 +01:00
|
|
|
$this->fileProvider->allows()->fileExists($baselineFilePath)->andReturns(true);
|
|
|
|
$this->fileProvider->allows()->getContents($baselineFilePath)->andReturns(
|
2021-06-26 22:59:40 +02:00
|
|
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
|
|
|
<files>
|
|
|
|
<file src=\"sample/sample-file.php\">
|
2022-12-21 04:59:35 +01:00
|
|
|
<MixedAssignment>
|
2021-06-26 22:59:40 +02:00
|
|
|
<code>foo\r</code>
|
|
|
|
</MixedAssignment>
|
|
|
|
</file>
|
2022-12-18 17:15:15 +01:00
|
|
|
</files>",
|
2021-06-26 22:59:40 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$expectedParsedBaseline = [
|
|
|
|
'sample/sample-file.php' => [
|
|
|
|
'MixedAssignment' => ['o' => 1, 's' => ['foo']],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
$expectedParsedBaseline,
|
2023-03-28 14:40:11 +02:00
|
|
|
ErrorBaseline::read($this->fileProvider, $baselineFilePath),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testShouldIgnoreCarriageReturnInMultilineSnippets(): void
|
|
|
|
{
|
|
|
|
$baselineFilePath = 'baseline.xml';
|
|
|
|
|
|
|
|
$this->fileProvider->allows()->fileExists($baselineFilePath)->andReturns(true);
|
|
|
|
$this->fileProvider->allows()->getContents($baselineFilePath)->andReturns(
|
|
|
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
|
|
|
<files>
|
|
|
|
<file src=\"sample/sample-file.php\">
|
|
|
|
<MixedAssignment>
|
|
|
|
<code>
|
|
|
|
foo
|
|
|
|
bar
|
|
|
|
</code>
|
|
|
|
</MixedAssignment>
|
|
|
|
</file>
|
|
|
|
</files>",
|
|
|
|
);
|
|
|
|
|
|
|
|
$expectedParsedBaseline = [
|
|
|
|
'sample/sample-file.php' => [
|
|
|
|
'MixedAssignment' => ['o' => 1, 's' => ["foo\nbar"]],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
$expectedParsedBaseline,
|
2022-12-18 17:15:15 +01:00
|
|
|
ErrorBaseline::read($this->fileProvider, $baselineFilePath),
|
2021-06-26 22:59:40 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-11-26 20:59:41 +01:00
|
|
|
public function testLoadShouldThrowExceptionWhenFilesAreNotDefinedInBaselineFile(): void
|
2018-10-30 15:32:20 +01:00
|
|
|
{
|
|
|
|
$this->expectException(ConfigException::class);
|
|
|
|
|
|
|
|
$baselineFile = 'baseline.xml';
|
|
|
|
|
2022-11-25 02:20:21 +01:00
|
|
|
$this->fileProvider->allows()->fileExists($baselineFile)->andReturns(true);
|
|
|
|
$this->fileProvider->allows()->getContents($baselineFile)->andReturns(
|
2018-10-30 15:32:20 +01:00
|
|
|
'<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<other>
|
|
|
|
</other>
|
2022-12-18 17:15:15 +01:00
|
|
|
',
|
2018-10-30 15:32:20 +01:00
|
|
|
);
|
|
|
|
|
2022-11-25 02:20:21 +01:00
|
|
|
ErrorBaseline::read($this->fileProvider, $baselineFile);
|
2018-10-30 15:32:20 +01:00
|
|
|
}
|
|
|
|
|
2021-11-26 20:59:41 +01:00
|
|
|
public function testLoadShouldThrowExceptionWhenBaselineFileDoesNotExist(): void
|
2018-10-30 15:32:20 +01:00
|
|
|
{
|
|
|
|
$this->expectException(ConfigException::class);
|
|
|
|
|
|
|
|
$baselineFile = 'baseline.xml';
|
|
|
|
|
2022-11-25 02:20:21 +01:00
|
|
|
$this->fileProvider->expects()->fileExists($baselineFile)->andReturns(false);
|
2018-10-30 15:32:20 +01:00
|
|
|
|
2022-11-25 02:20:21 +01:00
|
|
|
ErrorBaseline::read($this->fileProvider, $baselineFile);
|
2018-10-30 15:32:20 +01:00
|
|
|
}
|
|
|
|
|
2021-11-26 20:59:41 +01:00
|
|
|
public function testCountTotalIssuesShouldReturnCorrectNumber(): void
|
2019-02-09 12:13:58 +01:00
|
|
|
{
|
|
|
|
$existingIssues = [
|
|
|
|
'sample/sample-file.php' => [
|
|
|
|
'MixedAssignment' => ['o' => 2, 's' => ['bar']],
|
|
|
|
'MixedOperand' => ['o' => 2, 's' => []],
|
|
|
|
],
|
|
|
|
'sample/sample-file2.php' => [
|
|
|
|
'TypeCoercion' => ['o' => 1, 's' => []],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
$totalIssues = ErrorBaseline::countTotalIssues($existingIssues);
|
|
|
|
|
2019-03-23 19:27:54 +01:00
|
|
|
$this->assertSame($totalIssues, 5);
|
2019-02-09 12:13:58 +01:00
|
|
|
}
|
|
|
|
|
2021-11-26 20:59:41 +01:00
|
|
|
public function testCreateShouldAggregateIssuesPerFile(): void
|
2018-10-30 15:32:20 +01:00
|
|
|
{
|
|
|
|
$baselineFile = 'baseline.xml';
|
|
|
|
|
2022-11-25 02:20:21 +01:00
|
|
|
$this->fileProvider = Mockery::spy(FileProvider::class);
|
2018-10-30 15:32:20 +01:00
|
|
|
|
|
|
|
|
2020-01-22 03:22:38 +01:00
|
|
|
ErrorBaseline::create(
|
2022-11-25 02:20:21 +01:00
|
|
|
$this->fileProvider,
|
2020-01-22 03:22:38 +01:00
|
|
|
$baselineFile,
|
2018-10-30 15:32:20 +01:00
|
|
|
[
|
2020-01-22 03:22:38 +01:00
|
|
|
'sample/sample-file.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,
|
|
|
|
'MixedAssignment',
|
|
|
|
'Message',
|
|
|
|
'sample/sample-file.php',
|
|
|
|
'sample/sample-file.php',
|
|
|
|
'foo',
|
|
|
|
'foo',
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
2022-12-18 17:15:15 +01:00
|
|
|
0,
|
2020-02-17 00:24:40 +01:00
|
|
|
),
|
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,
|
|
|
|
'MixedAssignment',
|
|
|
|
'Message',
|
|
|
|
'sample/sample-file.php',
|
|
|
|
'sample/sample-file.php',
|
|
|
|
'bar',
|
|
|
|
'bar',
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
2022-12-18 17:15:15 +01:00
|
|
|
0,
|
2020-02-17 00:24:40 +01:00
|
|
|
),
|
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,
|
|
|
|
'MixedAssignment',
|
|
|
|
'Message',
|
|
|
|
'sample/sample-file.php',
|
|
|
|
'sample/sample-file.php',
|
|
|
|
'bat',
|
|
|
|
'bat',
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
2022-12-18 17:15:15 +01:00
|
|
|
0,
|
2020-02-17 00:24:40 +01:00
|
|
|
),
|
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,
|
|
|
|
'MixedOperand',
|
|
|
|
'Message',
|
|
|
|
'sample/sample-file.php',
|
|
|
|
'sample/sample-file.php',
|
|
|
|
'bing',
|
|
|
|
'bing',
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
2022-12-18 17:15:15 +01:00
|
|
|
0,
|
2020-02-17 00:24:40 +01:00
|
|
|
),
|
2021-12-03 20:11:20 +01:00
|
|
|
new IssueData(
|
2020-02-17 00:24:40 +01:00
|
|
|
'info',
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
'AssignmentToVoid',
|
|
|
|
'Message',
|
|
|
|
'sample/sample-file.php',
|
|
|
|
'sample/sample-file.php',
|
|
|
|
'bong',
|
|
|
|
'bong',
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
2022-12-18 17:15:15 +01:00
|
|
|
0,
|
2020-02-17 00:24:40 +01:00
|
|
|
),
|
2020-01-22 03:22:38 +01:00
|
|
|
],
|
|
|
|
'sample/sample-file2.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,
|
|
|
|
'MixedAssignment',
|
|
|
|
'Message',
|
|
|
|
'sample/sample-file2.php',
|
|
|
|
'sample/sample-file2.php',
|
|
|
|
'boardy',
|
|
|
|
'boardy',
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
2022-12-18 17:15:15 +01:00
|
|
|
0,
|
2020-02-17 00:24:40 +01:00
|
|
|
),
|
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,
|
|
|
|
'MixedAssignment',
|
|
|
|
'Message',
|
|
|
|
'sample/sample-file2.php',
|
|
|
|
'sample/sample-file2.php',
|
|
|
|
'bardy',
|
|
|
|
'bardy',
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
2022-12-18 17:15:15 +01:00
|
|
|
0,
|
2020-02-17 00:24:40 +01:00
|
|
|
),
|
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,
|
|
|
|
'TypeCoercion',
|
|
|
|
'Message',
|
|
|
|
'sample/sample-file2.php',
|
|
|
|
'sample/sample-file2.php',
|
|
|
|
'hardy' . "\n",
|
|
|
|
'hardy' . "\n",
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
2022-12-18 17:15:15 +01:00
|
|
|
0,
|
2020-02-17 00:24:40 +01:00
|
|
|
),
|
2020-01-22 03:22:38 +01:00
|
|
|
],
|
2018-10-30 15:32:20 +01:00
|
|
|
],
|
2022-12-18 17:15:15 +01:00
|
|
|
false,
|
2020-01-22 03:22:38 +01:00
|
|
|
);
|
2018-10-30 15:32:20 +01:00
|
|
|
|
2022-11-25 02:20:21 +01:00
|
|
|
$this->fileProvider->shouldHaveReceived()
|
|
|
|
->setContents(
|
|
|
|
$baselineFile,
|
|
|
|
Mockery::on(function (string $document): bool {
|
|
|
|
$baselineDocument = new DOMDocument();
|
|
|
|
$baselineDocument->loadXML($document, LIBXML_NOBLANKS);
|
|
|
|
|
|
|
|
/** @var DOMElement[] $files */
|
|
|
|
$files = $baselineDocument->getElementsByTagName('files')[0]->childNodes;
|
|
|
|
|
|
|
|
[$file1, $file2] = $files;
|
|
|
|
|
|
|
|
$this->assertSame('sample/sample-file.php', $file1->getAttribute('src'));
|
|
|
|
$this->assertSame('sample/sample-file2.php', $file2->getAttribute('src'));
|
|
|
|
|
|
|
|
/** @var DOMElement[] $file1Issues */
|
|
|
|
$file1Issues = $file1->childNodes;
|
|
|
|
/** @var DOMElement[] $file2Issues */
|
|
|
|
$file2Issues = $file2->childNodes;
|
|
|
|
|
|
|
|
$this->assertSame('MixedAssignment', $file1Issues[0]->tagName);
|
|
|
|
$this->assertSame(
|
2022-12-21 04:59:35 +01:00
|
|
|
3,
|
|
|
|
count($file1Issues[0]->getElementsByTagName('code')),
|
2022-12-18 17:15:15 +01:00
|
|
|
'MixedAssignment should have occured 3 times',
|
2022-11-25 02:20:21 +01:00
|
|
|
);
|
|
|
|
$this->assertSame('MixedOperand', $file1Issues[1]->tagName);
|
|
|
|
$this->assertSame(
|
2022-12-21 04:59:35 +01:00
|
|
|
1,
|
|
|
|
count($file1Issues[1]->getElementsByTagName('code')),
|
2022-12-18 17:15:15 +01:00
|
|
|
'MixedOperand should have occured 1 time',
|
2022-11-25 02:20:21 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertSame('MixedAssignment', $file2Issues[0]->tagName);
|
|
|
|
$this->assertSame(
|
2022-12-21 04:59:35 +01:00
|
|
|
2,
|
|
|
|
count($file2Issues[0]->getElementsByTagName('code')),
|
2022-11-25 02:20:21 +01:00
|
|
|
'MixedAssignment should have occured 2 times',
|
|
|
|
);
|
|
|
|
$this->assertSame('TypeCoercion', $file2Issues[1]->tagName);
|
|
|
|
$this->assertSame(
|
2022-12-21 04:59:35 +01:00
|
|
|
1,
|
|
|
|
count($file2Issues[1]->getElementsByTagName('code')),
|
2022-12-18 17:15:15 +01:00
|
|
|
'TypeCoercion should have occured 1 time',
|
2022-11-25 02:20:21 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
return true;
|
2022-12-18 17:15:15 +01:00
|
|
|
}),
|
2022-11-25 02:20:21 +01:00
|
|
|
);
|
2018-10-30 15:32:20 +01:00
|
|
|
}
|
|
|
|
|
2021-11-26 20:59:41 +01:00
|
|
|
public function testUpdateShouldRemoveExistingIssuesWithoutAddingNewOnes(): void
|
2018-10-30 15:32:20 +01:00
|
|
|
{
|
|
|
|
$baselineFile = 'baseline.xml';
|
|
|
|
|
2022-11-25 02:20:21 +01:00
|
|
|
$this->fileProvider->allows()->fileExists($baselineFile)->andReturns(true);
|
|
|
|
$this->fileProvider->allows()->getContents($baselineFile)->andReturns(
|
2018-10-30 15:32:20 +01:00
|
|
|
'<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<files>
|
|
|
|
<file src="sample/sample-file.php">
|
2018-11-09 06:46:13 +01:00
|
|
|
<MixedAssignment occurrences="3">
|
|
|
|
<code>bar</code>
|
|
|
|
<code>bat</code>
|
|
|
|
</MixedAssignment>
|
2018-10-30 15:32:20 +01:00
|
|
|
<MixedOperand occurrences="1"/>
|
|
|
|
</file>
|
|
|
|
<file src="sample/sample-file2.php">
|
|
|
|
<MixedAssignment occurrences="2"/>
|
|
|
|
<TypeCoercion occurrences="1"/>
|
|
|
|
</file>
|
|
|
|
<file src="sample/sample-file3.php">
|
|
|
|
<MixedAssignment occurrences="1"/>
|
|
|
|
</file>
|
2022-12-18 17:15:15 +01:00
|
|
|
</files>',
|
2018-10-30 15:32:20 +01:00
|
|
|
);
|
2022-11-25 02:20:21 +01:00
|
|
|
|
|
|
|
$this->fileProvider->allows()->setContents(Mockery::andAnyOtherArgs());
|
2018-10-30 15:32:20 +01:00
|
|
|
|
|
|
|
$newIssues = [
|
2020-01-22 03:22:38 +01:00
|
|
|
'sample/sample-file.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,
|
|
|
|
'MixedAssignment',
|
|
|
|
'Message',
|
|
|
|
'sample/sample-file.php',
|
|
|
|
'sample/sample-file.php',
|
|
|
|
'foo',
|
|
|
|
'foo',
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
2022-12-18 17:15:15 +01:00
|
|
|
0,
|
2020-02-17 00:24:40 +01:00
|
|
|
),
|
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,
|
|
|
|
'MixedAssignment',
|
|
|
|
'Message',
|
|
|
|
'sample/sample-file.php',
|
|
|
|
'sample/sample-file.php',
|
|
|
|
'bar',
|
|
|
|
'bar',
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
2022-12-18 17:15:15 +01:00
|
|
|
0,
|
2020-02-17 00:24:40 +01:00
|
|
|
),
|
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,
|
|
|
|
'MixedOperand',
|
|
|
|
'Message',
|
|
|
|
'sample/sample-file.php',
|
|
|
|
'sample/sample-file.php',
|
|
|
|
'bat',
|
|
|
|
'bat',
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
2022-12-18 17:15:15 +01:00
|
|
|
0,
|
2020-02-17 00:24:40 +01:00
|
|
|
),
|
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,
|
|
|
|
'MixedOperand',
|
|
|
|
'Message',
|
|
|
|
'sample/sample-file.php',
|
|
|
|
'sample/sample-file.php',
|
|
|
|
'bam',
|
|
|
|
'bam',
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
2022-12-18 17:15:15 +01:00
|
|
|
0,
|
2020-02-17 00:24:40 +01:00
|
|
|
),
|
2018-10-30 15:32:20 +01:00
|
|
|
],
|
2020-01-22 03:22:38 +01:00
|
|
|
'sample/sample-file2.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,
|
|
|
|
'TypeCoercion',
|
|
|
|
'Message',
|
|
|
|
'sample/sample-file2.php',
|
|
|
|
'sample/sample-file2.php',
|
|
|
|
'tar',
|
|
|
|
'tar',
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
2022-12-18 17:15:15 +01:00
|
|
|
0,
|
2020-02-17 00:24:40 +01:00
|
|
|
),
|
2018-10-30 15:32:20 +01:00
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
$remainingBaseline = ErrorBaseline::update(
|
2022-11-25 02:20:21 +01:00
|
|
|
$this->fileProvider,
|
2018-10-30 15:32:20 +01:00
|
|
|
$baselineFile,
|
2019-07-11 16:41:44 +02:00
|
|
|
$newIssues,
|
2022-12-18 17:15:15 +01:00
|
|
|
false,
|
2018-10-30 15:32:20 +01:00
|
|
|
);
|
|
|
|
|
2019-03-23 19:27:54 +01:00
|
|
|
$this->assertSame([
|
2018-10-30 15:32:20 +01:00
|
|
|
'sample/sample-file.php' => [
|
2018-11-09 06:46:13 +01:00
|
|
|
'MixedAssignment' => ['o' => 2, 's' => ['bar']],
|
|
|
|
'MixedOperand' => ['o' => 1, 's' => []],
|
2018-10-30 15:32:20 +01:00
|
|
|
],
|
|
|
|
'sample/sample-file2.php' => [
|
2018-11-09 06:46:13 +01:00
|
|
|
'TypeCoercion' => ['o' => 1, 's' => []],
|
2018-10-30 15:32:20 +01:00
|
|
|
],
|
|
|
|
], $remainingBaseline);
|
|
|
|
}
|
2019-11-07 19:03:18 +01:00
|
|
|
|
2021-11-26 20:59:41 +01:00
|
|
|
public function testAddingACommentInBaselineDoesntTriggerNotice(): void
|
2019-11-07 19:03:18 +01:00
|
|
|
{
|
|
|
|
$baselineFilePath = 'baseline.xml';
|
|
|
|
|
2022-11-25 02:20:21 +01:00
|
|
|
$this->fileProvider->allows()->fileExists($baselineFilePath)->andReturns(true);
|
|
|
|
$this->fileProvider->allows()->getContents($baselineFilePath)->andReturns(
|
2019-11-07 19:03:18 +01:00
|
|
|
'<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<files>
|
|
|
|
<file src="sample/sample-file.php">
|
|
|
|
<!-- here is a comment ! //-->
|
2022-12-21 04:59:35 +01:00
|
|
|
<MixedAssignment>
|
2019-11-07 19:03:18 +01:00
|
|
|
<code>foo</code>
|
|
|
|
<code>bar</code>
|
|
|
|
</MixedAssignment>
|
|
|
|
<InvalidReturnStatement occurrences="1"/>
|
|
|
|
</file>
|
|
|
|
<!-- And another one ! //-->
|
|
|
|
<file src="sample\sample-file2.php">
|
2022-12-21 04:59:35 +01:00
|
|
|
<PossiblyUnusedMethod>
|
2019-11-07 19:03:18 +01:00
|
|
|
<code>foo</code>
|
|
|
|
<code>bar</code>
|
|
|
|
</PossiblyUnusedMethod>
|
|
|
|
</file>
|
2022-12-18 17:15:15 +01:00
|
|
|
</files>',
|
2019-11-07 19:03:18 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$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,
|
2022-12-18 17:15:15 +01:00
|
|
|
ErrorBaseline::read($this->fileProvider, $baselineFilePath),
|
2019-11-07 19:03:18 +01:00
|
|
|
);
|
|
|
|
}
|
2018-10-30 15:32:20 +01:00
|
|
|
}
|