Merge pull request #4986 from Icinga/enhance-module-test-compatibility

Enhance module test compatibility
This commit is contained in:
Johannes Meyer 2023-01-18 12:18:54 +01:00 committed by GitHub
commit 04c9edeccc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 18 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) {
@ -92,9 +91,9 @@ foreach ($modulePaths as $path) {
$loader->registerNamespace($moduleNamespace, $moduleLibraryPath);
}
$moduleTestPath = "$path/test/php";
$moduleTestPath = "$path/test/php/Lib";
if (is_dir($moduleTestPath)) {
$loader->registerNamespace('Tests\\' . $moduleNamespace, $moduleTestPath);
$loader->registerNamespace('Tests\\' . $moduleNamespace . '\\Lib', $moduleTestPath);
}
$moduleFormPath = "$path/application/forms";
@ -112,13 +111,6 @@ set_include_path(
)
);
if (! class_exists('Mockery')) {
require_once 'Mockery/Loader.php';
$mockeryLoader = new \Mockery\Loader;
$mockeryLoader->register();
}
require_once 'Zend/Loader/Autoloader.php';
\Zend_Loader_Autoloader::getInstance();