A WordPress case for batch function replacement

Some thoughts on function-mocker in respect to WordPress functions.

Artificial functions

The function mocker comes with the embedded ability to replace both defined and undefined functions to stub them or spy them and that means that an “artificial” function environment can be created ad hoc for a piece of software to be tested. That “artificial” function universe comes in handy when testing WordPress components for both themes and plugins.

Batch replacement of functions

While I do not see much of a case for batch replacement of class static and instance methods I can very well see a case for batch function replacement when testing a properly localized WordPress component relying on WordPress translating functions: I’m not interested in testing what goes into a function like __() and what comes out of it as much as I might be interested in my code breaking due to that function not being defined; in a WordPress context functions like __() are as fundamentals as array_map and expected to “just work”.
In this specific case what could I want in a natural language? Something like “replace any call to translation functions with a function returning just the translatable string”; in testing code terms this means:

$this->assertEquals('A translatable string', __('A translatable string', 'plugin_text_domain'));

Right now I can get that result writing this in a PHPUnit_Framework_TestCase:

FunctionMocker::replace('__', function($string){
        return $string;

but that might become a chore if dealing not just with the __ function but with several of its incarnations. I’m working to make code like this possible

// a very long array 
$translationFunctions = ['__', '_e', 'esc_attr__', ...];

FunctionMocker::replace($translationFunctions, function($string){
        return $string;

and hope to have it up and running soon. The idea is to be able to define “classes of functions” to be replaced with the same return value or callback.