* 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
*/
}
/**
- * 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
}
/**
- * Invoke hooks.
+ * Invoke standard, mock and ad hoc hooks.
*
* @param int $numParams
* Number of parameters to pass to the hook.
*
* @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);
}