Skip to content

Commit 5325cc0

Browse files
authored
Merge pull request #11 from MaplePHP/develop
Fix: Code Coverage Exclude Path Resolution
2 parents d3f42d5 + 78012d6 commit 5325cc0

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/Console/Controllers/CoverageController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ public function index(RunTestService $service, ResponseInterface $response): Res
2020
return $response;
2121
}
2222

23-
24-
$coverage = new CodeCoverage();
23+
$coverage = new CodeCoverage($this->container->get("request")->getUri()->getDir());
2524
$coverage->start($this->path !== false ? $this->path : null);
2625
$handler = new SilentRender();
2726
$response = $service->run($handler);

src/Support/TestUtils/CodeCoverage.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
class CodeCoverage
2020
{
21+
private ?string $projectRootDir;
2122
private CoverageIssue $coverageIssue = CoverageIssue::None;
2223
private ?array $data = null;
2324
private ?string $path = null;
@@ -47,8 +48,9 @@ class CodeCoverage
4748
".github"
4849
];
4950

50-
public function __construct()
51+
public function __construct(?string $projectRootDir = null)
5152
{
53+
$this->projectRootDir = $projectRootDir;
5254
$this->exclude = self::DEFAULT_EXCLUDED_FILES;
5355
}
5456

@@ -151,7 +153,7 @@ public function end(): void
151153
protected function excludePattern(string $file): bool
152154
{
153155
$filename = basename($file);
154-
156+
$file = str_replace($this->projectRootDir, "", $file);
155157
foreach ($this->exclude as $pattern) {
156158
if (preg_match('#/' . preg_quote($pattern, '#') . '(/|$)#', $file)) {
157159
return true;

0 commit comments

Comments
 (0)