Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}
],
"require": {
"wp-cli/wp-cli": "^2.12"
"wp-cli/wp-cli": "^2.13"
},
"require-dev": {
"wp-cli/entity-command": "^1.3 || ^2",
Expand Down
12 changes: 12 additions & 0 deletions features/cache.feature
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Feature: Managed the WordPress object cache

@skip-object-cache
Scenario: Default group is 'default'
Given a WP install
And a wp-content/mu-plugins/test-harness.php file:
Expand Down Expand Up @@ -210,3 +211,14 @@ Feature: Managed the WordPress object cache

When I run `wp cache supports set_multiple`
Then the return code should be 0

@require-object-cache
Scenario: Object caches may return success when deleting non-existent objects
Given a WP install

When I run `wp cache delete nonexistentkey`
Then STDOUT should be:
"""
Success: Object deleted.
"""
And the return code should be 0
44 changes: 44 additions & 0 deletions features/transient.feature
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Feature: Manage WordPress transient cache
Success: Transient deleted.
"""

@skip-object-cache
Scenario: Deleting all transients on single site
Given a WP install
# We set `WP_DEVELOPMENT_MODE` to stop WordPress from automatically creating
Expand Down Expand Up @@ -125,6 +126,7 @@ Feature: Manage WordPress transient cache
Warning: Transient with key "foo4" is not set.
"""

@skip-object-cache
Scenario: Deleting expired transients on single site
Given a WP install
And I run `wp transient set foo bar 600`
Expand Down Expand Up @@ -196,6 +198,7 @@ Feature: Manage WordPress transient cache
bar4
"""

@skip-object-cache
Scenario: Deleting all transients on multisite
Given a WP multisite install
# We set `WP_DEVELOPMENT_MODE` to stop WordPress from automatically creating
Expand Down Expand Up @@ -291,6 +294,7 @@ Feature: Manage WordPress transient cache
Warning: Transient with key "foo6" is not set.
"""

@skip-object-cache
Scenario: Deleting expired transients on multisite
Given a WP multisite install
And I run `wp site create --slug=foo`
Expand Down Expand Up @@ -391,6 +395,7 @@ Feature: Manage WordPress transient cache
bar6
"""

@skip-object-cache
Scenario: List transients on single site
Given a WP install
And I run `wp transient set foo bar`
Expand Down Expand Up @@ -446,6 +451,7 @@ Feature: Manage WordPress transient cache
foo6,bar6,1321009871
"""

@skip-object-cache
Scenario: List transients on multisite
Given a WP multisite install
# We set `WP_DEVELOPMENT_MODE` to stop WordPress from automatically creating
Expand Down Expand Up @@ -504,6 +510,7 @@ Feature: Manage WordPress transient cache
foo6,bar6,1321009871
"""

@skip-object-cache
Scenario: List transients with search and exclude pattern
Given a WP install
And I run `wp transient set foo bar`
Expand Down Expand Up @@ -603,3 +610,40 @@ Feature: Manage WordPress transient cache
name
foo4
"""

@require-object-cache
Scenario: Transient database operations warn when external object cache is active
Given a WP install

When I try `wp transient list --format=count`
Then STDERR should be:
"""
Warning: Transients are stored in an external object cache, and this command only shows those stored in the database.
"""
And STDOUT should be:
"""
0
"""
And the return code should be 0

When I try `wp transient delete --all`
Then STDERR should be:
"""
Warning: Transients are stored in an external object cache, and this command only deletes those stored in the database. You must flush the cache to delete all transients.
"""
And STDOUT should be:
"""
Success: No transients found.
"""
And the return code should be 0

When I try `wp transient delete --expired`
Then STDERR should be:
"""
Warning: Transients are stored in an external object cache, and this command only deletes those stored in the database. You must flush the cache to delete all transients.
"""
And STDOUT should be:
"""
Success: No expired transients found.
"""
And the return code should be 0
3 changes: 1 addition & 2 deletions src/Cache_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ public function delete( $args, $assoc_args ) {
*/
public function flush() {
// TODO: Needs fixing in wp-cli/wp-cli
// @phpstan-ignore offsetAccess.nonOffsetAccessible
if ( WP_CLI::has_config( 'url' ) && ! empty( WP_CLI::get_config()['url'] ) && is_multisite() ) {
WP_CLI::warning( 'Flushing the cache may affect all sites in a multisite installation, depending on the implementation of the object cache.' );
}
Expand Down Expand Up @@ -574,7 +573,7 @@ function ( $key ) {
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 );
$patch_value = WP_CLI::read_value( (string) array_pop( $key_path ), $assoc_args );
} else {
$patch_value = null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Transient_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ function ( $key ) {
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 );
$patch_value = WP_CLI::read_value( (string) array_pop( $key_path ), $assoc_args );
} else {
$patch_value = null;
}
Expand Down