Make WordPress Core

Changeset 61589


Ignore:
Timestamp:
02/04/2026 09:05:25 AM (6 months ago)
Author:
SergeyBiryukov
Message:

Docs: Document some globals in WP_UnitTestCase_Base class methods.

Follow-up to [26005], [27183], [29251], [30276], [35136], [35258], [38678], [39626], [44633], [56212].

Props noruzzaman, mukesh27, SergeyBiryukov.
See #64224.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/abstract-testcase.php

    r61459 r61589  
    5959        /**
    6060         * Runs the routine before setting up all tests.
     61         *
     62         * @global wpdb $wpdb WordPress database abstraction object.
    6163         */
    6264        public static function set_up_before_class() {
     
    99101        /**
    100102         * Runs the routine before each test is executed.
     103         *
     104         * @global WP_Rewrite $wp_rewrite WordPress rewrite rules object.
    101105         */
    102106        public function set_up() {
     107                global $wp_rewrite;
     108
    103109                set_time_limit( 0 );
    104110
     
    112118                        $this->_backup_hooks();
    113119                }
    114 
    115                 global $wp_rewrite;
    116120
    117121                $this->clean_up_global_scope();
     
    156160        /**
    157161         * After a test method runs, resets any state in WordPress the test method might have changed.
     162         *
     163         * @global wpdb       $wpdb         WordPress database abstraction object.
     164         * @global WP_Query   $wp_the_query WordPress Query object.
     165         * @global WP_Query   $wp_query     WordPress Query object.
     166         * @global WP         $wp           WordPress environment object.
    158167         */
    159168        public function tear_down() {
    160169                global $wpdb, $wp_the_query, $wp_query, $wp;
     170
    161171                $wpdb->query( 'ROLLBACK' );
     172
    162173                if ( is_multisite() ) {
    163174                        while ( ms_is_switched() ) {
     
    360371         * on a class variable so they can be restored on tear_down() using _restore_hooks().
    361372         *
    362          * @global array $wp_filter
    363          * @global array $wp_actions
    364          * @global array $wp_filters
    365          * @global array $wp_current_filter
     373         * @global array $wp_filter         Stores all of the filters and actions.
     374         * @global array $wp_actions        Stores the number of times each action was triggered.
     375         * @global array $wp_filters        Stores the number of times each filter was triggered.
     376         * @global array $wp_current_filter Stores the list of current filters with the current one last.
    366377         */
    367378        protected function _backup_hooks() {
     
    383394         * so that future tests aren't affected by hooks set during this last test.
    384395         *
    385          * @global array $wp_filter
    386          * @global array $wp_actions
    387          * @global array $wp_filters
    388          * @global array $wp_current_filter
     396         * @global array $wp_filter         Stores all of the filters and actions.
     397         * @global array $wp_actions        Stores the number of times each action was triggered.
     398         * @global array $wp_filters        Stores the number of times each filter was triggered.
     399         * @global array $wp_current_filter Stores the list of current filters with the current one last.
    389400         */
    390401        protected function _restore_hooks() {
     
    408419        /**
    409420         * Flushes the WordPress object cache.
     421         *
     422         * @global WP_Object_Cache $wp_object_cache WordPress Object Cache object.
    410423         */
    411424        public static function flush_cache() {
     
    453466         * @since 5.1.0
    454467         *
    455          * @global array $wp_meta_keys
     468         * @global array $wp_meta_keys Global registry for meta keys.
    456469         */
    457470        public function unregister_all_meta_keys() {
    458471                global $wp_meta_keys;
     472
    459473                if ( ! is_array( $wp_meta_keys ) ) {
    460474                        return;
    461475                }
     476
    462477                foreach ( $wp_meta_keys as $object_type => $type_keys ) {
    463478                        foreach ( $type_keys as $object_subtype => $subtype_keys ) {
     
    471486        /**
    472487         * Starts a database transaction.
     488         *
     489         * @global wpdb $wpdb WordPress database abstraction object.
    473490         */
    474491        public function start_transaction() {
    475492                global $wpdb;
     493
    476494                $wpdb->query( 'SET autocommit = 0;' );
    477495                $wpdb->query( 'START TRANSACTION;' );
     496
    478497                add_filter( 'query', array( $this, '_create_temporary_tables' ) );
    479498                add_filter( 'query', array( $this, '_drop_temporary_tables' ) );
     
    484503         *
    485504         * @since 4.1.0
     505         *
     506         * @global wpdb $wpdb WordPress database abstraction object.
    486507         */
    487508        public static function commit_transaction() {
    488509                global $wpdb;
     510
    489511                $wpdb->query( 'COMMIT;' );
    490512        }
     
    11331155         * @since 5.3.0 Formalized the existing `...$prop` parameter by adding it
    11341156         *              to the function signature.
     1157         *
     1158         * @global WP_Query $wp_query WordPress Query object.
    11351159         *
    11361160         * @param string ...$prop Any number of WP_Query properties that are expected to be true for the current request.
     
    16331657         * @since 4.4.0
    16341658         *
    1635          * @global WP_Rewrite $wp_rewrite
     1659         * @global WP_Rewrite $wp_rewrite WordPress rewrite rules object.
    16361660         *
    16371661         * @param string $structure Optional. Permalink structure to set. Default empty.
Note: See TracChangeset for help on using the changeset viewer.