10up / wp_mock

WordPress API Mocking Framework
https://wp-mock.gitbook.io
Other
676 stars 70 forks source link

Add convenience `::expectFilterRemoved()` `::expectActionRemoved()` Fix #157 #246

Open BrianHenryIE opened 4 months ago

BrianHenryIE commented 4 months ago

Summary

As said in #157:

WP_Mock provides useful helpers for expectFilterAdded and expectFilterNotAdded, and [their] companion actions. However, we have no canonical way of checking remove_action nor remove_filter calls.

See: remove_filter().

Closes: #157

Details

It's really just a convenience function on top of WP_Mock::userFunction().

public static function expectFilterRemoved(string $filter, $callback, $priority = null) : void
{
    self::userFunction(
        'remove_filter'
        array(
            'args'   => array_filter(func_get_args()),
            'times'  => 1,
        )
    );
}

We're using array_filter() there to handle the optional use of $priority in remove_filter().

::expectFilterNotRemoved() is the same with 'times' => 0.

Contributor checklist

Testing

Reviewer checklist

- [ ] Code changes review - [ ] Documentation changes review - [ ] Unit tests pass - [ ] Static analysis passes
coveralls commented 4 months ago

Coverage Status

coverage: 64.889% (-1.6%) from 66.445% when pulling 67017782c351c0fceb9d74c53545cb424e1566a1 on BrianHenryIE:add/remove-action-remove-filter into 48b7f22934a4351e45e336f09263ee27fc9ddcbe on 10up:trunk.

coveralls commented 4 months ago

Coverage Status

coverage: 67.522% (+1.1%) from 66.445% when pulling 7d01fcb251bd6be87396602422d13a810ec58b4b on BrianHenryIE:add/remove-action-remove-filter into 48b7f22934a4351e45e336f09263ee27fc9ddcbe on 10up:trunk.

coveralls commented 4 months ago

Coverage Status

coverage: 67.651% (+1.2%) from 66.445% when pulling cd4cff50eca56e67491aafbd772f0e7e988bb388 on BrianHenryIE:add/remove-action-remove-filter into 48b7f22934a4351e45e336f09263ee27fc9ddcbe on 10up:trunk.

coveralls commented 4 months ago

Coverage Status

coverage: 67.651% (+1.2%) from 66.445% when pulling f56c5575258aaa920acd18b87986f4011af1a04e on BrianHenryIE:add/remove-action-remove-filter into 48b7f22934a4351e45e336f09263ee27fc9ddcbe on 10up:trunk.

coveralls commented 3 months ago

Coverage Status

coverage: 67.651% (+1.3%) from 66.312% when pulling 32b889800ce486f32f2bb777a38616bd06a630d2 on BrianHenryIE:add/remove-action-remove-filter into 010d556e0482e4d94776a5b0641429dca00333e4 on 10up:trunk.