From f66ab8dae2f3d0418759f81a3a64dc9517a62449 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 14 Apr 2024 15:17:31 +0200 Subject: Adding upstream version 1.10.2. Signed-off-by: Daniel Baumann --- library/Director/Test/IcingaObjectTestCase.php | 92 ++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 library/Director/Test/IcingaObjectTestCase.php (limited to 'library/Director/Test/IcingaObjectTestCase.php') diff --git a/library/Director/Test/IcingaObjectTestCase.php b/library/Director/Test/IcingaObjectTestCase.php new file mode 100644 index 0000000..a37fced --- /dev/null +++ b/library/Director/Test/IcingaObjectTestCase.php @@ -0,0 +1,92 @@ +table; + } + $properties['object_name'] = '___TEST___' . $type . '_' . $object_name; + $obj = IcingaObject::createByType($type, $properties, $this->getDb()); + + if ($storeIt === true) { + $obj->store(); + $this->prepareObjectTearDown($obj); + } + + return $obj; + } + + /** + * Helper method for loading an object + * + * @param string $name + * @param null $type + * @return IcingaObject + */ + protected function loadObject($name, $type = null) + { + if ($type === null) { + $type = $this->table; + } + $realName = '___TEST___' . $type . '_' . $name; + return IcingaObject::loadByType($type, $realName, $this->getDb()); + } + + /** + * Store the object in a list for deletion on tearDown() + * + * @param IcingaObject $object + * + * @return $this + */ + protected function prepareObjectTearDown(IcingaObject $object) + { + $this->assertTrue($object->hasBeenLoadedFromDb()); + $this->createdObjects[] = $object; + return $this; + } + + /** + * @inheritdoc + */ + public function tearDown() + { + if ($this->hasDb()) { + /** @var IcingaObject $object */ + foreach (array_reverse($this->createdObjects) as $object) { + $object->delete(); + } + + if ($this->subject !== null) { + $this->subject->delete(); + } + } + } +} -- cgit v1.2.3