如果它是Closure的一个实例,第一个方法将启动Closure调用,它将传递参数,第二个方法resolveByType
将格式化输出。
如何在PHPUnit中正确测试?
class Resolver
{
public function initiate($table)
{
if($table->action instanceof \Closure) {
$return = call_user_func_array($table->action, $table->params);
return $this->resolveByType($return);
}
}
/**
* resolve by returned type
*
* @param mixed $data
* @return void
*/
public function resolveByType($data)
{
switch (gettype($data)) {
case 'array': echo json_encode($data); break;
case 'object': echo json_encode($data); break;
default: echo $data; break;
}
}
}