From 464ad2021812d7df7b32ad9f42dbc99ffdb8ff4b Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 22 Mar 2023 09:25:32 +0000 Subject: [PATCH] Tests: Consistently sanitize expiration in the test suite's Memcached implementation. In a previous commit, the `::sanitize_expiration()` call in the `::add()` method was moved closer to where the value is used. This commit does the same for the other methods: * `::cas()` * `::replace()` * `::set()` * `::setMulti()` Follow-up to [40561], [55577]. See #57841, #57963. git-svn-id: https://develop.svn.wordpress.org/trunk@55581 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/includes/object-cache.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/phpunit/includes/object-cache.php b/tests/phpunit/includes/object-cache.php index f232051c6b..f9e2c4693e 100644 --- a/tests/phpunit/includes/object-cache.php +++ b/tests/phpunit/includes/object-cache.php @@ -1181,7 +1181,6 @@ class WP_Object_Cache { */ public function cas( $cas_token, $key, $value, $group = 'default', $expiration = 0, $server_key = '', $by_key = false ) { $derived_key = $this->buildKey( $key, $group ); - $expiration = $this->sanitize_expiration( $expiration ); /** * If group is a non-Memcached group, save to runtime cache, not Memcached. Note @@ -1193,6 +1192,8 @@ class WP_Object_Cache { return true; } + $expiration = $this->sanitize_expiration( $expiration ); + // Save to Memcached. if ( $by_key ) { $result = $this->m->casByKey( $cas_token, $server_key, $derived_key, $value, $expiration ); @@ -1906,7 +1907,6 @@ class WP_Object_Cache { */ public function replace( $key, $value, $group = 'default', $expiration = 0, $server_key = '', $by_key = false ) { $derived_key = $this->buildKey( $key, $group ); - $expiration = $this->sanitize_expiration( $expiration ); // If group is a non-Memcached group, save to runtime cache, not Memcached. if ( in_array( $group, $this->no_mc_groups, true ) ) { @@ -1920,6 +1920,8 @@ class WP_Object_Cache { return true; } + $expiration = $this->sanitize_expiration( $expiration ); + // Save to Memcached. if ( $by_key ) { $result = $this->m->replaceByKey( $server_key, $derived_key, $value, $expiration ); @@ -1971,7 +1973,6 @@ class WP_Object_Cache { */ public function set( $key, $value, $group = 'default', $expiration = 0, $server_key = '', $by_key = false ) { $derived_key = $this->buildKey( $key, $group ); - $expiration = $this->sanitize_expiration( $expiration ); // If group is a non-Memcached group, save to runtime cache, not Memcached. if ( in_array( $group, $this->no_mc_groups, true ) ) { @@ -1979,6 +1980,8 @@ class WP_Object_Cache { return true; } + $expiration = $this->sanitize_expiration( $expiration ); + // Save to Memcached. if ( $by_key ) { $result = $this->m->setByKey( $server_key, $derived_key, $value, $expiration ); @@ -2033,7 +2036,6 @@ class WP_Object_Cache { public function setMulti( $items, $groups = 'default', $expiration = 0, $server_key = '', $by_key = false ) { // Build final keys and replace $items keys with the new keys. $derived_keys = $this->buildKeys( array_keys( $items ), $groups ); - $expiration = $this->sanitize_expiration( $expiration ); $derived_items = array_combine( $derived_keys, $items ); // Do not add to memcached if in no_mc_groups. @@ -2049,6 +2051,8 @@ class WP_Object_Cache { } } + $expiration = $this->sanitize_expiration( $expiration ); + // Save to memcached. if ( $by_key ) { $result = $this->m->setMultiByKey( $server_key, $derived_items, $expiration );