Skip to content

Commit af683a3

Browse files
committed
Update Behat features tests
Split features for patch/pluck commands into their own file and use `When I run` for commands when they have a successful outcome.
1 parent 85fcc37 commit af683a3

File tree

6 files changed

+332
-328
lines changed

6 files changed

+332
-328
lines changed

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: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
"""

features/cache.feature

Lines changed: 0 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -210,123 +210,3 @@ Feature: Managed the WordPress object cache
210210

211211
When I run `wp cache supports set_multiple`
212212
Then the return code should be 0
213-
214-
Scenario: Nested values from cache can be retrieved at any depth.
215-
Given a WP install
216-
And a wp-content/mu-plugins/test-harness.php file:
217-
"""
218-
<?php
219-
$set_foo = function(){
220-
wp_cache_set( 'my_key', ['foo' => 'bar'] );
221-
wp_cache_set( 'my_key_2', ['foo' => ['bar' => 'baz']] );
222-
wp_cache_set( 'my_key_3', ['foo' => 'bar_custom'], 'my_custom_group' );
223-
};
224-
225-
WP_CLI::add_hook( 'before_invoke:cache pluck', $set_foo );
226-
"""
227-
228-
When I try `wp cache pluck my_key foo`
229-
Then STDOUT should be:
230-
"""
231-
bar
232-
"""
233-
234-
When I try `wp cache pluck my_key_2 foo bar`
235-
Then STDOUT should be:
236-
"""
237-
baz
238-
"""
239-
240-
When I try `wp cache pluck my_key_3 foo --group=my_custom_group`
241-
Then STDOUT should be:
242-
"""
243-
bar_custom
244-
"""
245-
246-
Scenario: Nested values from cache can be updated at any depth.
247-
Given a WP install
248-
And a wp-content/mu-plugins/test-harness.php file:
249-
"""
250-
<?php
251-
$set_foo = function(){
252-
wp_cache_set( 'my_key', ['foo' => 'bar'] );
253-
wp_cache_set( 'other_key', ['fuz' => 'biz'] );
254-
255-
$complex_key = (object) [
256-
'foo' => (object) [
257-
'bar' => (object) [
258-
'baz' => 2,
259-
],
260-
],
261-
];
262-
wp_cache_set( 'complex_key', $complex_key );
263-
};
264-
265-
WP_CLI::add_hook( 'before_invoke:cache patch', $set_foo );
266-
"""
267-
268-
When I try `wp cache patch insert my_key fuz baz`
269-
Then STDOUT should be:
270-
"""
271-
Success: Updated cache key 'my_key'.
272-
"""
273-
274-
When I try `wp cache patch insert complex_key foo bar fuz 34`
275-
Then STDOUT should be:
276-
"""
277-
Success: Updated cache key 'complex_key'.
278-
"""
279-
280-
When I try `wp cache patch insert unknown_key foo bar`
281-
Then STDERR should be:
282-
"""
283-
Error: Cannot create key "foo" on data type boolean
284-
"""
285-
286-
When I try `wp cache patch update my_key foo test`
287-
Then STDOUT should be:
288-
"""
289-
Success: Updated cache key 'my_key'.
290-
"""
291-
292-
When I try `wp cache patch update other_key fuz biz`
293-
Then STDOUT should be:
294-
"""
295-
Success: Value passed for cache key 'other_key' is unchanged.
296-
"""
297-
298-
When I try `wp cache patch update complex_key foo bar baz 34`
299-
Then STDOUT should be:
300-
"""
301-
Success: Updated cache key 'complex_key'.
302-
"""
303-
304-
When I try `wp cache patch update unknown_key foo test`
305-
Then STDERR should be:
306-
"""
307-
Error: No data exists for key "foo"
308-
"""
309-
310-
When I try `wp cache patch update my_key bar test`
311-
Then STDERR should be:
312-
"""
313-
Error: No data exists for key "bar"
314-
"""
315-
316-
When I try `wp cache patch delete my_key foo`
317-
Then STDOUT should be:
318-
"""
319-
Success: Updated cache key 'my_key'.
320-
"""
321-
322-
When I try `wp cache patch delete unknown_key foo`
323-
Then STDERR should be:
324-
"""
325-
Error: No data exists for key "foo"
326-
"""
327-
328-
When I try `wp cache patch delete my_key bar`
329-
Then STDERR should be:
330-
"""
331-
Error: No data exists for key "bar"
332-
"""

0 commit comments

Comments
 (0)