1

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);

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.