Skip to content

Conversation

@BrianHenryIE
Copy link
Contributor

@BrianHenryIE BrianHenryIE commented Jun 26, 2024

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

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly
  • I have added tests to cover changes introduced by this pull request
  • All new and existing tests pass

Testing

Reviewer checklist

  • Code changes review
  • Documentation changes review
  • Unit tests pass
  • Static analysis passes

@coveralls
Copy link

Coverage Status

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

@coveralls
Copy link

Coverage Status

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

@coveralls
Copy link

Coverage Status

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

@coveralls
Copy link

Coverage Status

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

@BrianHenryIE BrianHenryIE marked this pull request as ready for review June 27, 2024 22:54
@nmolham-godaddy nmolham-godaddy self-requested a review July 24, 2024 03:09
@coveralls
Copy link

coveralls commented Jul 24, 2024

Coverage Status

coverage: 67.215% (+1.1%) from 66.142%
when pulling d6e40f7 on BrianHenryIE:add/remove-action-remove-filter
into 446ea70 on 10up:trunk.

Copy link
Contributor

@nmolham-godaddy nmolham-godaddy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @BrianHenryIE for this nice PR, I have a couple of suggestions below, which I added for one method, but apply for all of the other new methods as well.

nmolham-godaddy and others added 6 commits August 8, 2024 14:42
Co-authored-by: Nabeel Molham <72820458+nmolham-godaddy@users.noreply.github.com>
Co-authored-by: Nabeel Molham <72820458+nmolham-godaddy@users.noreply.github.com>
@BrianHenryIE
Copy link
Contributor Author

BrianHenryIE commented Jan 16, 2026

  • 0 is a valid action priority so I changed the suggestion's if ($priority) { to an is_null() check rather than a falsey check
  • I removed the ?int type on $priority to allow Type also
  • Removed the explicit Mockery\Expectation return type and set the PhpDoc to ExpectationInterface after tests failed because they returned CompositeExpectation (from Functions::setUpMock()) and updated the intermediate PhpDoc
  • I updated the other functions to apply the suggestions
  • Added a documentation line to suggest where using \WP_Mock\Functions::type( 'int' ) might be helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add expectHookRemoved and expectHookNotRemoved support

3 participants