Skip to content

Commit

Permalink
Merge pull request #32 from DaveLiddament/feature/allow-line-number-0
Browse files Browse the repository at this point in the history
Feature/allow line number 0
  • Loading branch information
DaveLiddament authored Apr 28, 2019
2 parents 9f85513 + 684d3a9 commit 3881247
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Domain/Common/LineNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Plugins/GitDiffHistoryAnalyser/DiffHistoryAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
);
}

Expand Down
1 change: 1 addition & 0 deletions tests/resources/phpstan/phpstan.txt
Original file line number Diff line number Diff line change
@@ -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().

0 comments on commit 3881247

Please sign in to comment.