PHPUnit: Stubbing multiple interfaces PHPUnit: Stubbing multiple interfaces php php

PHPUnit: Stubbing multiple interfaces


For the future if somebody happens to see this answer this works for me in PHPUnit 7:

$mock = $this  ->getMockBuilder([InterfaceA::class,InterfaceB::class])  ->getMock();


Do you have access to edit the original code? If so I would create a new interface that extends both ArrayAccess and MyInterface. That way you should be able to stub/mock an object to test the method under test.


It is not a good idea to create an interface in application codebase to make tests happy. I mean you can create this interface but it would better if you put it somewhere in the test code base. For example you can put the interface after the test case class in the file directly

To test two interfaces same time I created an interface in the test case file (it could be any other place)

interface ApiAwareAction implements ActionInterface, ApiAwareInterface{}

And after I did a mock of that class:

$this->getMock('Payum\Tests\ApiAwareAction');