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

后端 未结 4 2154

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:22

    In my case the answer turned out to be quite simple:

    $this->expects($this->at(0))
        ->method('write')
        ->with(/* first set of params */);
    
    $this->expects($this->at(1))
        ->method('write')
        ->with(/* second set of params */);
    

    The key is to use $this->at(n), with n being the Nth call of the method. I couldn't do anything with any of the logicalOr() variants I tried.

提交回复
热议问题