WP: adding mocks for some miscellaneous functions
Closed this issue · 1 comments
Just wondering if there is interest in the addition of more mocks for some typically, often mocked, WP translation/output escaping functions, as well as some miscellaneous WP functions.
The functions I'm thinking of are:
Duh, just discovered the__()
etc - to just return the original string.Functions\stubTranslationFunctions()
method, so never mind about this.Duh, just discovered theesc_attr()
,esc_html()
etc - also to just return the original stringFunctions\stubEscapeFunctions()
method, so never mind about this.wp_json_encode()
- return the output ofjson_encode()
without further sanity check.wp_slash()
- same functionality as WPwp_unslash()
- same functionality as WPuser_trailingslashit()
justtrailingslashit()
wp_parse_args()
and by extensionwp_parse_str()
- same functionality as WP
Please let me know if any (or all) of these peek your interest.
Thanks @jrfnl
I would say that:
- wp_json_encode()
- user_trailingslashit()
could be added to the generic helper functions that are Mocked by default.
I normally put there "logicless" functions that can be written in one/two lines.
I think wp_slash()
and wp_unslash()
, would also be a nice addition, but considering in WP they support recursive array processing (and wp_unslash()
even recusrive object processing), as well as single string, they would not be completely logicless nor one line. Not sure about those.
Adding wp_parse_args()
and wp_parse_str()
is something I considered as well, the reasons I did not add the stub for them is that wp_parse_str()
triggers a filter, which means that by adding a stub that do not trigger any filter I could break existing tests.
On top of that, If I would ship a stub for these functions, it would use Functions\when
. I personally find myself using Functions\expect
with wp_parse_args
to both overcome the fact that function is not defined and also add expectation for it to be called. But when
and expect
can't be used in same test for same function, meaning that any test currently using expect
would fail.
That means that if will be convinced of adding a stub for those functions that should be opt-in, in the same fashion stub for escaping and translations functions are shipped now (for the same reason). Having those stubs opt-in is maybe enough also to overcome the issue of wp_parse_str()
not firing a filter.
What do you think?