|
| 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 | + """ |
0 commit comments