From 4f8ab6d04ff90849ac199ac6c39ff66e116fac78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Anne?= Date: Mon, 10 Feb 2025 11:29:46 +0100 Subject: [PATCH] Throw exception when no item is found by `getItemByTypeName()` --- tests/src/autoload/functions.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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); }