-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathcache.feature
More file actions
224 lines (194 loc) · 5.89 KB
/
cache.feature
File metadata and controls
224 lines (194 loc) · 5.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
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:
"""
<?php
$set_foo = function(){
wp_cache_set( 'foo', 'bar' );
};
$set_foo_value = function() {
wp_cache_set( 'foo', 2 );
};
$log_foo_value = function() {
WP_CLI::log( var_export( wp_cache_get( 'foo' ), true ) );
};
WP_CLI::add_hook( 'before_invoke:cache get', $set_foo );
WP_CLI::add_hook( 'before_invoke:cache delete', $set_foo );
WP_CLI::add_hook( 'before_invoke:cache add', $set_foo );
WP_CLI::add_hook( 'before_invoke:cache incr', $set_foo_value );
WP_CLI::add_hook( 'before_invoke:cache decr', $set_foo_value );
WP_CLI::add_hook( 'after_invoke:cache set', $log_foo_value );
WP_CLI::add_hook( 'before_invoke:cache replace', $set_foo_value );
"""
When I run `wp cache get foo`
Then STDOUT should be:
"""
bar
"""
When I try `wp cache get bar`
Then STDERR should be:
"""
Error: Object with key 'bar' and group 'default' not found.
"""
When I try `wp cache get bar burrito`
Then STDERR should be:
"""
Error: Object with key 'bar' and group 'burrito' not found.
"""
When I run `wp cache delete foo`
Then STDOUT should be:
"""
Success: Object deleted.
"""
When I try `wp cache delete bar`
Then STDERR should be:
"""
Error: The object was not deleted.
"""
When I try `wp cache add foo bar`
Then STDERR should be:
"""
Error: Could not add object 'foo' in group 'default'. Does it already exist?
"""
When I run `wp cache add bar burrito`
Then STDOUT should be:
"""
Success: Added object 'bar' in group 'default'.
"""
When I run `wp cache add bar foo burrito`
Then STDOUT should be:
"""
Success: Added object 'bar' in group 'burrito'.
"""
When I run `wp cache incr foo`
Then STDOUT should be:
"""
3
"""
When I run `wp cache incr foo 2`
Then STDOUT should be:
"""
4
"""
When I try `wp cache incr bar`
Then STDERR should be:
"""
Error: The value was not incremented.
"""
When I run `wp cache decr foo`
Then STDOUT should be:
"""
1
"""
When I run `wp cache decr foo 2`
Then STDOUT should be:
"""
0
"""
When I try `wp cache decr bar`
Then STDERR should be:
"""
Error: The value was not decremented.
"""
When I run `wp cache set foo bar`
Then STDOUT should be:
"""
Success: Set object 'foo' in group 'default'.
'bar'
"""
When I run `wp cache set burrito foo bar`
Then STDOUT should be:
"""
Success: Set object 'burrito' in group 'bar'.
false
"""
When I run `wp cache replace foo burrito`
Then STDOUT should be:
"""
Success: Replaced object 'foo' in group 'default'.
"""
When I try `wp cache replace bar burrito foo`
Then STDERR should be:
"""
Error: Could not replace object 'bar' in group 'foo'. Does it not exist?
"""
@require-wp-6.1
Scenario: Some cache groups cannot be cleared.
Given a WP install
When I run `wp cache flush-group add_multiple`
Then STDOUT should be:
"""
Success: Cache group 'add_multiple' was flushed.
"""
@require-wp-6.1
Scenario: Some cache groups cannot be cleared.
Given a WP install
And a wp-content/mu-plugins/unclearable-test-cache.php file:
"""php
<?php
class Dummy_Object_Cache extends WP_Object_Cache {
public function flush_group( $group ) {
if ( $group === 'permanent_root_cache' ) {
return false;
}
return parent::flush_group( $group );
}
}
$GLOBALS['wp_object_cache'] = new Dummy_Object_Cache();
"""
When I try `wp cache flush-group permanent_root_cache`
Then STDERR should be:
"""
Error: Cache group 'permanent_root_cache' was not flushed.
"""
@less-than-wp-6.1
Scenario: Some cache groups cannot be cleared.
Given a WP install
And a wp-content/mu-plugins/unclearable-test-cache.php file:
"""php
<?php
class Dummy_Object_Cache extends WP_Object_Cache {
public function flush_group( $group ) {
if ( $group === 'permanent_root_cache' ) {
return false;
}
return parent::flush_group( $group );
}
}
$GLOBALS['wp_object_cache'] = new Dummy_Object_Cache();
"""
When I try `wp cache flush-group permanent_root_cache`
Then STDERR should be:
"""
Error: Group flushing is not supported.
"""
Scenario: Flushing cache on a multisite installation
Given a WP multisite installation
When I try `wp cache flush`
Then STDERR should not contain:
"""
Warning: Flushing the cache may affect all sites in a multisite installation, depending on the implementation of the object cache.
"""
When I try `wp cache flush --url=example.com`
Then STDERR should contain:
"""
Warning: Flushing the cache may affect all sites in a multisite installation, depending on the implementation of the object cache.
"""
@require-wp-6.1
Scenario: Checking if the cache supports a feature
Given a WP install
When I try `wp cache supports non_existing`
Then the return code should be 1
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