Refactor php unittest bootstrapping

refs #4639
This commit is contained in:
Johannes Meyer 2014-04-09 10:42:06 +02:00
parent 7708b9901f
commit 0dc4a4f541
3 changed files with 52 additions and 68 deletions

View File

@ -1,67 +0,0 @@
<?php
class TestInit
{
public static function bootstrap()
{
$libaryPath = realpath(dirname(__FILE__) . '/../../library/');
if (!defined('ICINGA_APPDIR')) {
define('ICINGA_APPDIR', realpath($libaryPath . '/../application'));
}
$configPath = realpath($libaryPath . '/../config');
$modulePath = realpath(dirname(__FILE__) . '/../../modules/');
$applicationPath = realpath(dirname(__FILE__) . '/../../application/');
set_include_path(
$libaryPath . ':' . get_include_path()
);
require_once('Icinga/Application/Loader.php');
$loader = new \Icinga\Application\Loader();
$loader->registerNamespace('Icinga', $libaryPath . '/Icinga');
$loader->registerNamespace('Icinga\\Form', $applicationPath . '/forms');
$modules = scandir($modulePath);
foreach ($modules as $module) {
if ($module === '.' || $module === '..') {
continue;
}
$baseNs = 'Icinga\\Module\\' . ucfirst($module);
$moduleLibraryPath = $modulePath . '/' . $module . '/library/' . ucfirst($module);
if (is_dir($moduleLibraryPath)) {
$loader->registerNamespace($baseNs, $moduleLibraryPath);
}
$moduleTestPath = $modulePath . '/' . $module . '/test';
if (is_dir($moduleTestPath)) {
$testNs = $baseNs .= '\\Test';
$loader->registerNamespace($testNs, $moduleTestPath);
}
$moduleFormPath = $modulePath . '/' . $module . '/application/forms';
if (is_dir($moduleFormPath)) {
$formNs = $baseNs .= '\\Form';
$loader->registerNamespace($formNs, $moduleFormPath);
}
}
$loader->register();
require_once 'Zend/Loader/Autoloader.php';
\Zend_Loader_Autoloader::getInstance();
Icinga\Application\Config::$configDir = $configPath;
}
}
TestInit::bootstrap();

51
test/php/bootstrap.php Normal file
View File

@ -0,0 +1,51 @@
<?php
$applicationPath = realpath(dirname(__FILE__) . '/../../application/');
$modulePath = realpath(dirname(__FILE__) . '/../../modules/');
$libraryPath = realpath(dirname(__FILE__) . '/../../library/');
$configPath = realpath($libraryPath . '/../config');
// Is usually done in the application's bootstrap and is used by some of our internals
if (!defined('ICINGA_APPDIR')) {
define('ICINGA_APPDIR', $applicationPath);
}
// This is needed to get the Zend Plugin loader working
set_include_path(implode(PATH_SEPARATOR, array($libraryPath, get_include_path())));
require_once($libraryPath . '/Icinga/Application/Loader.php');
$loader = new Icinga\Application\Loader();
$loader->registerNamespace('Icinga', $libraryPath . '/Icinga');
$loader->registerNamespace('Icinga\\Form', $applicationPath . '/forms');
$modules = scandir($modulePath);
foreach ($modules as $module) {
if ($module === '.' || $module === '..') {
continue;
}
$moduleNamespace = 'Icinga\\Module\\' . ucfirst($module);
$moduleLibraryPath = $modulePath . '/' . $module . '/library/' . ucfirst($module);
if (is_dir($moduleLibraryPath)) {
$loader->registerNamespace($moduleNamespace, $moduleLibraryPath);
}
$moduleTestPath = $modulePath . '/' . $module . '/test';
if (is_dir($moduleTestPath)) {
$loader->registerNamespace($moduleNamespace . '\\Test', $moduleTestPath);
}
$moduleFormPath = $modulePath . '/' . $module . '/application/forms';
if (is_dir($moduleFormPath)) {
$loader->registerNamespace($moduleNamespace . '\\Form', $moduleFormPath);
}
}
$loader->register();
require_once 'Zend/Loader/Autoloader.php';
\Zend_Loader_Autoloader::getInstance();
Icinga\Application\Config::$configDir = $configPath;

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit bootstrap="TestInit.php">
<phpunit bootstrap="bootstrap.php">
<testsuites>
<!--
Unit testing