Skip to content

Commit

Permalink
Fix failing functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
petitphp committed Sep 18, 2023
1 parent 6e5ecdf commit e75e7c1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
5 changes: 2 additions & 3 deletions features/cache-patch.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ Feature: Patch command available for the object cache
"""php
<?php
$set_foo = function(){
//TODO: DEBUG, remove before merging branch.
WP_CLI::log( var_export( wp_cache_set( 'my_key', ['foo' => '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) [
Expand Down
20 changes: 15 additions & 5 deletions src/Cache_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
20 changes: 15 additions & 5 deletions src/Transient_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit e75e7c1

Please sign in to comment.