From 0803a1bbdccc95f5af11c1b21b727ef0d12a9cb1 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 18 Jan 2023 12:07:11 +0100 Subject: [PATCH] test: Support multiple paths in `ICINGAWEB_MODULES_DIR` --- library/Icinga/Test/BaseTestCase.php | 9 ++++++++- test/php/bootstrap.php | 15 +++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/library/Icinga/Test/BaseTestCase.php b/library/Icinga/Test/BaseTestCase.php index 6702df02f..d55f4476f 100644 --- a/library/Icinga/Test/BaseTestCase.php +++ b/library/Icinga/Test/BaseTestCase.php @@ -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'; } /** diff --git a/test/php/bootstrap.php b/test/php/bootstrap.php index 6cba6b5cd..293682bb9 100644 --- a/test/php/bootstrap.php +++ b/test/php/bootstrap.php @@ -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) {