Make WordPress Core

Opened 2 years ago

Closed 23 months ago

Last modified 23 months ago

#57236 closed defect (bug) (fixed)

Add $wp_filters to WP_UnitTestCase_Base::_backup_hooks() and ::_restore_hooks()

Reported by: sergeybiryukov's profile SergeyBiryukov Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 6.2 Priority: normal
Severity: normal Version:
Component: Build/Test Tools Keywords: good-first-bug has-patch has-unit-tests
Focuses: Cc:

Description

Background: #28535, #35357.

  • [29251] / #28535 introduced saving the state of filter-related globals ($wp_actions, $wp_current_filter, and $wp_filter) between running individual unit tests, so that all tests initially use the same filters/actions.
  • [53803] / #35357 added a new global, $wp_filters. It should be reset too, along with $wp_actions.

The change should be made in WP_UnitTestCase_Base::_backup_hooks() and ::_restore_hooks().

Change History (3)

This ticket was mentioned in PR #3739 on WordPress/wordpress-develop by @sanjucta.


2 years ago
#1

  • Keywords has-patch has-unit-tests added; needs-patch removed

Backs up $wp_filters global before running test cases

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

#2 @SergeyBiryukov
23 months ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 55160:

Build/Test Tools: Back up and restore the $wp_filters global when running tests.

Introduced along with the did_filter() function, the $wp_filters global stores the number of times each filter has been applied during the current request.

This commit adds $wp_filters to the list of globals that are saved in WP_UnitTestCase_Base::_backup_hooks() and restored in ::_restore_hooks() so that hooks set by the current test do not accidentally affect future tests.

Additionally, this commit brings some consistency by backing up and restoring the hook-related globals in the same order they are defined in wp-includes/plugin.php.

Follow-up to [29251], [53803].

Props sanjucta, SergeyBiryukov.
Fixes #57236.

@SergeyBiryukov commented on PR #3739:


23 months ago
#3

Thanks for the PR! Merged in r55160.

Note: See TracTickets for help on using tickets.