I was looking to get different return values for the same method while calling it multiple times. I tried many things but did not get an exact answer for this.
$mock = $this->getMockBuilder('Test')
                ->disableOriginalConstructor()
                ->setMethods(array('testMethod'))
                ->getMock();
$mock->expects($this->once())->method('testMethod')->will($this->returnValue(true));
$mock->expects($this->second())->method('testMethod')->will($this->returnValue(false));
                You can use willReturnOnConsecutiveCalls method
$mock
    ->expects($this->exactly(2))
    ->method('testMethod')
    ->willReturnOnConsecutiveCalls(true, false);
Alternative (for phpunit < 4):
$mock
    ->expects($this->exactly(2))
    ->method('testMethod')
    ->will($this->onConsecutiveCalls(true, false));
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With