Is it possible to mock an object in a way that it fakes multiple interfaces implementations? (Note: I am using "padraic's mockery" https://github.com/padraic/mockery)
Suppose I have a class Mysql, which implements Db_Interface and Configurable_Interface, and which I need to mock just to be able to test another class. I want to create a mock with another name, not Mysql (because it could change or disappear in the future, that's why we use interfaces, right?), so I don't want to do Mockery::mock('Mysql').
I know I could create it like Mockery::mock('Db_Interface') and it would pass the instanceof Db_Interface check. But how can I make it pass the check for the other interface too?
@Gordon ok heres the code:
$m = Mockery::mock('Configurable_Interface');
var_dump($m instanceof Configurable_Interface); // true
var_dump($m instanceof Db_Interface); // false of course, since I don't know how to make a mock implement 2 interfaces
For anyone stumbling into this. In Mockery, you can call Mockery::mock('firstInterface, secondInterface');
to mock an object wich needs to implement multiple interfaces.
Source: Mockery README
$this->getMockBuilder(['A', 'B'])->getMock();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With