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(): void { if ($this->hasDb()) { /** @var IcingaObject $object */ foreach (array_reverse($this->createdObjects) as $object) { $object->delete(); } if ($this->subject !== null) { $this->subject->delete(); } } parent::tearDown(); } }