Skip to content

Commit d061301

Browse files
petitphpschlessera
authored andcommitted
Refactor pluck feature tests to use wp eval to set the transient
1 parent 7d3a483 commit d061301

File tree

1 file changed

+22
-26
lines changed

1 file changed

+22
-26
lines changed

features/transient-pluck.feature

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,8 @@ Feature: Pluck command available for the transient cache
22

33
Scenario: Nested values from transient can be retrieved at any depth.
44
Given a WP install
5-
And a wp-content/mu-plugins/test-harness.php file:
6-
"""php
7-
<?php
8-
$set_foo = function(){
9-
set_transient( 'my_key', ['foo' => 'bar'] );
10-
set_transient( 'my_key_2', ['foo' => ['bar' => 'baz']] );
11-
};
12-
13-
WP_CLI::add_hook( 'before_invoke:transient pluck', $set_foo );
14-
"""
5+
And I run `wp eval "set_transient( 'my_key', ['foo' => 'bar'] );"`
6+
And I run `wp eval "set_transient( 'my_key_2', ['foo' => ['bar' => 'baz']] );"`
157

168
When I run `wp transient pluck my_key foo`
179
Then STDOUT should be:
@@ -25,27 +17,31 @@ Feature: Pluck command available for the transient cache
2517
baz
2618
"""
2719

20+
When I try `wp transient pluck unknown_key foo`
21+
Then STDERR should be:
22+
"""
23+
Warning: Transient with key "unknown_key" is not set.
24+
"""
25+
2826
Scenario: Nested values from site transient can be retrieved at any depth.
2927
Given a WP multisite install
30-
And I run `wp site create --slug=foo`
31-
And a wp-content/mu-plugins/test-harness.php file:
32-
"""php
33-
<?php
34-
$set_foo = function(){
35-
set_site_transient( 'my_key', ['foo' => 'bar'] );
36-
};
28+
And I run `wp eval "set_site_transient( 'my_key', ['foo' => 'bar'] );"`
29+
And I run `wp eval "set_site_transient( 'my_key_2', ['foo' => ['bar' => 'baz']] );"`
3730

38-
WP_CLI::add_hook( 'before_invoke:transient pluck', $set_foo );
31+
When I run `wp transient pluck my_key foo --network`
32+
Then STDOUT should be:
33+
"""
34+
bar
3935
"""
4036

41-
When I run `wp transient pluck my_key foo --network`
37+
When I run `wp transient pluck my_key_2 foo bar --network`
4238
Then STDOUT should be:
43-
"""
44-
bar
45-
"""
39+
"""
40+
baz
41+
"""
4642

47-
When I try `wp transient pluck my_key foo`
43+
When I try `wp transient pluck unknown_key foo --network`
4844
Then STDERR should be:
49-
"""
50-
Warning: Transient with key "my_key" is not set.
51-
"""
45+
"""
46+
Warning: Transient with key "unknown_key" is not set.
47+
"""

0 commit comments

Comments
 (0)