[wp-trac] [WordPress Trac] #65301: Remove redundant remove_filter()/remove_action() calls in abilities test coverage

WordPress Trac noreply at wordpress.org
Thu May 21 10:43:24 UTC 2026


#65301: Remove redundant remove_filter()/remove_action() calls in abilities test
coverage
------------------------------+--------------------
 Reporter:  gziolo            |      Owner:  (none)
     Type:  task (blessed)    |     Status:  new
 Priority:  normal            |  Milestone:  7.1
Component:  Build/Test Tools  |    Version:
 Severity:  normal            |   Keywords:
  Focuses:                    |
------------------------------+--------------------
 Several Abilities API tests call `remove_filter()` / `remove_action()`
 purely to undo a hook added earlier in the same test. These are redundant:
 `WP_UnitTestCase_Base::tear_down()` runs `_restore_hooks()`, which
 restores `$wp_filter`/`$wp_actions` to a pre-test baseline, so hooks added
 during a test are removed automatically. In each case the removal sits
 after the hook's last use, with only assertions following — it changes
 nothing.

 Files to clean up:

 * `tests/phpunit/tests/abilities-api/wpAbility.php`
 * `tests/phpunit/tests/abilities-api/wpRegisterAbilityCategory.php`
 * `tests/phpunit/tests/abilities-api/wpRegisterAbility.php`
 * `tests/phpunit/tests/rest-api/wpRestAbilitiesV1CategoriesController.php`
 * `tests/phpunit/tests/rest-api/wpRestAbilitiesV1ListController.php`
 * `tests/phpunit/tests/rest-api/wpRestAbilitiesV1RunController.php`

 '''Watch for:''' only remove a call when the hook was added in the same
 test and fires for the last time before the removal. Keep removals that
 run in `set_up()`/`set_up_before_class()` (and their paired teardown re-
 adds), since those manage state `_restore_hooks()` doesn't cover — e.g.
 `wpRegisterCoreAbilities.php` toggles the core (un)hook callbacks across
 the whole class.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/65301>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list