From 241bda33d5edb85ab5b139c4d86bdae6c64e8736 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 3 Mar 2017 16:52:01 -0800 Subject: [PATCH] CRM-19813 - CRM_Utils_Hook_UnitTests::invoke() - Fix return handling The normal `runHooks()` function has a weird protocol wherein results may be progressively merged (if they're non-empty arrays). This revision extends that behavior to each of the unit-test hook formulations. The patch enables better unit-testing of CRM-19813. --- CRM/Utils/Hook/UnitTests.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/CRM/Utils/Hook/UnitTests.php b/CRM/Utils/Hook/UnitTests.php index fba73256c2..2061c30c49 100644 --- a/CRM/Utils/Hook/UnitTests.php +++ b/CRM/Utils/Hook/UnitTests.php @@ -99,20 +99,34 @@ class CRM_Utils_Hook_UnitTests extends CRM_Utils_Hook { &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6, $fnSuffix) { $params = array(&$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6); + + $fResult1 = $fResult2 = $fResult3 = NULL; + // run standard hooks if ($this->civiModules === NULL) { $this->civiModules = array(); $this->requireCiviModules($this->civiModules); } - $this->runHooks($this->civiModules, $fnSuffix, $numParams, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6); + $fResult1 = $this->runHooks($this->civiModules, $fnSuffix, $numParams, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6); + // run mock object hooks if ($this->mockObject && is_callable(array($this->mockObject, $fnSuffix))) { - call_user_func(array($this->mockObject, $fnSuffix), $arg1, $arg2, $arg3, $arg4, $arg5, $arg6); + $fResult2 = call_user_func(array($this->mockObject, $fnSuffix), $arg1, $arg2, $arg3, $arg4, $arg5, $arg6); } + // run adhoc hooks if (!empty($this->adhocHooks[$fnSuffix])) { - call_user_func_array($this->adhocHooks[$fnSuffix], $params); + $fResult3 = call_user_func_array($this->adhocHooks[$fnSuffix], $params); } + + $result = array(); + foreach (array($fResult1, $fResult2, $fResult3) as $fResult) { + if (!empty($fResult) && is_array($fResult)) { + $result = array_merge($result, $fResult); + } + } + + return empty($result) ? TRUE : $result; } } -- 2.25.1