Adding some power to the the mocking engine.
The function-mocker mocking engine was born out of three needs of mine:
- mocking functions
- mocking static methods
- easier instance method mocking, spying and setting of expectations
Until now it held to this needs allowing some mocking and expectation that comes “handy” in WordPress not-so-test-friendly environment
$mock_dbDelta = FunctionMocker::replace('dbDelta'); // ...some execution... $mock_dbDelta->wasCalledOnce(); $mock_dbDelta->wasCalledWithOnce([$query]);
and things like that.
$mock = FunctionMocker::replace('MyClass')->get(); $mock->methodOne('foo', 'bar'); $mock->wasCalledWithOnce(['foo', 'bar'], 'methodOne');
This works but I’d like, while keeping the current API in place, to be able to write code like this equivalent to the one above
$mock = FunctionMocker::replace('MyClass')->get(); $mock->methodOne('foo', 'bar'); $mock->verify()->methodOne('foo','bar')->wasCalledOnce();
Which is so fluid to require no comments.
I’m iterating over the code now to get to that mocking point and will push a new version to GitHub when done.