lithium\test\Mocker::callFunction PHP Method

callFunction() public static method

This method should only be accessed by functions created by Mocker::overwriteFunction(). If no matching stored function exists, the global function will be called instead.
public static callFunction ( string $name, array &$params = [] ) : mixed
$name string Fully namespaced function name to call.
$params array Params to be passed to the function.
return mixed
    public static function callFunction($name, array &$params = array())
    {
        $function = substr($name, strrpos($name, '\\'));
        $exists = isset(static::$_functionCallbacks[$name]);
        if ($exists && is_callable(static::$_functionCallbacks[$name])) {
            $function = static::$_functionCallbacks[$name];
        }
        $result = call_user_func_array($function, $params);
        if (!isset(static::$_functionResults[$name])) {
            static::$_functionResults[$name] = array();
        }
        static::$_functionResults[$name][] = array('args' => $params, 'result' => $result, 'time' => microtime(true));
        return $result;
    }

Usage Example

示例#1
0
 public function testCallFunctionUsesGlobalFallback()
 {
     $result = Mocker::callFunction('foo\\bar\\baz\\get_called_class');
     $this->assertIdentical('lithium\\test\\Mocker', $result);
 }