From e75e7c1ef991537ed2cbf358f2e2c17b5efb4728 Mon Sep 17 00:00:00 2001 From: Clement Boirie Date: Fri, 15 Sep 2023 16:20:00 +0200 Subject: [PATCH] Fix failing functional tests --- features/cache-patch.feature | 5 ++--- src/Cache_Command.php | 20 +++++++++++++++----- src/Transient_Command.php | 20 +++++++++++++++----- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/features/cache-patch.feature b/features/cache-patch.feature index f79e9386..770cb14a 100644 --- a/features/cache-patch.feature +++ b/features/cache-patch.feature @@ -6,9 +6,8 @@ Feature: Patch command available for the object cache """php 'bar'] ), true ) ); - WP_CLI::log( var_export( wp_cache_set( 'other_key', ['fuz' => 'biz'] ), true ) ); + wp_cache_set( 'my_key', ['foo' => 'bar'] ); + wp_cache_set( 'other_key', ['fuz' => 'biz'] ); $complex_key = (object) [ 'foo' => (object) [ diff --git a/src/Cache_Command.php b/src/Cache_Command.php index 4f2540fd..df5394b1 100644 --- a/src/Cache_Command.php +++ b/src/Cache_Command.php @@ -530,12 +530,22 @@ function ( $key ) { if ( 'delete' === $action ) { $patch_value = null; - } elseif ( \WP_CLI\Entity\Utils::has_stdin() ) { - $stdin_value = WP_CLI::get_value_from_arg_or_stdin( $args, - 1 ); - $patch_value = WP_CLI::read_value( trim( $stdin_value ), $assoc_args ); } else { - // Take the patch value as the last positional argument. Mutates $key_path to be 1 element shorter! - $patch_value = WP_CLI::read_value( array_pop( $key_path ), $assoc_args ); + $stdin_value = WP_CLI\Cache\Utils::has_stdin() + ? trim( WP_CLI::get_value_from_arg_or_stdin( $args, -1 ) ) + : null; + + if ( ! empty( $stdin_value ) ) { + $patch_value = WP_CLI::read_value( $stdin_value, $assoc_args ); + } elseif ( count( $key_path ) > 1 ) { + $patch_value = WP_CLI::read_value( array_pop( $key_path ), $assoc_args ); + } else { + $patch_value = null; + } + + if ( null === $patch_value ) { + WP_CLI::error( 'Please provide value to update.' ); + } } /* Need to make a copy of $current_value here as it is modified by reference */ diff --git a/src/Transient_Command.php b/src/Transient_Command.php index d6dc4cc4..e1814a1b 100644 --- a/src/Transient_Command.php +++ b/src/Transient_Command.php @@ -523,12 +523,22 @@ function ( $key ) { if ( 'delete' === $action ) { $patch_value = null; - } elseif ( \WP_CLI\Entity\Utils::has_stdin() ) { - $stdin_value = WP_CLI::get_value_from_arg_or_stdin( $args, - 1 ); - $patch_value = WP_CLI::read_value( trim( $stdin_value ), $assoc_args ); } else { - // Take the patch value as the last positional argument. Mutates $key_path to be 1 element shorter! - $patch_value = WP_CLI::read_value( array_pop( $key_path ), $assoc_args ); + $stdin_value = WP_CLI\Cache\Utils::has_stdin() + ? trim( WP_CLI::get_value_from_arg_or_stdin( $args, -1 ) ) + : null; + + if ( ! empty( $stdin_value ) ) { + $patch_value = WP_CLI::read_value( $stdin_value, $assoc_args ); + } elseif ( count( $key_path ) > 1 ) { + $patch_value = WP_CLI::read_value( array_pop( $key_path ), $assoc_args ); + } else { + $patch_value = null; + } + + if ( null === $patch_value ) { + WP_CLI::error( 'Please provide value to update.' ); + } } /* Need to make a copy of $current_value here as it is modified by reference */