Skip to content

Commit

Permalink
Limit remote code coverage to src directories of active modules. (#2903)
Browse files Browse the repository at this point in the history
  • Loading branch information
EreMaijala authored May 23, 2023
1 parent ee63a57 commit 98520ae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 9 additions & 2 deletions module/VuFind/functions/codecoverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@
/**
* Setup remote code coverage support if requested
*
* @param array $modules Active modules
*
* @return void
*/
function setupVuFindRemoteCodeCoverage(): void
function setupVuFindRemoteCodeCoverage(array $modules): void
{
if (!($coverageHeader = $_SERVER['HTTP_X_VUFIND_REMOTE_COVERAGE'] ?? null)) {
return;
Expand All @@ -63,7 +65,12 @@ function setupVuFindRemoteCodeCoverage(): void

try {
$filter = new Filter();
$filter->includeDirectory(__DIR__ . '/../../');
foreach ($modules as $module) {
$moduleDir = __DIR__ . "/../../$module";
if (!str_contains($module, '\\') && is_dir($moduleDir)) {
$filter->includeDirectory("$moduleDir/src/");
}
}

$coverage = new CodeCoverage(
(new Selector())->forLineCoverage($filter),
Expand Down
4 changes: 3 additions & 1 deletion public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
} else {
// Setup remote code coverage if enabled:
if (getenv('VUFIND_CODE_COVERAGE')) {
$modules = $app->getServiceManager()
->get(\Laminas\ModuleManager\ModuleManager::class)->getModules();
include __DIR__ . '/../module/VuFind/functions/codecoverage.php';
setupVuFindRemoteCodeCoverage();
setupVuFindRemoteCodeCoverage($modules);
}
$app->run();
}

0 comments on commit 98520ae

Please sign in to comment.