icingacli test php unit: include the classes of all installed modules

refs #3494
This commit is contained in:
Alexander A. Klimov 2018-07-10 15:22:47 +02:00
parent 6da5d4173e
commit 0c364f7866
2 changed files with 28 additions and 7 deletions

View File

@ -186,9 +186,15 @@ class PhpCommand extends Command
*/ */
protected function getEnvironmentVariables() protected function getEnvironmentVariables()
{ {
$modulePaths = [];
foreach (Icinga::app()->getModuleManager()->getModuleInfo() as $module) {
$modulePaths[] = $module->path;
}
$vars = array(); $vars = array();
$vars[] = sprintf('ICINGAWEB_BASEDIR=%s', $this->app->getBaseDir()); $vars[] = sprintf('ICINGAWEB_BASEDIR=%s', $this->app->getBaseDir());
$vars[] = sprintf('ICINGAWEB_ICINGA_LIB=%s', $this->app->getLibraryDir('Icinga')); $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 // Disabled as the bootstrap.php for PHPUnit and class BaseTestCase can't handle multiple paths yet
/*$vars[] = sprintf( /*$vars[] = sprintf(

View File

@ -35,25 +35,40 @@ $loader->registerNamespace('Tests', $testLibraryPath);
$loader->registerNamespace('Icinga', $icingaLibPath); $loader->registerNamespace('Icinga', $icingaLibPath);
$loader->registerNamespace('Icinga\\Forms', $applicationPath . '/forms'); $loader->registerNamespace('Icinga\\Forms', $applicationPath . '/forms');
$modules = scandir($modulePath); $modulePaths = getenv('ICINGAWEB_MODULE_DIRS');
foreach ($modules as $module) {
if ($module === '.' || $module === '..') { if ($modulePaths) {
continue; $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); $moduleNamespace = 'Icinga\\Module\\' . ucfirst($module);
$moduleLibraryPath = $modulePath . '/' . $module . '/library/' . ucfirst($module); $moduleLibraryPath = "$path/library/" . ucfirst($module);
if (is_dir($moduleLibraryPath)) { if (is_dir($moduleLibraryPath)) {
$loader->registerNamespace($moduleNamespace, $moduleLibraryPath); $loader->registerNamespace($moduleNamespace, $moduleLibraryPath);
} }
$moduleTestPath = $modulePath . '/' . $module . '/test/php'; $moduleTestPath = "$path/test/php";
if (is_dir($moduleTestPath)) { if (is_dir($moduleTestPath)) {
$loader->registerNamespace('Tests\\' . $moduleNamespace, $moduleTestPath); $loader->registerNamespace('Tests\\' . $moduleNamespace, $moduleTestPath);
} }
$moduleFormPath = $modulePath . '/' . $module . '/application/forms'; $moduleFormPath = "$path/application/forms";
if (is_dir($moduleFormPath)) { if (is_dir($moduleFormPath)) {
$loader->registerNamespace($moduleNamespace . '\\Forms', $moduleFormPath); $loader->registerNamespace($moduleNamespace . '\\Forms', $moduleFormPath);
} }