Skip to content

Commit 283ccb2

Browse files
authored
Merge pull request #107 from petitphp/fix/expiration-arg
2 parents 5e372e7 + d3298e2 commit 283ccb2

File tree

6 files changed

+82
-6
lines changed

6 files changed

+82
-6
lines changed

features/cache-patch.feature

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Feature: Patch command available for the object cache
88
$set_foo = function(){
99
wp_cache_set( 'my_key', ['foo' => 'bar'] );
1010
wp_cache_set( 'other_key', ['fuz' => 'biz'] );
11+
wp_cache_set( 'my_key_in_group', ['fuz' => 'biz'], 'my_group' );
1112
1213
$complex_key = (object) [
1314
'foo' => (object) [
@@ -34,12 +35,24 @@ Feature: Patch command available for the object cache
3435
Success: Updated cache key 'complex_key'.
3536
"""
3637

38+
When I try `wp cache patch insert my_key_in_group foo bar --group=my_group`
39+
Then STDOUT should be:
40+
"""
41+
Success: Updated cache key 'my_key_in_group'.
42+
"""
43+
3744
When I try `wp cache patch insert unknown_key foo bar`
3845
Then STDERR should be:
3946
"""
4047
Error: Cannot create key "foo" on data type boolean
4148
"""
4249

50+
When I try `wp cache patch insert other_key foo bar --group=unknown_group`
51+
Then STDERR should be:
52+
"""
53+
Error: Cannot create key "foo" on data type boolean
54+
"""
55+
4356
When I run `wp cache patch update my_key foo test`
4457
Then STDOUT should be:
4558
"""
@@ -58,6 +71,12 @@ Feature: Patch command available for the object cache
5871
Success: Updated cache key 'complex_key'.
5972
"""
6073

74+
When I try `wp cache patch update my_key_in_group fuz baz --group=my_group`
75+
Then STDOUT should be:
76+
"""
77+
Success: Updated cache key 'my_key_in_group'.
78+
"""
79+
6180
When I try `wp cache patch update unknown_key foo test`
6281
Then STDERR should be:
6382
"""
@@ -70,12 +89,24 @@ Feature: Patch command available for the object cache
7089
Error: No data exists for key "bar"
7190
"""
7291

92+
When I try `wp cache patch update my_key foo baz --expiration=60`
93+
Then STDOUT should be:
94+
"""
95+
Success: Updated cache key 'my_key'.
96+
"""
97+
7398
When I run `wp cache patch delete my_key foo`
7499
Then STDOUT should be:
75100
"""
76101
Success: Updated cache key 'my_key'.
77102
"""
78103

104+
When I try `wp cache patch delete my_key_in_group fuz --group=my_group`
105+
Then STDOUT should be:
106+
"""
107+
Success: Updated cache key 'my_key_in_group'.
108+
"""
109+
79110
When I try `wp cache patch delete unknown_key foo`
80111
Then STDERR should be:
81112
"""
@@ -87,3 +118,9 @@ Feature: Patch command available for the object cache
87118
"""
88119
Error: No data exists for key "bar"
89120
"""
121+
122+
When I try `wp cache patch delete my_key foo --group=my_group`
123+
Then STDERR should be:
124+
"""
125+
Error: No data exists for key "foo"
126+
"""

features/cache-pluck.feature

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ Feature: Pluck command available for the object cache
2626
baz
2727
"""
2828

29+
When I run `wp cache pluck my_key_2 foo bar --format=json`
30+
Then STDOUT should be:
31+
"""
32+
"baz"
33+
"""
34+
35+
When I run `wp cache pluck my_key_2 foo --format=json`
36+
Then STDOUT should be:
37+
"""
38+
{"bar":"baz"}
39+
"""
40+
2941
When I run `wp cache pluck my_key_3 foo --group=my_custom_group`
3042
Then STDOUT should be:
3143
"""

features/transient-patch.feature

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ Feature: Patch command available for the transient cache
5353
{"foo":{"bar":"baz","fuz":"biz"}}
5454
"""
5555

56+
When I run `wp transient patch insert my_key fiz bar --expiration=300`
57+
Then STDOUT should be:
58+
"""
59+
Success: Updated transient 'my_key'.
60+
"""
61+
62+
When I run `wp transient get my_key --format=json`
63+
Then STDOUT should be:
64+
"""
65+
{"foo":"bar","fuz":"baz","fiz":"bar"}
66+
"""
67+
5668
When I try `wp transient patch insert unknown_key foo bar`
5769
Then STDERR should be:
5870
"""

features/transient-pluck.feature

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ Feature: Pluck command available for the transient cache
1717
baz
1818
"""
1919

20+
When I run `wp transient pluck my_key_2 foo bar --format=json`
21+
Then STDOUT should be:
22+
"""
23+
"baz"
24+
"""
25+
26+
When I run `wp transient pluck my_key_2 foo --format=json`
27+
Then STDOUT should be:
28+
"""
29+
{"bar":"baz"}
30+
"""
31+
2032
When I try `wp transient pluck unknown_key foo`
2133
Then STDERR should be:
2234
"""

src/Cache_Command.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -529,10 +529,10 @@ function ( $key ) {
529529
* ---
530530
*
531531
* [--expiration=<expiration>]
532-
* : Define how long to keep the value, in seconds. `0` means as long as possible.
533-
* ---
534-
* default: 0
535-
* ---
532+
* : Define how long to keep the value, in seconds. `0` means as long as possible.
533+
* ---
534+
* default: 0
535+
* ---
536536
*
537537
* [--format=<format>]
538538
* : The serialization format for the value.
@@ -551,7 +551,7 @@ public function patch( $args, $assoc_args ) {
551551

552552
$group = Utils\get_flag_value( $assoc_args, 'group' );
553553

554-
$expiration = Utils\get_flag_value( $assoc_args, 'expiration' );
554+
$expiration = (int) Utils\get_flag_value( $assoc_args, 'expiration' );
555555

556556
$key_path = array_map(
557557
function ( $key ) {
@@ -604,7 +604,7 @@ function ( $key ) {
604604
if ( $patched_value === $old_value ) {
605605
WP_CLI::success( "Value passed for cache key '$key' is unchanged." );
606606
} else {
607-
$success = wp_cache_set( $key, $patched_value, $group, (int) $expiration );
607+
$success = wp_cache_set( $key, $patched_value, $group, $expiration );
608608
if ( $success ) {
609609
WP_CLI::success( "Updated cache key '$key'." );
610610
} else {

src/Transient_Command.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,9 @@ function ( $key ) {
516516
*
517517
* [--expiration=<expiration>]
518518
* : Time until expiration, in seconds.
519+
* ---
520+
* default: 0
521+
* ---
519522
*
520523
* [--network]
521524
* : Get the value of a network|site transient. On single site, this is

0 commit comments

Comments
 (0)