Function Mocker 0.4.0 out!

Out, updated and working: function mocker is becoming a tool I can rely on.

The simple code pitch

I will copy and paste the example code that’s at the top of function-mocker README file: I’ve updated it to use the new instance method replacement API and made some refactoring in the meanwhile

use tad\FunctionMocker\FunctionMocker as Test;

class SomeClassTest extends \PHPUnit_Framework_TestCase {

    public function setUp(){
        Test::setUp();
    }

    public function tearDown(){
        Test::tearDown();
    }

    public function testSomeMethodCallsSomeFunction(){
        // Setup
        // please note: it can replace not defined functions too!
        $someFunction = Test::replace('some_function');

        // Exercise
        some_function(23);

        // Assert
        $someFunction->wasCalledOnce();

        // check primitive call args
        $someFunction->wasCalledWithOnce(23);

        // check primitive type
        $someFunction->wasCalledWithOnce(Test::isType('int'));
    }

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

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

        // Assert
        $get_post_title->wasCalledOnce();
    }

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

        // Exercise
        $caller = function(Dependency $dependency){
            $dependency->methodOne('foo', 23);
            $dependency->methodTwo();
        };

        $caller($replacement);

        // Assert
        $replacement->wasCalledOnce('methodOne');
        $replacement->wasCalledWithOnce([Test::isType('string'), Test::isType('int')]'methodOne');
        $replacement->wasCalledOnce('methodTwo');
    }
}

I will stick with the current feature set for a while and leverage function-mocker replacement power to stick to TDD in WordPress as much as possible.

I appreciate your input