diff --git a/CRM/Utils/Hook/UnitTests.php b/CRM/Utils/Hook/UnitTests.php index eb529aa901ab..fba73256c27d 100644 --- a/CRM/Utils/Hook/UnitTests.php +++ b/CRM/Utils/Hook/UnitTests.php @@ -52,6 +52,7 @@ public function reset() { * Use a unit-testing mock object to handle hook invocations. * * e.g. hook_civicrm_foo === $mockObject->foo() + * Mocks with a magic `__call()` method are called for every hook invokation. * * @param object $mockObject */ @@ -60,7 +61,7 @@ public function setMock($mockObject) { } /** - * Register a piece of code to run when invoking a hook. + * Register a function to run when invoking a specific hook. * @param string $hook * Hook name, e.g civicrm_pre. * @param array $callable @@ -72,7 +73,7 @@ public function setHook($hook, $callable) { } /** - * Invoke hooks. + * Invoke standard, mock and ad hoc hooks. * * @param int $numParams * Number of parameters to pass to the hook. @@ -93,34 +94,22 @@ public function setHook($hook, $callable) { * * @return mixed */ - /** - * @param int $numParams - * @param mixed $arg1 - * @param mixed $arg2 - * @param mixed $arg3 - * @param mixed $arg4 - * @param mixed $arg5 - * @param mixed $arg6 - * @param string $fnSuffix - * - * @return mixed - */ public function invoke( $numParams, &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6, $fnSuffix) { - $params = array(&$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6); - + // 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); - + // 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); } + // run adhoc hooks if (!empty($this->adhocHooks[$fnSuffix])) { call_user_func_array($this->adhocHooks[$fnSuffix], $params); }