thom thom - 11 months ago 39
PHP Question

PHPUnit: expects method meaning

When I create a new mock I need to call the expects method. What exactly it does? What about its arguments?

$todoListMock = $this->getMock('\Model\Todo_List');

I can't find the reason anywhere (I've tried docs). I've read the sources but I can't understand it. Thanks.


expects() - Sets how many times you expect a method to be called:

$mock = $this->getMock('nameOfTheClass', array('firstMethod','secondMethod','thirdMethod'));

If you know, that method is called once use $this->once() in expects(), otherwise use $this->any()

PHPUnit mock with multiple expects() calls