lithium\test\Mocker::overwriteFunction()
Will overwrite namespaced functions.
Parameters
-
string|bool
$name Fully namespaced function, or
false
to reset functions. -
closure|bool
$callback Callback to be called, or
false
to reset this function.
Returns
voidSource
public static function overwriteFunction($name, $callback = null) {
if ($name === false) {
static::$_functionResults = [];
return static::$_functionCallbacks = [];
}
if ($callback === false) {
static::$_functionResults[$name] = [];
return static::$_functionCallbacks[$name] = false;
}
static::$_functionCallbacks[$name] = $callback;
if (function_exists($name)) {
return;
}
$function = new ReflectionFunction($callback);
$pos = strrpos($name, '\\');
eval(static::_dynamicCode('mockFunction', 'function', [
'namespace' => substr($name, 0, $pos),
'function' => substr($name, $pos + 1),
'args' => static::_methodParams($function),
'stringArgs' => static::_stringMethodParams($function),
]));
return;
}