Skip to content

Tests: Clean up redundant hook removals in Abilities API tests#11921

Open
NoumaanAhamed wants to merge 1 commit into
WordPress:trunkfrom
NoumaanAhamed:fix/65301-clean-hooks-abilities-api
Open

Tests: Clean up redundant hook removals in Abilities API tests#11921
NoumaanAhamed wants to merge 1 commit into
WordPress:trunkfrom
NoumaanAhamed:fix/65301-clean-hooks-abilities-api

Conversation

@NoumaanAhamed
Copy link
Copy Markdown

Summary

Removes redundant remove_filter() and remove_action() calls in several Abilities API tests.

Previously, these tests called remove_filter() or remove_action() purely to undo a hook added earlier in the same test. These manual removals are redundant because WP_UnitTestCase_Base::tear_down() natively runs _restore_hooks(), which restores $wp_filter and $wp_actions to a pre-test baseline, ensuring hooks added during a test are automatically removed.

The removals targeted by this PR sit exactly after the hook's last use with only assertions following, meaning they functionally changed nothing. Removals that run in set_up() or set_up_before_class() (and their paired teardowns) have been explicitly preserved since they manage state outside the coverage of _restore_hooks().

Changes

tests/phpunit/tests/abilities-api/

  • wpAbility.php: Removed 10 redundant remove_action() calls.
  • wpRegisterAbilityCategory.php: Removed 1 redundant remove_action() call.
  • wpRegisterAbility.php: Removed 1 redundant remove_action() call.

tests/phpunit/tests/rest-api/

  • wpRestAbilitiesV1CategoriesController.php: Removed 1 redundant remove_filter() call.
  • wpRestAbilitiesV1ListController.php: Removed 2 redundant remove_filter() calls.

Testing

Test Result
npm run test:php -- --group abilities-api ✅ All 245 tests pass successfully
Verify _restore_hooks() handles hook cleanup ✅ Verified

Trac ticket: https://core.trac.wordpress.org/ticket/65301

Use of AI Tools

AI assistance: Yes
Tool(s): Gemini (Antigravity IDE)
Model(s): Gemini 3.1 Pro (High)
Used for: Identifying redundant manual hook removals. Final implementation and testing were reviewed and validated by me.

@github-actions
Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props mohamedahamed.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions
Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

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.

1 participant