diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php index 95a0e0df57..b03d12a097 100644 --- a/tests/phpunit/includes/abstract-testcase.php +++ b/tests/phpunit/includes/abstract-testcase.php @@ -387,12 +387,9 @@ abstract class WP_UnitTestCase_Base extends PHPUnit_Adapter_TestCase { public static function flush_cache() { global $wp_object_cache; - $wp_object_cache->group_ops = array(); - $wp_object_cache->stats = array(); - $wp_object_cache->memcache_debug = array(); - $wp_object_cache->cache = array(); + wp_cache_flush_runtime(); - if ( method_exists( $wp_object_cache, '__remoteset' ) ) { + if ( is_object( $wp_object_cache ) && method_exists( $wp_object_cache, '__remoteset' ) ) { $wp_object_cache->__remoteset(); } diff --git a/tests/phpunit/includes/object-cache.php b/tests/phpunit/includes/object-cache.php index f9e2c4693e..2bea171f19 100644 --- a/tests/phpunit/includes/object-cache.php +++ b/tests/phpunit/includes/object-cache.php @@ -325,12 +325,23 @@ function wp_cache_flush( $delay = 0 ) { function wp_cache_supports( $feature ) { switch ( $feature ) { case 'get_multiple': + case 'flush_runtime': return true; default: return false; } } +/** + * Removes all cache items from the in-memory runtime cache. + * + * @return bool True on success, false on failure. + */ +function wp_cache_flush_runtime() { + global $wp_object_cache; + return $wp_object_cache->flush_runtime(); +} + /** * Retrieves object from cache. * @@ -1412,6 +1423,17 @@ class WP_Object_Cache { return $result; } + /** + * Clears the in-memory cache of all data leaving the external cache untouched. + * + * @return bool Always returns true. + */ + public function flush_runtime() { + $this->cache = array(); + + return true; + } + /** * Retrieves object from cache. *