MyTestCase
that is assumed very similar to the one coded in the WordPress / Setup docs section.has_action()
and has_filter()
has_action()
and has_filter()
that, just like real WordPress functions can be used to test if some hook (action or filter) has been added, and also verify the arguments.$this
outside of the class.has_action
and has_filter
allow to check this cases with a very intuitive syntax:->
and the method name followed by parenthesis.::
and the method name followed by parenthesis, e.g. 'Some\Name\Space\MyClass::init()'
__invoke()
method) can be identified by the class name followed by parenthesis, e.g. 'Some\Name\Space\MyClass()'
has_action()
/ has_filter()
if a specific closure has been added to an hook.static
closures. Following closure:remove_action
or remove_filter
can make impossible to test some code using has_action
and has_filter
, because hooks are actually removed.with()
, validates hook arguments, not function arguments, it means what is passed to add_action()
or add_filter()
excluding hook name itself.Call to undefined function add_action()
it could have to do with how you are loading your plugin file in the bootstrap.php file. See some tips for procedural/OOP setup.add_action()
and add_filter()
always return true
.true
as well.andReturn
method that allows to force an expectation to return a given value.expectAdded()
method works with Mockery expectations, you may be tempted to use it... if you do that an exception will be thrown.add_action
and add_filter
that had been in contrast with real WordPress code, with disastrous effects on tests.