sebastianbergmann/phpunit-mock-objects — Issue #79: onConsecutiveCalls takes array, or similar function that takes one
Author: MarkRoddy
Created: 2012-01-27 23:04:08+00:00
State: open

The onConsecutiveCalls() method takes a variable number of arguments, and it would be useful if it could also take a single argument that was an array of values that should be consecutively returned. This is especially useful if you have a set of similar tests and want to set up a stub to share between them, but they need to return different values. Something like:

class SomeTest extends PHPUnit_Framework_TestCase {
public function createStubSomeObj($retvals) {
$stub = $this->getMockBuilder("SomeObj")
->setMethods(array("foo"))
->getMock();
$sut->expects($this->any())
->method('foo') // Would you notice this?
->will($this->onConsecutiveCalls($retvals));
}

Right now to accomplish this you need to use call_user_func_array on $this->onConsecutiveCalls which is confusing to look and drops the use of the fluent interface.