From 5827cb37cbd8c6bde595178a7472f5a66048b9e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jannis=20Mo=C3=9Fhammer?= Date: Fri, 19 Jul 2013 11:29:51 +0200 Subject: [PATCH] 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 --- .../Protocol/Statusdat/ObjectContainer.php | 71 -------- library/Icinga/Protocol/Statusdat/Query.php | 23 +-- library/Icinga/Protocol/Statusdat/Reader.php | 17 +- .../View/AbstractAccessorStrategy.php | 74 ++++++++ .../Statusdat/View/MonitoringObjectList.php | 134 ++++++++++++++ .../Statusdat/View/ObjectRemappingView.php | 172 ++++++++++++++++++ .../controllers/ListController.php | 3 + .../views/helpers/MonitoringProperties.php | 5 +- .../Statusdat/Query/GroupsummaryQuery.php | 2 +- .../helpers/MonitoringPropertiesTest.php | 4 +- .../test/php/library}/Backend/ComboTest.php | 0 .../test/php/library}/Backend/IdoTest.php | 0 .../php/library}/Backend/LivestatusTest.php | 0 .../Backend/MonitoringObjectListTest.php | 0 .../ServicegroupsummaryQueryTest.php | 33 ++-- .../Statusdat/ServicelistQueryTest.php | 0 .../php/library}/Backend/StatusdatTest.php | 0 .../php/testlib/MonitoringControllerTest.php | 8 +- .../strategies/StatusdatSetupStrategy.php | 16 +- test/php/library/Icinga/LibraryLoader.php | 46 +++++ .../Component/StatusdatComponentTest.php | 29 +-- .../Icinga/Protocol/Statusdat/ParserTest.php | 6 +- .../Statusdat/StatusdatTestLoader.php | 32 ++++ 23 files changed, 530 insertions(+), 145 deletions(-) delete mode 100644 library/Icinga/Protocol/Statusdat/ObjectContainer.php create mode 100644 library/Icinga/Protocol/Statusdat/View/AbstractAccessorStrategy.php create mode 100755 library/Icinga/Protocol/Statusdat/View/MonitoringObjectList.php create mode 100755 library/Icinga/Protocol/Statusdat/View/ObjectRemappingView.php rename {test/php/library/Icinga => modules/monitoring/test/php/library}/Backend/ComboTest.php (100%) rename {test/php/library/Icinga => modules/monitoring/test/php/library}/Backend/IdoTest.php (100%) rename {test/php/library/Icinga => modules/monitoring/test/php/library}/Backend/LivestatusTest.php (100%) rename {test/php/library/Icinga => modules/monitoring/test/php/library}/Backend/MonitoringObjectListTest.php (100%) rename {test/php/library/Icinga => modules/monitoring/test/php/library}/Backend/Statusdat/ServicegroupsummaryQueryTest.php (86%) rename {test/php/library/Icinga => modules/monitoring/test/php/library}/Backend/Statusdat/ServicelistQueryTest.php (100%) rename {test/php/library/Icinga => modules/monitoring/test/php/library}/Backend/StatusdatTest.php (100%) create mode 100644 test/php/library/Icinga/LibraryLoader.php create mode 100644 test/php/library/Icinga/Protocol/Statusdat/StatusdatTestLoader.php diff --git a/library/Icinga/Protocol/Statusdat/ObjectContainer.php b/library/Icinga/Protocol/Statusdat/ObjectContainer.php deleted file mode 100644 index 42b1b6cdb..000000000 --- a/library/Icinga/Protocol/Statusdat/ObjectContainer.php +++ /dev/null @@ -1,71 +0,0 @@ - - * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 - * @author Icinga Development Team - */ -// {{{ICINGA_LICENSE_HEADER}}} - -namespace Icinga\Protocol\Statusdat; - -/** - * Class ObjectContainer - * @package Icinga\Protocol\Statusdat - */ -class ObjectContainer extends \stdClass -{ - /** - * @var \stdClass - */ - public $ref; - - /** - * @var IReader - */ - public $reader; - - /** - * @param \stdClass $obj - * @param IReader $reader - */ - public function __construct(\stdClass &$obj, IReader &$reader) - { - $this->ref = & $obj; - $this->reader = & $reader; - } - - /** - * @param $attribute - * @return \stdClass - */ - public function __get($attribute) - { - $exploded = explode(".", $attribute); - $result = $this->ref; - foreach ($exploded as $elem) { - - $result = $result->$elem; - } - return $result; - } -} diff --git a/library/Icinga/Protocol/Statusdat/Query.php b/library/Icinga/Protocol/Statusdat/Query.php index 5c6defcfb..1d91cd096 100755 --- a/library/Icinga/Protocol/Statusdat/Query.php +++ b/library/Icinga/Protocol/Statusdat/Query.php @@ -29,12 +29,12 @@ namespace Icinga\Protocol\Statusdat; use Icinga\Protocol; - +use Icinga\Data\AbstractQuery; /** * Class Query * @package Icinga\Protocol\Statusdat */ -class Query extends Protocol\AbstractQuery +class Query extends AbstractQuery { /** * @var array @@ -49,7 +49,8 @@ class Query extends Protocol\AbstractQuery "servicegroups" => array("servicegroup"), "comments" => array("servicecomment", "hostcomment"), "hostcomments" => array("hostcomment"), - "servicecomments" => array("servicecomment") + "servicecomments" => array("servicecomment"), + "status" => array("host", "service") ); /** @@ -65,7 +66,7 @@ class Query extends Protocol\AbstractQuery /** * @var array */ - private $columns = array(); + protected $columns = array(); /** * @var null @@ -80,7 +81,7 @@ class Query extends Protocol\AbstractQuery /** * @var array */ - private $order_columns = array(); + protected $order_columns = array(); /** * @var array @@ -169,7 +170,7 @@ class Query extends Protocol\AbstractQuery */ public function __construct(IReader $reader) { - $this->reader = $reader; + $this->ds = $reader; } /** @@ -266,7 +267,7 @@ class Query extends Protocol\AbstractQuery } } - $state = $this->reader->getObjects(); + $state = $this->ds->getObjects(); $result = array(); foreach (self::$VALID_TARGETS[$this->source] as $target) { $indexes = & array_keys($state[$target]); @@ -302,8 +303,8 @@ class Query extends Protocol\AbstractQuery */ private function orderResult($a, $b) { - $o1 = & $this->reader->getObjectByName($this->currentType, $a); - $o2 = & $this->reader->getObjectByName($this->currentType, $b); + $o1 = & $this->ds->getObjectByName($this->currentType, $a); + $o2 = & $this->ds->getObjectByName($this->currentType, $b); $result = 0; foreach ($this->order_columns as $col) { @@ -363,7 +364,7 @@ class Query extends Protocol\AbstractQuery $result = array(); foreach ($indices as $type => $subindices) { foreach ($subindices as $objectIndex) { - $r = & $this->reader->getObjectByName($type, $objectIndex); + $r = & $this->ds->getObjectByName($type, $objectIndex); $hash = ""; $cols = array(); foreach ($this->groupColumns as $col) { @@ -400,7 +401,7 @@ class Query extends Protocol\AbstractQuery $this->limitIndices($indices); $result = array(); - $state = & $this->reader->getObjects(); + $state = & $this->ds->getObjects(); foreach ($indices as $type => $subindices) { foreach ($subindices as $index) { diff --git a/library/Icinga/Protocol/Statusdat/Reader.php b/library/Icinga/Protocol/Statusdat/Reader.php index fbfc0bfe0..d20ade975 100755 --- a/library/Icinga/Protocol/Statusdat/Reader.php +++ b/library/Icinga/Protocol/Statusdat/Reader.php @@ -28,10 +28,10 @@ namespace Icinga\Protocol\Statusdat; -use Icinga\Backend\MonitoringObjectList; + use Icinga\Exception as Exception; use Icinga\Benchmark as Benchmark; - +use Icinga\Protocol\Statusdat\View\MonitoringObjectList; /** * Class Reader * @package Icinga\Protocol\Statusdat @@ -91,9 +91,12 @@ class Reader implements IReader public function __construct($config = \Zend_Config, $parser = null, $noCache = false) { $this->noCache = $noCache; + if (isset($config->no_cache)) { + $this->noCache = $config->no_cache; + } $this->config = $config; $this->parser = $parser; - if (!$noCache) { + if (!$this->noCache) { $this->cache = $this->initializeCaches($config); if ($this->fromCache()) { $this->createHostServiceConnections(); @@ -104,7 +107,7 @@ class Reader implements IReader $this->parseObjectsCacheFile(); } if (!$this->hasRuntimeState) { - ; + } $this->parseStatusDatFile(); if (!$noCache && $this->newState) { @@ -275,10 +278,7 @@ class Reader implements IReader */ public function fetchAll(Query $query) { - return new MonitoringObjectList( - $query->getResult(), - $query->getView() - ); + return $query->getResult(); } /** @@ -318,4 +318,5 @@ class Reader implements IReader { return isset($this->lastState[$type]) ? array_keys($this->lastState[$type]) : null; } + } diff --git a/library/Icinga/Protocol/Statusdat/View/AbstractAccessorStrategy.php b/library/Icinga/Protocol/Statusdat/View/AbstractAccessorStrategy.php new file mode 100644 index 000000000..e61ef12e6 --- /dev/null +++ b/library/Icinga/Protocol/Statusdat/View/AbstractAccessorStrategy.php @@ -0,0 +1,74 @@ + + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} + +namespace Icinga\Protocol\Statusdat\View; + +/** + * Class AbstractAccessorStrategy + * Basic interface for views. + * The name sound weirder than it is: Views define special get and exists operations for fields + * that are not directly available in a resultset, but exist under another name or can be + * accessed by loading an additional object during runtime. + * + * @see Icinga\Backend\DataView\ObjectRemappingView For an implementation of mapping field names + * to storage specific names, e.g. service_state being status.current_state in status.dat views. + * + * @see Icinga\Backend\MonitoringObjectList For the typical usage of this class. It is not wrapped + * around the monitoring object, so we don't use __get() or __set() and always have to give the + * item we'd like to access. + * @package Icinga\Backend\DataView + */ +interface AbstractAccessorStrategy +{ + /** + * Returns a field for the item, or throws an Exception if the field doesn't exist + * + * @param $item The item to access + * @param $field The field of the item that should be accessed + * @return string The content of the field + * + * @throws \InvalidArgumentException when the field does not exist + */ + public function get(&$item, $field); + + /** + * Returns the name that the field has in the specific backend. Might not be available for every field/view + * @param $field The field name that should be translated + * @return string The real name of this field + */ + public function getNormalizedFieldName($field); + + /** + * Returns true if the field exists on the specific item, otherwise false + * + * @param $item The item to access + * @param $field The field to check on the $item + * @return bool True when the field exists, otherwise false + */ + public function exists(&$item, $field); +} diff --git a/library/Icinga/Protocol/Statusdat/View/MonitoringObjectList.php b/library/Icinga/Protocol/Statusdat/View/MonitoringObjectList.php new file mode 100755 index 000000000..3ae1d6e6a --- /dev/null +++ b/library/Icinga/Protocol/Statusdat/View/MonitoringObjectList.php @@ -0,0 +1,134 @@ +dataSet = $dataset; + $this->position = 0; + $this->dataView = $dataView; + } + + public function count() + { + return count($this->dataSet); + } + + public function setPosition($pos) + { + $this->position = $pos; + } + + /** + * (PHP 5 >= 5.0.0)
+ * Return the current element + * @link http://php.net/manual/en/iterator.current.php + * @return mixed Can return any type. + */ + public function current() + { + if ($this->dataView) + return $this; + return $this->dataSet[$this->position]; + } + + /** + * (PHP 5 >= 5.0.0)
+ * Move forward to next element + * @link http://php.net/manual/en/iterator.next.php + * @return void Any returned value is ignored. + */ + public function next() + { + $this->position++; + } + + /** + * (PHP 5 >= 5.0.0)
+ * Return the key of the current element + * @link http://php.net/manual/en/iterator.key.php + * @return mixed scalar on success, or null on failure. + */ + public function key() + { + return $this->position; + } + + /** + * (PHP 5 >= 5.0.0)
+ * Checks if current position is valid + * @link http://php.net/manual/en/iterator.valid.php + * @return boolean The return value will be casted to boolean and then evaluated. + * Returns true on success or false on failure. + */ + public function valid() + { + return $this->position < count($this->dataSet); + } + + /** + * (PHP 5 >= 5.0.0)
+ * Rewind the Iterator to the first element + * @link http://php.net/manual/en/iterator.rewind.php + * @return void Any returned value is ignored. + */ + public function rewind() + { + $this->position = 0; + } + + public function __isset($name) + { + return $this->dataView->exists($this->dataSet[$this->position],$name); + } + + function __get($name) + { + return $this->dataView->get($this->dataSet[$this->position],$name); + } + + function __set($name, $value) + { + throw new \Exception("Setting is currently not available for objects"); + } + + public function offsetExists($offset) + { + return count($this->dataSet) < $offset; + } + + public function offsetGet($offset) + { + $res = new MonitoringObjectList($this->dataSet, $this->dataView); + $res->position = $offset; + return $res; + } + + public function offsetSet($offset, $value) + { + // non mutable + } + + public function offsetUnset($offset) + { + // non mutable + } + +} diff --git a/library/Icinga/Protocol/Statusdat/View/ObjectRemappingView.php b/library/Icinga/Protocol/Statusdat/View/ObjectRemappingView.php new file mode 100755 index 000000000..b9e5be6f0 --- /dev/null +++ b/library/Icinga/Protocol/Statusdat/View/ObjectRemappingView.php @@ -0,0 +1,172 @@ + + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} + +namespace Icinga\Protocol\Statusdat\View; + +/** + * Class ObjectRemappingView + * + * Dataview that maps generic field names to storage specific fields or requests them via handlers. + * + * When accessing objects, every storage api returns them with other names. You can't simply say + * $object->service_state, because this field is, e.g. under status.current_state in the status.dat + * view, while IDO uses servicestate->current_state. + * + * This view is intended for normalizing these changes, so a request of service_state returns the + * right field for the backend. When implementing it, you have to fill the mappedParameters and/or + * the handlerParameters array. While mappedParameters simply translate logic field names to + * storage specific ones, handlerParameters determins functions that handle data retrieval for + * the specific fields. + * + */ + + +class ObjectRemappingView implements AbstractAccessorStrategy +{ + + /** + * When implementing your own Mapper, this contains the static mapping rules. + * @see Icinga\Backend\Statusdat\DataView\StatusdatServiceView for an example + * + * @var array + */ + protected $mappedParameters = array(); + + private $functionMap = array( + "TO_DATE" => "toDateFormat" + ); + + /** + * When implementing your own Mapper, this contains the handler for specific fields and allows you to lazy load + * different fields if necessary. The methods are strings that will be mapped to methods of this class + * + * @see Icinga\Backend\Statusdat\DataView\StatusdatServiceView for an example + * + * @var array + */ + protected $handlerParameters = array(); + + /** + * + * @see Icinga\Backend\DataView\AbstractAccessorStrategy + * + * @param The $item + * @param The $field + * @return The|string + * @throws \InvalidArgumentException + */ + public function get(&$item, $field) + { + + if (isset($item->$field)) { + return $item->$field; + } + if (isset($this->mappedParameters[$field])) { + return $this->getMappedParameter($item, $field); + } + + if (isset($this->handlerParameters[$field])) { + $hdl = $this->handlerParameters[$field]; + return $this->$hdl($item); + } + throw new \InvalidArgumentException("Field $field does not exist for status.dat services"); + } + + private function applyPropertyFunction($function, $value) + { + if (!isset($this->functionMap[$function])) + return $value; + $fn = $this->functionMap[$function]; + + return $this->$fn($value); + } + + private function toDateFormat($value) + { + if (is_numeric($value)) { + return date("Y-m-d H:i:s", intval($value)); + } else { + return $value; + } + } + + private function getMappedParameter(&$item, $field) + { + $matches = array(); + $fieldDef = $this->mappedParameters[$field]; + $function = false; + if (preg_match_all('/(?P\w+)\((?P.*)\)/', $fieldDef, $matches)) { + $function = $matches["FUNCTION"][0]; + $fieldDef = $matches["PARAMETER"][0]; + } + $mapped = explode(".", $fieldDef); + $res = $item; + + foreach ($mapped as $map) { + if (!isset($res->$map)) { + return ""; + } + $res = $res->$map; + } + if ($function) { + return $this->applyPropertyFunction($function, $res); + } + return $res; + } + + /** + * + * @see Icinga\Backend\DataView\AbstractAccessorStrategy + * + * @param The $field + * @return The|string + */ + public function getNormalizedFieldName($field) + { + if (isset($this->mappedParameters[$field])) { + return $this->mappedParameters[$field]; + } + return $field; + } + + /** + * + * @see Icinga\Backend\DataView\AbstractAccessorStrategy + * + * @param The $item + * @param The $field + * @return bool + */ + public function exists(&$item, $field) + { + return (isset($item->$field) + || isset($this->mappedParameters[$field]) + || isset($this->handlerParameters[$field]) + ); + } +} diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index 27446d750..0c5341b9d 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -31,10 +31,12 @@ class Monitoring_ListController extends ModuleActionController 'host_address', 'host_acknowledged', 'host_output', + 'host_long_output', 'host_in_downtime', 'host_is_flapping', 'host_state_type', 'host_handled', + 'host_last_check', 'host_last_state_change', 'host_notifications_enabled', 'host_unhandled_service_count', @@ -65,6 +67,7 @@ class Monitoring_ListController extends ModuleActionController if ($this->_getParam('view') === 'compact') { $this->_helper->viewRenderer('hosts_compact'); } + } public function servicesAction() diff --git a/modules/monitoring/application/views/helpers/MonitoringProperties.php b/modules/monitoring/application/views/helpers/MonitoringProperties.php index 632178afb..d3603bbec 100644 --- a/modules/monitoring/application/views/helpers/MonitoringProperties.php +++ b/modules/monitoring/application/views/helpers/MonitoringProperties.php @@ -133,14 +133,13 @@ class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract private function buildLatency(\stdClass $object) { $val = ''; - if ($this->buildCheckType($object) === self::CHECK_PASSIVE) { $val .= self::VALUE_NA; } else { - $val .= $this->floatFormatter($object->check_latency); + $val .= $this->floatFormatter($object->latency); } - $val .= ' / '. $this->floatFormatter($object->check_execution_time). ' seconds'; + $val .= ' / '. $this->floatFormatter($object->execution_time). ' seconds'; return $val; } diff --git a/modules/monitoring/library/Monitoring/Backend/Statusdat/Query/GroupsummaryQuery.php b/modules/monitoring/library/Monitoring/Backend/Statusdat/Query/GroupsummaryQuery.php index 17aa250b3..018781bd3 100755 --- a/modules/monitoring/library/Monitoring/Backend/Statusdat/Query/GroupsummaryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Statusdat/Query/GroupsummaryQuery.php @@ -170,7 +170,7 @@ abstract class GroupsummaryQuery extends Query */ public function init() { - $this->reader = $this->backend->getReader(); + $this->reader = $this->ds->getReader(); $this->query = $this->reader->select()->from($this->base, array())->groupByFunction( "groupByProblemType", $this diff --git a/modules/monitoring/test/php/application/views/helpers/MonitoringPropertiesTest.php b/modules/monitoring/test/php/application/views/helpers/MonitoringPropertiesTest.php index 0551c23bb..74e9d38fb 100644 --- a/modules/monitoring/test/php/application/views/helpers/MonitoringPropertiesTest.php +++ b/modules/monitoring/test/php/application/views/helpers/MonitoringPropertiesTest.php @@ -66,6 +66,7 @@ class MonitoringPropertiesTest extends \PHPUnit_Framework_TestCase $host = new HostStruct4Properties(); $host->host_current_check_attempt = '5'; + $propertyHelper = new \Zend_View_Helper_MonitoringProperties(); $items = $propertyHelper->monitoringProperties($host); @@ -76,6 +77,7 @@ class MonitoringPropertiesTest extends \PHPUnit_Framework_TestCase public function testOutput2() { + date_default_timezone_set("UTC"); $host = new HostStruct4Properties(); $host->host_current_check_attempt = '5'; $host->host_active_checks_enabled = '1'; @@ -93,7 +95,7 @@ class MonitoringPropertiesTest extends \PHPUnit_Framework_TestCase 'Check type' => "ACTIVE", 'Check latency / duration' => "0.1204 / 0.0000 seconds", 'Next scheduled active check' => "2013-07-04 11:29:43", - 'Last state change' => "2013-07-04 13:24:43", + 'Last state change' => "2013-07-04 11:24:43", 'Last notification' => "N/A (notification 0)", 'Is this host flapping?' => "YES (12.37% state change)", 'In scheduled downtime?' => "YES", diff --git a/test/php/library/Icinga/Backend/ComboTest.php b/modules/monitoring/test/php/library/Backend/ComboTest.php similarity index 100% rename from test/php/library/Icinga/Backend/ComboTest.php rename to modules/monitoring/test/php/library/Backend/ComboTest.php diff --git a/test/php/library/Icinga/Backend/IdoTest.php b/modules/monitoring/test/php/library/Backend/IdoTest.php similarity index 100% rename from test/php/library/Icinga/Backend/IdoTest.php rename to modules/monitoring/test/php/library/Backend/IdoTest.php diff --git a/test/php/library/Icinga/Backend/LivestatusTest.php b/modules/monitoring/test/php/library/Backend/LivestatusTest.php similarity index 100% rename from test/php/library/Icinga/Backend/LivestatusTest.php rename to modules/monitoring/test/php/library/Backend/LivestatusTest.php diff --git a/test/php/library/Icinga/Backend/MonitoringObjectListTest.php b/modules/monitoring/test/php/library/Backend/MonitoringObjectListTest.php similarity index 100% rename from test/php/library/Icinga/Backend/MonitoringObjectListTest.php rename to modules/monitoring/test/php/library/Backend/MonitoringObjectListTest.php diff --git a/test/php/library/Icinga/Backend/Statusdat/ServicegroupsummaryQueryTest.php b/modules/monitoring/test/php/library/Backend/Statusdat/ServicegroupsummaryQueryTest.php similarity index 86% rename from test/php/library/Icinga/Backend/Statusdat/ServicegroupsummaryQueryTest.php rename to modules/monitoring/test/php/library/Backend/Statusdat/ServicegroupsummaryQueryTest.php index 0d329daa1..a4f451ffb 100644 --- a/test/php/library/Icinga/Backend/Statusdat/ServicegroupsummaryQueryTest.php +++ b/modules/monitoring/test/php/library/Backend/Statusdat/ServicegroupsummaryQueryTest.php @@ -1,17 +1,22 @@ setReader($this->getTestDataset()); - $q = new \Icinga\Backend\Statusdat\ServicegroupsummaryQuery($backend); + $q = new ServicegroupsummaryQuery($backend); $indices = array( "service" => array( "hosta;service1", "hosta;service2", "hosta;service3", diff --git a/test/php/library/Icinga/Backend/Statusdat/ServicelistQueryTest.php b/modules/monitoring/test/php/library/Backend/Statusdat/ServicelistQueryTest.php similarity index 100% rename from test/php/library/Icinga/Backend/Statusdat/ServicelistQueryTest.php rename to modules/monitoring/test/php/library/Backend/Statusdat/ServicelistQueryTest.php diff --git a/test/php/library/Icinga/Backend/StatusdatTest.php b/modules/monitoring/test/php/library/Backend/StatusdatTest.php similarity index 100% rename from test/php/library/Icinga/Backend/StatusdatTest.php rename to modules/monitoring/test/php/library/Backend/StatusdatTest.php diff --git a/modules/monitoring/test/php/testlib/MonitoringControllerTest.php b/modules/monitoring/test/php/testlib/MonitoringControllerTest.php index 25f127107..6831fe85b 100644 --- a/modules/monitoring/test/php/testlib/MonitoringControllerTest.php +++ b/modules/monitoring/test/php/testlib/MonitoringControllerTest.php @@ -81,7 +81,7 @@ namespace Test\Monitoring\Testlib * } * } */ - class MonitoringControllerTest extends \PHPUnit_Framework_TestCase + abstract class MonitoringControllerTest extends \PHPUnit_Framework_TestCase { /** * The module directory for requiring modules (is relative to the source file) @@ -159,7 +159,7 @@ namespace Test\Monitoring\Testlib if (!preg_match('/php$/', $view)) { continue; } - require_once($module.$folder."/".$view); + require_once(realpath($module.$folder."/".$view)); } } @@ -169,8 +169,8 @@ namespace Test\Monitoring\Testlib */ private function requireStatusDatQueries() { - require_once('library/Monitoring/Backend/Statusdat.php'); - require_once($this->moduleDir.'/library/Monitoring/Backend/Statusdat/Query/Query.php'); + require_once(realpath($this->moduleDir.'/library/Monitoring/Backend/Statusdat.php')); + require_once(realpath($this->moduleDir.'/library/Monitoring/Backend/Statusdat/Query/Query.php')); $this->requireFolder('library/Monitoring/Backend/Statusdat'); $this->requireFolder('library/Monitoring/Backend/Statusdat/Criteria'); $this->requireFolder('library/Monitoring/Backend/Statusdat/Query'); diff --git a/modules/monitoring/test/php/testlib/datasource/strategies/StatusdatSetupStrategy.php b/modules/monitoring/test/php/testlib/datasource/strategies/StatusdatSetupStrategy.php index 041213d1b..0478b30da 100644 --- a/modules/monitoring/test/php/testlib/datasource/strategies/StatusdatSetupStrategy.php +++ b/modules/monitoring/test/php/testlib/datasource/strategies/StatusdatSetupStrategy.php @@ -4,6 +4,7 @@ namespace Test\Monitoring\Testlib\Datasource\Strategies; +use Tests\Icinga\Protocol\Statusdat\StatusdatTestLoader; /** * SetupStrategy for status dat. * @@ -28,7 +29,7 @@ class StatusdatSetupStrategy implements SetupStrategy { if (is_dir($folder."/".$file)) { $this->requireFolder($folder."/".$file); } elseif (preg_match("/\.php/", $file)) { - require_once($folder."/".$file); + require_once(realpath($folder."/".$file)); } } } @@ -42,17 +43,8 @@ class StatusdatSetupStrategy implements SetupStrategy { */ private function requireStatusDat() { - $moduleDir = realpath(dirname(__FILE__)."/../../../../../"); - $appDir = realpath($moduleDir."/../../"); - $base = $appDir."/library/Icinga/Protocol/StatusDat"; - require_once("Zend/Cache.php"); - require_once("Zend/Log.php"); - require_once($appDir."/library/Icinga/Application/Logger.php"); - require_once($appDir."/library/Icinga/Protocol/AbstractQuery.php"); - require_once($base."/Exception/ParsingException.php"); - require_once($base."/Query/IQueryPart.php"); - require_once($base."/IReader.php"); - $this->requireFolder($base); + require_once 'library/Icinga/Protocol/Statusdat/StatusdatTestLoader.php'; + StatusdatTestLoader::requireLibrary(); } /** diff --git a/test/php/library/Icinga/LibraryLoader.php b/test/php/library/Icinga/LibraryLoader.php new file mode 100644 index 000000000..d07b4a184 --- /dev/null +++ b/test/php/library/Icinga/LibraryLoader.php @@ -0,0 +1,46 @@ +