I'm trying to mock a singleton using this method described by the author of PHPUnit and stub one of its methods:
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());
}
The problem is that this dumps NULL every time. As I understand it, when you mock an object, all the methods are replaced with stubs that return NULL unless explicitly stubbed like I'm doing. So, since I've stubbed the bar() method, why is it not dumping the expected 'bar' string? What have I done wrong?