测试方法:
public function convert(AbstractMessage $message)
{
$data = array();
// Text conversion
$text = $message->getText();
if(null !== $text) {
if(!is_string($text) && (is_object($text)
&& !method_exists($text, '__toString'))) {
throw new UnexpectedTypeException(gettype($text), 'string');
}
$data['text'] = (string) $text;
}
}
如何模拟具有__toString
方法的通用对象(无论类)?