MyTestCase
that is assumed very similar to the one coded in the WordPress / Setup docs section.did_action()
and Filters\applied()
did_action()
, it doesn't exist any did_filter()
or applied_filter()
.did_action()
for filters, Brain Monkey has a method accessible via Brain\Monkey\Filters\applied()
that does what you might expect.did_action()
and Filters\applied()
return the number of times an action or a filter has been triggered, just like did_action()
does in WordPress, but there's no way to use them to check which arguments were passed to the fired hook.did_action()
and Filters\applied()
are fine for simple tests, mostly because using them you don't need to recall Brain Monkey methods, but they are not very powerful: arguments checking and, above all, the ability to respond to fired hooks are pivotal tasks to proper test WordPress code.Actions\expectDone()
and Filters\expectApplied()
functions.MyClass
above in this page, it can be tested with:with()
, validates hook arguments, not function arguments, it means what is passed to do_action
or apply_filters
excluding hook name itselfapply_filters
by default returns the first argument passed to it, just like WordPress function does when no callback is added to the filter.andReturn()
and andReturnUsing()
expectation methods that can be used to make a filter return anything.andReturnFirstArg()
that can be used to make a filter expectation behave like WordPress does: return first argument received:"Meh!"
.andReturnFirstArg()
comes useful again, to set a "catch all" expectation:do_action()
always returns null
so, if Brain Monkey would allow a mocked returning value for do_action()
expectations, it would be in contrast with real WordPress code, with disastrous effects on tests.andReturn()
or andReturnUsing()
with Actions\expectDone()
because it will throw an exception.do_action()
, like WordPress actually does.whenHappen()
method for action expectations. The method takes a callback to be ran when an action is fired.current_filter()
, doing_action
and doing_filter()
current_filter()
returns false
.current_filter()
correctly resolves to the correct hook during the execution of any callback added to respond to hooks.current_filter()
returns the right hook just like it does in WordPress. Note this will also work with any callback passed to whenHappen()
.doing_action()
and doing_filter()
works as well!