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::$etcDir = $baseDir . '/etc';
self::$testDir = $baseDir . '/test/php'; self::$testDir = $baseDir . '/test/php';
self::$shareDir = $baseDir . '/share/icinga2-web'; 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) { if (! $modulePaths) {
$modulePaths = array_flip(scandir($modulePath)); $modulePaths = [];
unset($modulePaths['.']); foreach (preg_split('/:/', $modulePath, -1, PREG_SPLIT_NO_EMPTY) as $path) {
unset($modulePaths['..']); $candidates = array_flip(scandir($path));
$modulePaths = array_keys($modulePaths); unset($candidates['.'], $candidates['..']);
foreach ($candidates as $candidate => $_) {
foreach ($modulePaths as &$path) { $modulePaths[] = "$path/$candidate";
$path = "$modulePath/$path"; }
} }
unset($path);
} }
foreach ($modulePaths as $path) { foreach ($modulePaths as $path) {