thom thom -5 years ago 228
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.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download