Function mocker out!

It’s good enough a function mocker to be released.

The giants who lent the shoulders

The whole function and method mocking thing is made possible by patchwork by antecedent and PHPUnit and those are the giants I’ve used to climb: kudos.

Code pitch

I’m not copying and pasting the README from the repo here but for the code pitch; in short terms “test everything” (that nasty legacy code too).
This can be written in a PHPUnit test suite

use tad\FunctionMocker\FunctionMocker;

class SomeClassTest extends \PHPUnit_Framework_TestCase {

    public function setUp(){

    public function tearDown(){

    public function testSomeMethodCallsSomeFunction(){
        // Setup
        $functionMock = FunctionMocker::replace('some_function');

        // Exercise

        // Assert

    public function testSomeMethodCallsSomeStaticMethod(){
        // Setup
        $staticMethod = FunctionMocker::replace('Post::get_post_title', 'Post title');

        // Exercise
        $this->assertEquals('Post title', Post::get_post_title());

        // Assert

    public function testSomeMethodCallsSomeInstanceMethod(){
        // Setup
        $replacement = FunctionMocker::replace('Dependency::methodOne');

        // Exercise
        $caller = function(Dependency $dependency){


        // Assert
        $replacement->wasCalledTimes(1, 'methodOne');
        $replacement->wasCalledTimes(1, 'methodTwo');

On GitHub

Here it is on GitHub.


I will undergo the shaming experience of inspecting the code using SensioLabInsight and do some refactor along the way. Beside bug-fixes I will be using the tool a little to put some mileage on it.

I appreciate your input