test: Support multiple paths in `ICINGAWEB_MODULES_DIR`

This commit is contained in:
Johannes Meyer 2023-01-18 12:07:11 +01:00
parent 93bac9443d
commit 0803a1bbdc
2 changed files with 15 additions and 9 deletions

View File

@ -133,7 +133,14 @@ namespace Icinga\Test {
self::$etcDir = $baseDir . '/etc';
self::$testDir = $baseDir . '/test/php';
self::$shareDir = $baseDir . '/share/icinga2-web';
self::$moduleDir = getenv('ICINGAWEB_MODULES_DIR') ?: $baseDir . '/modules';
$modulesDir = getenv('ICINGAWEB_MODULES_DIR');
if ($modulesDir && strpos($modulesDir, ':') !== false) {
// Only use the env variable if it contains a single path
$modulesDir = false;
}
self::$moduleDir = $modulesDir ?: $baseDir . '/modules';
}
/**

View File

@ -71,15 +71,14 @@ if ($modulePaths) {
}
if (! $modulePaths) {
$modulePaths = array_flip(scandir($modulePath));
unset($modulePaths['.']);
unset($modulePaths['..']);
$modulePaths = array_keys($modulePaths);
foreach ($modulePaths as &$path) {
$path = "$modulePath/$path";
$modulePaths = [];
foreach (preg_split('/:/', $modulePath, -1, PREG_SPLIT_NO_EMPTY) as $path) {
$candidates = array_flip(scandir($path));
unset($candidates['.'], $candidates['..']);
foreach ($candidates as $candidate => $_) {
$modulePaths[] = "$path/$candidate";
}
}
unset($path);
}
foreach ($modulePaths as $path) {