Call forwarding with function-mocker

I’ve pushed an addition to function-mocker to allow for practical forwarding of the call to the original function or method when needed.

A use case

Working to a WordPress project I need to replace the value returned by the get_option function when a certain specific option is requested. While I might set up a fixed return value for that specific call and make any other call use its default value (false by default) using a replacement set up like this

public function test_replace_specific_get_option_call_and_default_others(){

    // presuming a WP environment is running
    add_option('some_option', 23);

    FunctionMocker::replace('get_option', function($option){
        return $option === 'target_option' ? 'foo' : false;
    })

    // passes 
    $this->assertEquals('foo', get_option('target_option'));

    // fails
    $this->assertEquals(23, get_option('some_option'));

    // passes
    $this->assertFalse(get_option('some_option'));
}

that might, in more complex tests like those run in a service suite set up using WP Browser, screw a lot of things up.

More specific replacement

The library function-mocker uses to replace functions and static methods is patchwork and that library did pack a \Patchwork\callOriginal(array $args = null) function already.
What this means is that the FunctionMocker::callOriginal(array $args = null) method is a mere wrapping around the \Patchwork\callOriginal function that empowers the code above with more specific replacement possibilities

public function test_replace_specific_get_option_call_and_leave_others_unaltered(){

    // presuming a WP environment is running
    add_option('some_option', 23);

    FunctionMocker::replace('get_option', function($option){
        return $option === 'target_option' ? 'foo' : FunctionMocker::callOriginal([$option]);
    });

    // passes 
    $this->assertEquals('foo', get_option('targe_option'));

    // passes
    $this->assertEquals(23, get_option('some_option'));
}

Next

Working mainly on WordPress projects the needs and wants of the library are driven by that and I will commit another capital crime venturing into the land of global variables.

I appreciate your input