static function spy_instance($class)
{
$spyClass = self::spy_class($class);
$res = new $spyClass();
// Find the constructor args
$constructor_args = func_get_args();
array_shift($constructor_args);
// Call the constructor (maybe)
if (count($constructor_args) != 1 || $constructor_args[0] !== self::DONT_CALL_CONSTRUCTOR) {
$constructor = array($res, '__phockito_parent_construct');
if (!is_callable($constructor)) {
if ($constructor_args) {
user_error("Tried to create spy of {$class} with constructor args, but that {$class} doesn't have a constructor defined", E_USER_ERROR);
}
} else {
call_user_func_array($constructor, $constructor_args);
}
}
// And done
return $res;
}