diff --git a/library/Icinga/Test/BaseTestCase.php b/library/Icinga/Test/BaseTestCase.php index 8caedf62d..fa7db57bd 100644 --- a/library/Icinga/Test/BaseTestCase.php +++ b/library/Icinga/Test/BaseTestCase.php @@ -117,18 +117,22 @@ namespace Icinga\Test { */ public static function setupDirectories() { - $baseDir = realpath(__DIR__ . '/../../../'); - + $baseDir = getenv('ICINGAWEB_BASEDIR') ?: realpath(__DIR__ . '/../../../'); if ($baseDir === false) { throw new RuntimeException('Application base dir not found'); } + $libDir = getenv('ICINGAWEB_ICINGA_LIB') ?: realpath($baseDir . '/library/Icinga'); + if ($libDir === false) { + throw new RuntimeException('Icinga library dir not found'); + } + self::$appDir = $baseDir . '/application'; - self::$libDir = $baseDir . '/library/Icinga'; + self::$libDir = $libDir; self::$etcDir = $baseDir . '/etc'; self::$testDir = $baseDir . '/test/php'; self::$shareDir = $baseDir . '/share/icinga2-web'; - self::$moduleDir = $baseDir . '/modules'; + self::$moduleDir = getenv('ICINGAWEB_MODULES_DIR') ?: $baseDir . '/modules'; } /** diff --git a/modules/test/application/clicommands/PhpCommand.php b/modules/test/application/clicommands/PhpCommand.php index b9aab4c5b..1ec80de2f 100644 --- a/modules/test/application/clicommands/PhpCommand.php +++ b/modules/test/application/clicommands/PhpCommand.php @@ -70,7 +70,10 @@ class PhpCommand extends Command } chdir(realpath(__DIR__ . '/../..')); - $command = $phpUnit . ' ' . join(' ', array_merge($options, $this->params->getAllStandalone())); + $command = $this->getEnvironmentVariables() . $phpUnit . ' ' . join( + ' ', + array_merge($options, $this->params->getAllStandalone()) + ); if ($this->isVerbose) { $res = `$command`; foreach (preg_split('/\n/', $res) as $line) { @@ -173,4 +176,22 @@ class PhpCommand extends Command return $path; } + + /** + * Setup some required environment variables + */ + protected function getEnvironmentVariables() + { + $vars = array(); + $vars[] = sprintf('ICINGAWEB_BASEDIR=%s', $this->app->getBaseDir()); + $vars[] = sprintf('ICINGAWEB_ICINGA_LIB=%s', $this->app->getLibraryDir('Icinga')); + + // Disabled as the bootstrap.php for PHPUnit and class BaseTestCase can't handle multiple paths yet + /*$vars[] = sprintf( + 'ICINGAWEB_MODULES_DIR=%s', + implode(PATH_SEPARATOR, $this->app->getModuleManager()->getModuleDirs()) + );*/ + + return join(' ', $vars) . ' '; + } } diff --git a/test/php/bootstrap.php b/test/php/bootstrap.php index 954387012..580013fd2 100644 --- a/test/php/bootstrap.php +++ b/test/php/bootstrap.php @@ -1,11 +1,13 @@ register(); -require_once($libraryPath . '/Icinga/Test/ClassLoader.php'); +require_once($icingaLibPath . '/Test/ClassLoader.php'); $loader = new Icinga\Test\ClassLoader(); $loader->registerNamespace('Tests', $testLibraryPath); -$loader->registerNamespace('Icinga', $libraryPath . '/Icinga'); +$loader->registerNamespace('Icinga', $icingaLibPath); $loader->registerNamespace('Icinga\\Forms', $applicationPath . '/forms'); $modules = scandir($modulePath); diff --git a/test/php/library/Icinga/Web/Paginator/ScrollingStyle/SlidingWithBorderTest.php b/test/php/library/Icinga/Web/Paginator/ScrollingStyle/SlidingWithBorderTest.php index a5b9be6cc..93fc2b171 100644 --- a/test/php/library/Icinga/Web/Paginator/ScrollingStyle/SlidingWithBorderTest.php +++ b/test/php/library/Icinga/Web/Paginator/ScrollingStyle/SlidingWithBorderTest.php @@ -3,12 +3,12 @@ namespace Tests\Icinga\Web\Paginator\ScrollingStyle; -require_once realpath(ICINGA_LIBDIR . '/Icinga/Web/Paginator/ScrollingStyle/SlidingWithBorder.php'); - use Mockery; use Zend_Paginator; use Icinga\Test\BaseTestCase; +require_once realpath(BaseTestCase::$libDir . '/Web/Paginator/ScrollingStyle/SlidingWithBorder.php'); + class SlidingwithborderTest extends BaseTestCase { public function testGetPages2()