PHPUnit: how do I mock multiple method calls with multiple arguments?

后端 未结 4 2178

I am writing a unit test for a method using PHPUnit. The method I am testing makes a call to the same method on the same object 3 times but with different sets of arguments.

4条回答
  •  旧巷少年郎
    2020-12-12 22:27

    For others who are looking to both match input parameters and provide return values for multiple calls.. this works for me:

        $mock->method('myMockedMethod')
             ->withConsecutive([$argA1, $argA2], [$argB1, $argB2], [$argC1, $argC2])
             ->willReturnOnConsecutiveCalls($retValue1, $retValue2, $retValue3);
    

提交回复
热议问题