Make WordPress Core

Changeset 55741


Ignore:
Timestamp:
05/10/2023 09:09:06 AM (4 years ago)
Author:
spacedmonkey
Message:

Build/Test Tools: Call wp_cache_flush_runtime in WP_UnitTestCase.

In WP_UnitTestCase::flush_cache method, the properties of the global $wp_object_cache object were manaully being reset to flush the cache. The function wp_cache_flush_runtime was added in [52772] and is designed to reset any class properties to default values. Using wp_cache_flush_runtime improve compatibility with third party object caches, as it allows developers to define their own wp_cache_flush_runtime function.

Props rmccue, johnbillion, wonderboymusic, boonebgorges, voldemortensen, dd32, DrewAPicture, tillkruess, spacedmonkey.
Fixes #31463.

Location:
trunk/tests/phpunit/includes
Files:
2 edited

Legend:

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

    r55680 r55741  
    388388                global $wp_object_cache;
    389389
    390                 $wp_object_cache->group_ops      = array();
    391                 $wp_object_cache->stats          = array();
    392                 $wp_object_cache->memcache_debug = array();
    393                 $wp_object_cache->cache          = array();
    394 
    395                 if ( method_exists( $wp_object_cache, '__remoteset' ) ) {
     390                wp_cache_flush_runtime();
     391
     392                if ( is_object( $wp_object_cache ) && method_exists( $wp_object_cache, '__remoteset' ) ) {
    396393                        $wp_object_cache->__remoteset();
    397394                }
  • trunk/tests/phpunit/includes/object-cache.php

    r55581 r55741  
    326326        switch ( $feature ) {
    327327                case 'get_multiple':
     328                case 'flush_runtime':
    328329                        return true;
    329330                default:
    330331                        return false;
    331332        }
     333}
     334
     335/**
     336 * Removes all cache items from the in-memory runtime cache.
     337 *
     338 * @return bool True on success, false on failure.
     339 */
     340function wp_cache_flush_runtime() {
     341        global $wp_object_cache;
     342        return $wp_object_cache->flush_runtime();
    332343}
    333344
    … …  
    14111422
    14121423                return $result;
     1424        }
     1425
     1426        /**
     1427         * Clears the in-memory cache of all data leaving the external cache untouched.
     1428         *
     1429         * @return bool Always returns true.
     1430         */
     1431        public function flush_runtime() {
     1432                $this->cache = array();
     1433
     1434                return true;
    14131435        }
    14141436
Note: See TracChangeset for help on using the changeset viewer.