Skip to content

Commit 1d789af

Browse files
authored
Merge pull request #89 from petitphp/feature/pluck-patch-cache-transient
2 parents dec8eae + de71744 commit 1d789af

File tree

7 files changed

+850
-2
lines changed

7 files changed

+850
-2
lines changed

composer.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,20 @@
4141
"cache flush-group",
4242
"cache get",
4343
"cache incr",
44+
"cache patch",
45+
"cache pluck",
4446
"cache replace",
4547
"cache set",
4648
"cache supports",
4749
"cache type",
4850
"transient",
4951
"transient delete",
5052
"transient get",
53+
"transient list",
54+
"transient patch",
55+
"transient pluck",
5156
"transient set",
52-
"transient type",
53-
"transient list"
57+
"transient type"
5458
]
5559
},
5660
"autoload": {

features/cache-patch.feature

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
Feature: Patch command available for the object cache
2+
3+
Scenario: Nested values from cache can be updated at any depth.
4+
Given a WP install
5+
And a wp-content/mu-plugins/test-harness.php file:
6+
"""php
7+
<?php
8+
$set_foo = function(){
9+
wp_cache_set( 'my_key', ['foo' => 'bar'] );
10+
wp_cache_set( 'other_key', ['fuz' => 'biz'] );
11+
12+
$complex_key = (object) [
13+
'foo' => (object) [
14+
'bar' => (object) [
15+
'baz' => 2,
16+
],
17+
],
18+
];
19+
wp_cache_set( 'complex_key', $complex_key );
20+
};
21+
22+
WP_CLI::add_hook( 'before_invoke:cache patch', $set_foo );
23+
"""
24+
25+
When I run `wp cache patch insert my_key fuz baz`
26+
Then STDOUT should be:
27+
"""
28+
Success: Updated cache key 'my_key'.
29+
"""
30+
31+
When I run `wp cache patch insert complex_key foo bar fuz 34`
32+
Then STDOUT should be:
33+
"""
34+
Success: Updated cache key 'complex_key'.
35+
"""
36+
37+
When I try `wp cache patch insert unknown_key foo bar`
38+
Then STDERR should be:
39+
"""
40+
Error: Cannot create key "foo" on data type boolean
41+
"""
42+
43+
When I run `wp cache patch update my_key foo test`
44+
Then STDOUT should be:
45+
"""
46+
Success: Updated cache key 'my_key'.
47+
"""
48+
49+
When I run `wp cache patch update other_key fuz biz`
50+
Then STDOUT should be:
51+
"""
52+
Success: Value passed for cache key 'other_key' is unchanged.
53+
"""
54+
55+
When I run `wp cache patch update complex_key foo bar baz 34`
56+
Then STDOUT should be:
57+
"""
58+
Success: Updated cache key 'complex_key'.
59+
"""
60+
61+
When I try `wp cache patch update unknown_key foo test`
62+
Then STDERR should be:
63+
"""
64+
Error: No data exists for key "foo"
65+
"""
66+
67+
When I try `wp cache patch update my_key bar test`
68+
Then STDERR should be:
69+
"""
70+
Error: No data exists for key "bar"
71+
"""
72+
73+
When I run `wp cache patch delete my_key foo`
74+
Then STDOUT should be:
75+
"""
76+
Success: Updated cache key 'my_key'.
77+
"""
78+
79+
When I try `wp cache patch delete unknown_key foo`
80+
Then STDERR should be:
81+
"""
82+
Error: No data exists for key "foo"
83+
"""
84+
85+
When I try `wp cache patch delete my_key bar`
86+
Then STDERR should be:
87+
"""
88+
Error: No data exists for key "bar"
89+
"""

features/cache-pluck.feature

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
Feature: Pluck command available for the object cache
2+
3+
Scenario: Nested values from cache can be retrieved at any depth.
4+
Given a WP install
5+
And a wp-content/mu-plugins/test-harness.php file:
6+
"""php
7+
<?php
8+
$set_foo = function(){
9+
wp_cache_set( 'my_key', ['foo' => 'bar'] );
10+
wp_cache_set( 'my_key_2', ['foo' => ['bar' => 'baz']] );
11+
wp_cache_set( 'my_key_3', ['foo' => 'bar_custom'], 'my_custom_group' );
12+
};
13+
14+
WP_CLI::add_hook( 'before_invoke:cache pluck', $set_foo );
15+
"""
16+
17+
When I run `wp cache pluck my_key foo`
18+
Then STDOUT should be:
19+
"""
20+
bar
21+
"""
22+
23+
When I run `wp cache pluck my_key_2 foo bar`
24+
Then STDOUT should be:
25+
"""
26+
baz
27+
"""
28+
29+
When I run `wp cache pluck my_key_3 foo --group=my_custom_group`
30+
Then STDOUT should be:
31+
"""
32+
bar_custom
33+
"""
34+
35+
When I try `wp cache pluck unknown_key test`
36+
Then STDERR should be:
37+
"""
38+
Warning: No object found for the key 'unknown_key' in group 'default'
39+
"""
40+

0 commit comments

Comments
 (0)