when()and its related functions are quite simple and straightforward.
Functions\stubs()accepts an array of functions to be defined.
callable, the function given as array item key is aliased to the given callback instead of returning the callback itself;
null, the function given as array item key will return the first argument received, just like
when( $function_name )->justReturnArg()was used for it
stubs, useful to stub many function with same return value, is to pass to a non-associative array of function names as first argument, and the wanted return value for all of them as second argument.
truefor all the given functions:
null, and because using
nullas value means "return first received argument" it is possible to stub many functions that have to return first received argument, by passing their names as first argument to
stubs()(and no second argument), like this:
stubs()can be mixed together, for example like this:
Functions\stubEscapeFunctions(), for all of the functions listed above a stub will be created that will do some very basic escaping on the received first argument before returning it.
Functions\stubs, since its introduction, has been to stub translation functions.
esc_html_x()...) the same escaping mechanism used by the pre-defined escaping functions stubs (see above) is applied before returning first received argument.
Functions\stubTranslationFunctions()creates stubs for functions that echo translated text, something not easily doable with
nullas the "value" of the function to stub, the return value of the stub will not be
null, but the first received value.
stubs()to stub functions that return
nullit is possible to do something like this:
__return_nullis a WP function that Brain Monkey also defines since version 2.0.
stubs, passing a
callableas the "value" of the function to stub, the created stub will be an alias of the given callable, will not return it.
stubsto stub a function that returns a callable, a way to do it would be something like this: