我試圖用this method described by the author of PHPUnit嘲弄一個單身和存根其方法之一:PHPUnit存根方法返回NULL?
public function setUp() {
$this->_foo = $this->getMockBuilder('Foo')
->disableOriginalConstructor()
->getMock();
$this->_foo->expects($this->any())
->method('bar')
->will($this->returnValue('bar'));
var_dump($this->_foo->bar());
}
的問題是,這個轉儲每次NULL
。據我瞭解,當你嘲笑一個對象時,所有的方法都被替換爲存根,除非明確地像我所做的那樣剔除,否則返回NULL
。所以,因爲我已經扼殺了bar()
方法,爲什麼它不傾銷預期的'bar'
字符串?我做錯了什麼?