From 20fe291433ba538fa6fe5f6329eb0eebddad6072 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Mon, 28 Aug 2017 06:00:23 +0200 Subject: [PATCH] IcingaServiceSet: do not allow for objects without ...a host --- library/Director/Objects/IcingaServiceSet.php | 6 ++++++ test/php/library/Director/Objects/IcingaServiceSetTest.php | 4 ---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/library/Director/Objects/IcingaServiceSet.php b/library/Director/Objects/IcingaServiceSet.php index dd23c753..c934e8e5 100644 --- a/library/Director/Objects/IcingaServiceSet.php +++ b/library/Director/Objects/IcingaServiceSet.php @@ -4,6 +4,7 @@ namespace Icinga\Module\Director\Objects; use Icinga\Data\Filter\Filter; use Icinga\Exception\IcingaException; +use Icinga\Exception\ProgrammingError; use Icinga\Module\Director\Exception\DuplicateKeyException; use Icinga\Module\Director\IcingaConfig\IcingaConfig; @@ -267,6 +268,11 @@ class IcingaServiceSet extends IcingaObject $name = $this->getObjectName(); + if ($this->isObject() && $this->get('host_id') === null) { + throw new ProgrammingError( + 'A Service Set cannot be an object with no related host' + ); + } // checking if template object_name is unique // TODO: Move to IcingaObject if (! $this->hasBeenLoadedFromDb() && $this->isTemplate() && static::exists($name, $this->connection)) { diff --git a/test/php/library/Director/Objects/IcingaServiceSetTest.php b/test/php/library/Director/Objects/IcingaServiceSetTest.php index 493dec8c..c1cb817d 100644 --- a/test/php/library/Director/Objects/IcingaServiceSetTest.php +++ b/test/php/library/Director/Objects/IcingaServiceSetTest.php @@ -125,16 +125,12 @@ class IcingaServiceSetTest extends IcingaObjectTestCase */ public function testCreatingHostSetWithoutHost() { - $this->markTestIncomplete('Throws no error currently, but will create the object'); - - /* TODO: fix this, it will create an object currently $set = IcingaServiceSet::create(array( 'object_name' => '___TEST__set_BAD2', 'object_type' => 'object', )); $set->store($this->getDb()); - */ } public function testDeletingSet()