icingaweb2/test/php/library/Icinga/LibraryLoader.php
Jannis Moßhammer 5827cb37cb Fix statusdat tests and implementation
After moving StatusDat to monitoring/Backends and changing the
inheritance to Library/Icinga/Data, a few changes must be reflected in the tests:
- Move tests to monitoring module
- Change $this->backend references in StatusDat Queries to $this->ds
- Added LibraryLoader to ease requiring of libaries (to be discussed)

refs #4417
refs #4179
2013-07-19 11:36:05 +02:00

46 lines
1.2 KiB
PHP

<?php
namespace Test\Icinga;
abstract class LibraryLoader {
public static function getBasePath()
{
$path = realpath(dirname(__FILE__));
while (!preg_match('/.*test$/', $path) && $path != '/') {
$path = realpath($path.'/../');
}
return realpath($path.'/../');
}
public static function getLibraryPath()
{
return realpath(self::getBasePath().'/library/Icinga/');
}
public static function getModulePath($module = '')
{
return realpath(self::getBasePath().'/module/'.$module);
}
/**
* Require all php files in the folder $folder
*
* @param $folder The path to the folder containing PHP files
*/
public static function loadFolder($folder, $recursive = true)
{
$files = scandir($folder);
foreach ($files as $file) {
if ($recursive && is_dir(realpath($folder."/".$file))) {
self::loadFolder(realpath($folder."/".$file));
}
if (!preg_match('/php$/', $file)) {
continue;
}
require_once(realpath($folder.'/'.$file));
}
}
abstract public static function requireLibrary();
}