Reputation: 5247
Have two mock methods setAsy1
and setAsy2
that returns the same values. Currently I need to call twice the same method function to setup mock methods. Is there any way I can setup with a single call?
$transferItemMockf->expects($this->any())
->method('setAsy1')
->willReturn($id);
$transferItemMockf->expects($this->any())
->method('setAsy2')
->willReturn($id);
Upvotes: 1
Views: 434
Reputation: 14501
PHPUnit\Framework\MockObject\Builder\InvocationMocker::method()
can get PHPUnit\Framework\Constraint\Constraint
as parameter. So, you can set up mock from your example with a single call:
$transferItemMockf->expects($this->any())
->method($this->logicalOr(
$this->equalTo('setAsy1'),
$this->equalTo('setAsy2')
))
->willReturn($id);
Upvotes: 1