Function Mocker 1.0.2 out

New Function Mocker API is in.

Flowing

While I’ve not broken back-compatibility I’ve pushed the latest version of function-mocker to GitHub and, beside some general cleanup, I’ve implemented a more expressive and prophecy inspired API when it comes to mocking object methods.
The object method mocking “market” is a crowded one with PhpUnit, prophecy itself, AspectMock and others I’m leaving out for ignorance rather than importance.
Function Mocker gathers mocking, stubbing and spying in a single call to the replace method

$mock = FunctionMocker::replace('MyClass')->method('myMethod');

and in a way similar to what prophecy does using the reveal method the mocking engine will generate an injectable mock object using the get method

// prophecy in PHPUnit context
$mock = $this->prophesize('MyClass');

$subject = new ObjectUnderTest($mock->reveal());
$subject->doSomething();

$mock->myMethod('foo')->shouldHaveBeenCalled();

// function-mocker
$mock = FunctionMocker::replace('MyClass')->method('myMethod');

$subject = new ObjectUnderTest($mock->get());
$subject->doSomething();

$mock->verify()->myMethod('foo')->wasCalledOnce();

In a matter of personal taste I prefer the user interface function-mocker exposes as it’s coherent throughout function, static method and instance method mocking but that’s my use case and my working context (WordPress) where I get to mock, stub and spy functions as much as I do for objects.

Next

I will iterate over Function Mocker performances and try to tap into runkit powers to allow for even more “unlawful” mocking.

I appreciate your input