mocking - PHPUnit mock with multiple expects() calls -
using phpunit, wonder how can have multiple expectation same stub/mock.
for example, want test mock have method display()
called , return null. want test method process()
called.
in fact test called testprocessiscalledifdisplayreturnnull()
.
so need setup 2 expectations on same mock object, , manual doesn't :(
if know, method called once use $this->once() in expects(), otherwise use $this->any()
$mock = $this->getmock('nameofthecalss', array('firstmethod','secondmethod','thirdmethod')); $mock->expects($this->once()) ->method('firstmethod') ->will($this->returnvalue('value')); $mock->expects($this->once()) ->method('secondmethod') ->will($this->returnvalue('value')); $mock->expects($this->once()) ->method('thirdmethod') ->will($this->returnvalue('value'));
Comments
Post a Comment