when()
and its related functions are quite simple and straightforward.stubs()
stubs()
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 itstubs
, 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.true
for all the given functions:null
, and because using null
as 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\stubs
.Functions\stubEscapeFunctions()
esc_js()
esc_sql()
esc_attr()
esc_html()
esc_textarea()
esc_url()
esc_url_raw()
esc_xml()
(since 2.6)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.Functions\stubTranslationFunctions()
__()
_e()
_ex()
_x()
_n()
(since 2.6)_nx()
(since 2.6)translate()
esc_html__()
esc_html_x()
esc_attr__()
esc_attr_x()
esc_html_e()
esc_attr_e()
esc_html__()
, 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 Functions\stubs()
alone.Functions\stubs
stubs()
, passing null
as 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 null
it is possible to do something like this:__return_null
is a WP function that Brain Monkey also defines since version 2.0.stubs
, passing a callable
as the "value" of the function to stub, the created stub will be an alias of the given callable, will not return it.stubs
to stub a function that returns a callable, a way to do it would be something like this:when
+ justReturn
: