diff --git a/src/Domain/Common/LineNumber.php b/src/Domain/Common/LineNumber.php index 23674d55..899b814a 100644 --- a/src/Domain/Common/LineNumber.php +++ b/src/Domain/Common/LineNumber.php @@ -31,7 +31,7 @@ class LineNumber */ public function __construct(int $lineNumber) { - Assert::greaterThan($lineNumber, 0, 'Line number must be positive integer. Got: %s'); + Assert::greaterThanEq($lineNumber, 0, 'Line number must be positive integer or 0. Got: %s'); $this->lineNumber = $lineNumber; } diff --git a/src/Plugins/GitDiffHistoryAnalyser/DiffHistoryAnalyser.php b/src/Plugins/GitDiffHistoryAnalyser/DiffHistoryAnalyser.php index 6c3eb324..6902a2e9 100644 --- a/src/Plugins/GitDiffHistoryAnalyser/DiffHistoryAnalyser.php +++ b/src/Plugins/GitDiffHistoryAnalyser/DiffHistoryAnalyser.php @@ -55,7 +55,7 @@ public function getPreviousLocation(Location $location): PreviousLocation return PreviousLocation::fromLocation($location); } - // If file added then + // If file added then this is not in the baseline. if ($fileMutation->isAddedFile()) { return PreviousLocation::noPreviousLocation(); } diff --git a/tests/Unit/Plugins/GitDiffHistoryAnalyser/internal/OriginalLineNameCalculatorTest.php b/tests/Unit/Plugins/GitDiffHistoryAnalyser/internal/OriginalLineNameCalculatorTest.php index 8e75ce56..f50b1894 100644 --- a/tests/Unit/Plugins/GitDiffHistoryAnalyser/internal/OriginalLineNameCalculatorTest.php +++ b/tests/Unit/Plugins/GitDiffHistoryAnalyser/internal/OriginalLineNameCalculatorTest.php @@ -81,4 +81,10 @@ public function testCalculateOriginalLine(int $newLineNumber, ?int $expectedOrig $originalLineNumber = OriginalLineNumberCalculator::calculateOriginalLineNumber($this->fileMutation, $newLineNumber); $this->assertSame($expectedOriginalLineNumber, $originalLineNumber); } + + public function testLineNumber0(): void + { + $originalLineNumber = OriginalLineNumberCalculator::calculateOriginalLineNumber($this->fileMutation, 0); + $this->assertSame(0, $originalLineNumber); + } } diff --git a/tests/Unit/Plugins/PhpstanTextResultsParser/PhpstanTextResultsParserTest.php b/tests/Unit/Plugins/PhpstanTextResultsParser/PhpstanTextResultsParserTest.php index 4a1e6374..b60e7c0f 100644 --- a/tests/Unit/Plugins/PhpstanTextResultsParser/PhpstanTextResultsParserTest.php +++ b/tests/Unit/Plugins/PhpstanTextResultsParser/PhpstanTextResultsParserTest.php @@ -46,11 +46,25 @@ public function testConversionFromString(): void { $analysisResults = $this->phpstanTextResultsParser->convertFromString($this->fileContents, $this->projectRoot); - $this->assertCount(1, $analysisResults->getAnalysisResults()); + $this->assertCount(2, $analysisResults->getAnalysisResults()); $result1 = $analysisResults->getAnalysisResults()[0]; $this->assertTrue($result1->isMatch( + new Location( + new FileName('src/Employee.php'), + new LineNumber(0) + ), + new Type('Class not found and could not be autoloaded.') + )); + $this->assertSame( + 'Class Demo\Foo not found and could not be autoloaded.', + $result1->getMessage() + ); + + $result2 = $analysisResults->getAnalysisResults()[1]; + + $this->assertTrue($result2->isMatch( new Location( new FileName('src/Plugins/PsalmTextResultsParser/PsalmTextResultsParser.php'), new LineNumber(50) @@ -59,7 +73,7 @@ public function testConversionFromString(): void )); $this->assertSame( 'Call to an undefined method DaveLiddament\StaticAnalysisResultsBaseliner\Plugins\PsalmTextResultsParser\PsalmTextResultsParser::processLine().', - $result1->getMessage() + $result2->getMessage() ); } diff --git a/tests/resources/phpstan/phpstan.txt b/tests/resources/phpstan/phpstan.txt index 0ba144ae..4a87e3b0 100644 --- a/tests/resources/phpstan/phpstan.txt +++ b/tests/resources/phpstan/phpstan.txt @@ -1,3 +1,4 @@ +/vagrant/static-analysis-baseliner/src/Employee.php:0:Class Demo\Foo not found and could not be autoloaded. /vagrant/static-analysis-baseliner/src/Plugins/PsalmTextResultsParser/PsalmTextResultsParser.php:50:Call to an undefined method DaveLiddament\StaticAnalysisResultsBaseliner\Plugins\PsalmTextResultsParser\PsalmTextResultsParser::processLine().