Skip to content

Commit

Permalink
Create MutationExecutionResult instance with real path always, not …
Browse files Browse the repository at this point in the history
…mixed (#1652)

Fixes #1650

Previously, we could have a mix of real paths and relative paths in `MutationExecutionResult` instances. This broke HTML logger, which assumes that all paths are real (absolute), to find the base common path (`Path::getLongestCommonBasePath`).
  • Loading branch information
maks-rafalko committed Jan 20, 2022
1 parent 1e584ea commit c4c7390
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/Logger/Html/StrykerHtmlReportBuilder.php
Expand Up @@ -166,6 +166,9 @@ private function getFiles(): ArrayObject

if ($this->metricsCalculator->getTotalMutantsCount() !== 0) {
$resultsByPath = $this->retrieveResultsByPath();

Assert::minCount($resultsByPath, 1, 'There must be at least one result to build HTML report.');

$basePath = Path::getLongestCommonBasePath(array_keys($resultsByPath));

Assert::string($basePath, '$basePath must be a string');
Expand Down
6 changes: 2 additions & 4 deletions src/Mutation/FileMutationGenerator.php
Expand Up @@ -97,14 +97,12 @@ public function generate(
return;
}

$fileInfo = $trace->getSourceFileInfo();

$initialStatements = $this->parser->parse($fileInfo);
$initialStatements = $this->parser->parse($trace->getSourceFileInfo());

$mutationCollectorVisitor = new MutationCollectorVisitor(
new NodeMutationGenerator(
$mutators,
$fileInfo->getPathname(),
$trace->getRealPath(),
$initialStatements,
$trace,
$onlyCovered,
Expand Down
5 changes: 5 additions & 0 deletions tests/phpunit/Mutation/FileMutationGeneratorTest.php
Expand Up @@ -114,6 +114,11 @@ public function test_it_generates_mutations_for_a_given_file(): void
->method('getAllTestsForMutation')
->willReturn([])
;
$traceMock
->expects($this->once())
->method('getRealPath')
->willReturn(self::FIXTURES_DIR . '/Mutation/OneFile/OneFile.php')
;

$mutationGenerator = SingletonContainer::getContainer()->getFileMutationGenerator();

Expand Down

0 comments on commit c4c7390

Please sign in to comment.