diff --git a/tests/src/autoload/functions.php b/tests/src/autoload/functions.php index cf2ac628bb5..4912cf1bf46 100644 --- a/tests/src/autoload/functions.php +++ b/tests/src/autoload/functions.php @@ -774,17 +774,17 @@ function loadDataset() /** * Test helper, search an item from its type and name * - * @param string $type - * @param string $name - * @param boolean $onlyid - * @return CommonDBTM|false the item, or its id + * @param string $type + * @param string $name + * @param bool $onlyid + * @return CommonDBTM|int the item, or its id */ -function getItemByTypeName($type, $name, $onlyid = false) +function getItemByTypeName(string $type, string $name, bool $onlyid = false): CommonDBTM|int { $item = getItemForItemtype($type); $nameField = $type::getNameField(); - if ($item->getFromDBByCrit([$nameField => $name])) { - return ($onlyid ? $item->getField('id') : $item); + if (!$item->getFromDBByCrit([$nameField => $name])) { + throw new \RuntimeException(sprintf('Unable to load the `%s` item with the name `%s`.', $type, $name)); } - return false; + return ($onlyid ? $item->getID() : $item); }