From 0c364f7866b8521b08c14ffe4133d4ba767dd88b Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Tue, 10 Jul 2018 15:22:47 +0200 Subject: [PATCH] icingacli test php unit: include the classes of all installed modules refs #3494 --- .../application/clicommands/PhpCommand.php | 6 ++++ test/php/bootstrap.php | 29 ++++++++++++++----- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/modules/test/application/clicommands/PhpCommand.php b/modules/test/application/clicommands/PhpCommand.php index a2553943c..926ece7dc 100644 --- a/modules/test/application/clicommands/PhpCommand.php +++ b/modules/test/application/clicommands/PhpCommand.php @@ -186,9 +186,15 @@ class PhpCommand extends Command */ protected function getEnvironmentVariables() { + $modulePaths = []; + foreach (Icinga::app()->getModuleManager()->getModuleInfo() as $module) { + $modulePaths[] = $module->path; + } + $vars = array(); $vars[] = sprintf('ICINGAWEB_BASEDIR=%s', $this->app->getBaseDir()); $vars[] = sprintf('ICINGAWEB_ICINGA_LIB=%s', $this->app->getLibraryDir('Icinga')); + $vars[] = sprintf('ICINGAWEB_MODULE_DIRS=%s', implode(':', $modulePaths)); // Disabled as the bootstrap.php for PHPUnit and class BaseTestCase can't handle multiple paths yet /*$vars[] = sprintf( diff --git a/test/php/bootstrap.php b/test/php/bootstrap.php index 2c805e8b5..6e3345c14 100644 --- a/test/php/bootstrap.php +++ b/test/php/bootstrap.php @@ -35,25 +35,40 @@ $loader->registerNamespace('Tests', $testLibraryPath); $loader->registerNamespace('Icinga', $icingaLibPath); $loader->registerNamespace('Icinga\\Forms', $applicationPath . '/forms'); -$modules = scandir($modulePath); -foreach ($modules as $module) { - if ($module === '.' || $module === '..') { - continue; +$modulePaths = getenv('ICINGAWEB_MODULE_DIRS'); + +if ($modulePaths) { + $modulePaths = preg_split('/:/', $modulePaths, -1, PREG_SPLIT_NO_EMPTY); +} + +if (! $modulePaths) { + $modulePaths = array_flip(scandir($modulePath)); + unset($modulePaths['.']); + unset($modulePaths['..']); + $modulePaths = array_keys($modulePaths); + + foreach ($modulePaths as &$path) { + $path = "$modulePath/$path"; } + unset($path); +} + +foreach ($modulePaths as $path) { + $module = basename($path); $moduleNamespace = 'Icinga\\Module\\' . ucfirst($module); - $moduleLibraryPath = $modulePath . '/' . $module . '/library/' . ucfirst($module); + $moduleLibraryPath = "$path/library/" . ucfirst($module); if (is_dir($moduleLibraryPath)) { $loader->registerNamespace($moduleNamespace, $moduleLibraryPath); } - $moduleTestPath = $modulePath . '/' . $module . '/test/php'; + $moduleTestPath = "$path/test/php"; if (is_dir($moduleTestPath)) { $loader->registerNamespace('Tests\\' . $moduleNamespace, $moduleTestPath); } - $moduleFormPath = $modulePath . '/' . $module . '/application/forms'; + $moduleFormPath = "$path/application/forms"; if (is_dir($moduleFormPath)) { $loader->registerNamespace($moduleNamespace . '\\Forms', $moduleFormPath); }