PHPUnit - 创建 Mock 对象以充当属性的存根
我正在尝试在PHPunit中配置一个Mock对象以返回不同属性的值(使用__get函数访问)
例:
class OriginalObject {
public function __get($name){
switch($name)
case "ParameterA":
return "ValueA";
case "ParameterB":
return "ValueB";
}
}
我试图用以下方式来嘲笑这一点:
$mockObject = $this->getMock("OrigionalObject");
$mockObject ->expects($this->once())
->method('__get')
->with($this->equalTo('ParameterA'))
->will($this->returnValue("ValueA"));
$mockObject ->expects($this->once())
->method('__get')
->with($this->equalTo('ParameterB'))
->will($this->returnValue("ValueB"));
但这失败了:-(