Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pluck/patch commands for caches and transients #89

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d212c2e
Add `RecursiveDataStructureTraverser` helper to manipulate nested data
petitphp Jun 26, 2023
7292638
add pluck command to cache
petitphp Jun 26, 2023
8e1b63d
add pluck command to transient
petitphp Jun 26, 2023
6e286af
add patch command to cache
petitphp Jul 1, 2023
bd13459
add patch command to transient
petitphp Aug 23, 2023
05424ec
Add missing `expiration` option for patch cache command
petitphp Aug 23, 2023
ca02d28
Fix cs
petitphp Aug 28, 2023
15ad011
Update Behat features tests
petitphp Aug 31, 2023
ba1f610
Add temporary log to debug failing tests in github action
petitphp Aug 31, 2023
6b8d91c
Small CS fixes for WPCS v3
petitphp Sep 7, 2023
a70e2d7
Fix failing functional tests
petitphp Sep 15, 2023
5d0e6df
Add tests for RecursiveDataStructureTraverser.php
petitphp Sep 18, 2023
dd9eec3
Fix wrong command in docblock
petitphp Sep 19, 2023
d174717
Fix CS issue
petitphp Sep 19, 2023
ae6d0a6
Reuse has_stdin() from framework
schlessera Nov 14, 2023
b74bc47
Fix PHPCS issues
schlessera Nov 14, 2023
d28445f
Use `wp eval` to set the transient
petitphp Dec 4, 2023
b1afe2e
split `patch` feature tests and add additionnal checks with `transien…
petitphp Dec 8, 2023
8d9ba42
split `patch` feature tests for site transient and add additionnal ch…
petitphp Dec 11, 2023
7d3a483
Add test cases for invalid keys
petitphp Dec 11, 2023
d061301
Refactor `pluck` feature tests to use `wp eval` to set the transient
petitphp Dec 11, 2023
cf568fb
new feature test for calling cache pluck command with invalid key
petitphp Dec 12, 2023
3fa7fe1
add the new commands to the `composer.json`
petitphp Apr 26, 2024
119c991
use string interpolation for building message
petitphp Apr 29, 2024
2d17185
explicitly call update methods for clearer code
petitphp Apr 29, 2024
9eca4d9
fix tests
petitphp Apr 29, 2024
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
10 changes: 7 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}
],
"require": {
"wp-cli/wp-cli": "^2.5"
swissspidy marked this conversation as resolved.
Show resolved Hide resolved
"wp-cli/wp-cli": "^2.10"
},
"require-dev": {
"wp-cli/entity-command": "^1.3 || ^2",
Expand Down Expand Up @@ -40,16 +40,20 @@
"cache flush-group",
"cache get",
"cache incr",
"cache patch",
"cache pluck",
"cache replace",
"cache set",
"cache supports",
"cache type",
"transient",
"transient delete",
"transient get",
"transient list",
"transient patch",
"transient pluck",
"transient set",
"transient type",
"transient list"
"transient type"
]
},
"autoload": {
Expand Down
89 changes: 89 additions & 0 deletions features/cache-patch.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
Feature: Patch command available for the object cache

Scenario: Nested values from cache can be updated at any depth.
Given a WP install
And a wp-content/mu-plugins/test-harness.php file:
"""php
<?php
$set_foo = function(){
wp_cache_set( 'my_key', ['foo' => 'bar'] );
wp_cache_set( 'other_key', ['fuz' => 'biz'] );

$complex_key = (object) [
'foo' => (object) [
'bar' => (object) [
'baz' => 2,
],
],
];
wp_cache_set( 'complex_key', $complex_key );
};

WP_CLI::add_hook( 'before_invoke:cache patch', $set_foo );
"""

When I run `wp cache patch insert my_key fuz baz`
Then STDOUT should be:
"""
Success: Updated cache key 'my_key'.
"""

When I run `wp cache patch insert complex_key foo bar fuz 34`
Then STDOUT should be:
"""
Success: Updated cache key 'complex_key'.
"""

When I try `wp cache patch insert unknown_key foo bar`
Then STDERR should be:
"""
Error: Cannot create key "foo" on data type boolean
"""

When I run `wp cache patch update my_key foo test`
Then STDOUT should be:
"""
Success: Updated cache key 'my_key'.
"""

When I run `wp cache patch update other_key fuz biz`
Then STDOUT should be:
"""
Success: Value passed for cache key 'other_key' is unchanged.
"""

When I run `wp cache patch update complex_key foo bar baz 34`
Then STDOUT should be:
"""
Success: Updated cache key 'complex_key'.
"""

When I try `wp cache patch update unknown_key foo test`
Then STDERR should be:
"""
Error: No data exists for key "foo"
"""

When I try `wp cache patch update my_key bar test`
Then STDERR should be:
"""
Error: No data exists for key "bar"
"""

When I run `wp cache patch delete my_key foo`
Then STDOUT should be:
"""
Success: Updated cache key 'my_key'.
"""

When I try `wp cache patch delete unknown_key foo`
Then STDERR should be:
"""
Error: No data exists for key "foo"
"""

When I try `wp cache patch delete my_key bar`
Then STDERR should be:
"""
Error: No data exists for key "bar"
"""
40 changes: 40 additions & 0 deletions features/cache-pluck.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Feature: Pluck command available for the object cache

Scenario: Nested values from cache can be retrieved at any depth.
Given a WP install
And a wp-content/mu-plugins/test-harness.php file:
"""php
<?php
$set_foo = function(){
wp_cache_set( 'my_key', ['foo' => 'bar'] );
wp_cache_set( 'my_key_2', ['foo' => ['bar' => 'baz']] );
wp_cache_set( 'my_key_3', ['foo' => 'bar_custom'], 'my_custom_group' );
};

WP_CLI::add_hook( 'before_invoke:cache pluck', $set_foo );
"""

When I run `wp cache pluck my_key foo`
Then STDOUT should be:
"""
bar
"""

When I run `wp cache pluck my_key_2 foo bar`
Then STDOUT should be:
"""
baz
"""

When I run `wp cache pluck my_key_3 foo --group=my_custom_group`
Then STDOUT should be:
"""
bar_custom
"""

When I try `wp cache pluck unknown_key test`
Then STDERR should be:
"""
Warning: No object found for the key 'unknown_key' in group 'default'
"""

Loading
Loading