Skip to content

Commit

Permalink
split patch feature tests and add additionnal checks with `transien…
Browse files Browse the repository at this point in the history
…t get`
  • Loading branch information
petitphp committed Dec 8, 2023
1 parent c5cc6f4 commit 7e8c2ce
Showing 1 changed file with 92 additions and 16 deletions.
108 changes: 92 additions & 16 deletions features/transient-patch.feature
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Feature: Patch command available for the transient cache

Scenario: Nested values from transient can be updated at any depth.
Scenario: Nested values from transient can be inserted at any depth.
Given a WP install
And I run `wp eval "set_transient( 'my_key', ['foo' => 'bar'] );"`
And I run `wp eval "set_transient( 'my_key_2', ['foo' => ['bar' => 'baz']] );"`
Expand All @@ -11,64 +11,140 @@ Feature: Patch command available for the transient cache
Success: Updated transient 'my_key'.
"""

When I run `wp transient patch insert my_key_2 foo fuz bar`
When I run `wp transient get my_key --format=json`
Then STDOUT should be:
"""
{"foo":"bar","fuz":"baz"}
"""

When I run `wp transient patch insert my_key foo bar`
Then STDOUT should be:
"""
Success: Value passed for transient 'my_key' is unchanged.
"""

When I run `wp transient get my_key --format=json`
Then STDOUT should be:
"""
{"foo":"bar","fuz":"baz"}
"""

When I run `wp transient patch insert my_key_2 foo fuz biz`
Then STDOUT should be:
"""
Success: Updated transient 'my_key_2'.
"""

When I try `wp transient patch insert unknown_key foo bar`
Then STDERR should be:
When I run `wp transient get my_key_2 --format=json`
Then STDOUT should be:
"""
Error: Cannot create key "foo" on data type boolean
{"foo":{"bar":"baz","fuz":"biz"}}
"""

When I run `wp transient patch insert my_key foo bar`
When I run `wp transient patch insert my_key_2 foo bar baz`
Then STDOUT should be:
"""
Success: Value passed for transient 'my_key' is unchanged.
Success: Value passed for transient 'my_key_2' is unchanged.
"""

When I run `wp transient get my_key_2 --format=json`
Then STDOUT should be:
"""
{"foo":{"bar":"baz","fuz":"biz"}}
"""

Scenario: Nested values from transient can be updated at any depth.
Given a WP install
And I run `wp eval "set_transient( 'my_key', ['foo' => 'bar'] );"`
And I run `wp eval "set_transient( 'my_key_2', ['foo' => ['bar' => 'baz']] );"`

When I run `wp transient patch update my_key foo biz`
When I run `wp transient patch update my_key foo baz`
Then STDOUT should be:
"""
Success: Updated transient 'my_key'.
"""

When I run `wp transient get my_key --format=json`
Then STDOUT should be:
"""
{"foo":"baz"}
"""

When I run `wp transient patch update my_key foo baz`
Then STDOUT should be:
"""
Success: Value passed for transient 'my_key' is unchanged.
"""

When I run `wp transient get my_key --format=json`
Then STDOUT should be:
"""
{"foo":"baz"}
"""

When I run `wp transient patch update my_key_2 foo bar biz`
Then STDOUT should be:
"""
Success: Updated transient 'my_key_2'.
"""

When I try `wp transient patch update unknown_key foo bar`
Then STDERR should be:
When I run `wp transient get my_key_2 --format=json`
Then STDOUT should be:
"""
Error: No data exists for key "foo"
{"foo":{"bar":"biz"}}
"""

When I run `wp transient patch update my_key foo bar`
When I run `wp transient patch update my_key_2 foo bar biz`
Then STDOUT should be:
"""
Success: Value passed for transient 'my_key' is unchanged.
Success: Value passed for transient 'my_key_2' is unchanged.
"""

When I run `wp transient get my_key_2 --format=json`
Then STDOUT should be:
"""
{"foo":{"bar":"biz"}}
"""

Scenario: Nested values from transient can be deleted at any depth.
Given a WP install
And I run `wp eval "set_transient( 'my_key', ['foo' => 'bar'] );"`
And I run `wp eval "set_transient( 'my_key_2', ['foo' => ['bar' => 'baz']] );"`

When I run `wp transient patch delete my_key foo`
Then STDOUT should be:
"""
Success: Updated transient 'my_key'.
"""

When I run `wp transient get my_key --format=json`
Then STDOUT should be:
"""
[]
"""

When I run `wp transient patch delete my_key_2 foo bar`
Then STDOUT should be:
"""
Success: Updated transient 'my_key_2'.
"""

When I try `wp transient patch delete unknown_key foo`
Then STDERR should be:
When I run `wp transient get my_key_2 --format=json`
Then STDOUT should be:
"""
Error: No data exists for key "foo"
{"foo":[]}
"""

When I run `wp transient patch delete my_key_2 foo`
Then STDOUT should be:
"""
Success: Updated transient 'my_key_2'.
"""

When I run `wp transient get my_key_2 --format=json`
Then STDOUT should be:
"""
[]
"""

Scenario: Nested values from site transient can be updated at any depth.
Expand Down

0 comments on commit 7e8c2ce

Please sign in to comment.