|
9 | 9 | */ |
10 | 10 | namespace SebastianBergmann\PHPCOV; |
11 | 11 |
|
| 12 | +use const DIRECTORY_SEPARATOR; |
12 | 13 | use const PHP_EOL; |
13 | 14 | use function file_put_contents; |
14 | 15 | use function is_dir; |
@@ -94,17 +95,17 @@ public function run(Arguments $arguments): int |
94 | 95 | print 'done' . PHP_EOL; |
95 | 96 | } |
96 | 97 |
|
97 | | - $this->handleReports($merged['codeCoverage'], $merged['testResults'], $arguments); |
| 98 | + $this->handleReports($merged['codeCoverage'], $merged['testResults'], $merged['basePath'], $arguments); |
98 | 99 |
|
99 | 100 | return 0; |
100 | 101 | } |
101 | 102 |
|
102 | 103 | /** |
103 | 104 | * @param array<string, TestType> $testResults |
104 | 105 | */ |
105 | | - private function handleReports(ProcessedCodeCoverageData $codeCoverage, array $testResults, Arguments $arguments): void |
| 106 | + private function handleReports(ProcessedCodeCoverageData $codeCoverage, array $testResults, string $basePath, Arguments $arguments): void |
106 | 107 | { |
107 | | - $report = $this->buildReport($codeCoverage, $testResults); |
| 108 | + $report = $this->buildReport($codeCoverage, $testResults, $basePath); |
108 | 109 |
|
109 | 110 | if ($arguments->clover() !== null) { |
110 | 111 | print 'Generating code coverage report in Clover XML format ... '; |
@@ -187,8 +188,16 @@ private function handleReports(ProcessedCodeCoverageData $codeCoverage, array $t |
187 | 188 | /** |
188 | 189 | * @param array<string, TestType> $testResults |
189 | 190 | */ |
190 | | - private function buildReport(ProcessedCodeCoverageData $codeCoverage, array $testResults): Directory |
| 191 | + private function buildReport(ProcessedCodeCoverageData $codeCoverage, array $testResults, string $basePath): Directory |
191 | 192 | { |
| 193 | + if ($basePath !== '') { |
| 194 | + $codeCoverage = clone $codeCoverage; |
| 195 | + |
| 196 | + foreach ($codeCoverage->coveredFiles() as $relPath) { |
| 197 | + $codeCoverage->renameFile($relPath, $basePath . DIRECTORY_SEPARATOR . $relPath); |
| 198 | + } |
| 199 | + } |
| 200 | + |
192 | 201 | return (new Builder(new FileAnalyser(new ParsingSourceAnalyser, false, false)))->build($codeCoverage, $testResults); |
193 | 202 | } |
194 | 203 | } |
0 commit comments