Teaching Function Mocker new tricks

Adding some power to the the mocking engine.

Uneducated and powerful

The function-mocker mocking engine was born out of three needs of mine:

  1. mocking functions
  2. mocking static methods
  3. 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.

Additional API

Inspired by the prophecy mocking engine I want to add to function-mocker a more fluid API when it comes to instance method mocking.
Currently this code will verify an instance method was called once

$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.

Next

I’m iterating over the code now to get to that mocking point and will push a new version to GitHub when done.