Tests: Clean up redundant hook removals in Abilities API tests#11921
Tests: Clean up redundant hook removals in Abilities API tests#11921NoumaanAhamed wants to merge 1 commit into
Conversation
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Summary
Removes redundant
remove_filter()andremove_action()calls in several Abilities API tests.Previously, these tests called
remove_filter()orremove_action()purely to undo a hook added earlier in the same test. These manual removals are redundant becauseWP_UnitTestCase_Base::tear_down()natively runs_restore_hooks(), which restores$wp_filterand$wp_actionsto 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()orset_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 redundantremove_action()calls.wpRegisterAbilityCategory.php: Removed 1 redundantremove_action()call.wpRegisterAbility.php: Removed 1 redundantremove_action()call.tests/phpunit/tests/rest-api/wpRestAbilitiesV1CategoriesController.php: Removed 1 redundantremove_filter()call.wpRestAbilitiesV1ListController.php: Removed 2 redundantremove_filter()calls.Testing
npm run test:php -- --group abilities-api_restore_hooks()handles hook cleanupTrac 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.