-
Notifications
You must be signed in to change notification settings - Fork 95
Add pluck and patch subcommands #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
caa8f10
124b5a9
195d100
b71936b
b4073ea
2b011e9
670a7a4
2fcf1ed
3da5ecc
5acaf20
b178f7b
05ca479
6a9229b
ce24ce0
f2c2e3f
5ebce33
d293990
0739704
dc488c7
a7c6545
67c7476
03930d3
96da024
868f0c3
057a930
de2d604
2ab55f4
46a9e56
4b89ef9
5691612
10f232e
7e6f0b2
ecbc037
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,3 +139,273 @@ Feature: Manage post custom fields | |
""" | ||
My\New\Meta | ||
""" | ||
|
||
@pluck | ||
Scenario: Nested values can be retrieved. | ||
Given a WP install | ||
And an input.json file: | ||
""" | ||
{ | ||
"foo": "bar" | ||
} | ||
""" | ||
And I run `wp post meta set 1 meta-key --format=json < input.json` | ||
|
||
When I run `wp post meta pluck 1 meta-key foo` | ||
Then STDOUT should be: | ||
""" | ||
bar | ||
""" | ||
|
||
@pluck @pluck-deep | ||
Scenario: A nested value can be retrieved at any depth. | ||
Given a WP install | ||
And an input.json file: | ||
""" | ||
{ | ||
"foo": { | ||
"bar": { | ||
"baz": "some value" | ||
} | ||
}, | ||
"foo.com": { | ||
"visitors": 999 | ||
} | ||
} | ||
""" | ||
And I run `wp post meta set 1 meta-key --format=json < input.json` | ||
|
||
When I run `wp post meta pluck 1 meta-key foo bar baz` | ||
Then STDOUT should be: | ||
""" | ||
some value | ||
""" | ||
|
||
When I run `wp post meta pluck 1 meta-key foo.com visitors` | ||
Then STDOUT should be: | ||
""" | ||
999 | ||
""" | ||
|
||
@pluck @pluck-fail | ||
Scenario: Attempting to pluck a non-existent nested value fails. | ||
Given a WP install | ||
And I run `wp post meta set 1 meta-key '{ "key": "value" }' --format=json` | ||
|
||
When I run `wp post meta pluck 1 meta-key key` | ||
Then STDOUT should be: | ||
""" | ||
value | ||
""" | ||
|
||
When I try `wp post meta pluck 1 meta-key foo` | ||
Then STDOUT should be empty | ||
And the return code should be 1 | ||
|
||
@pluck @pluck-fail | ||
Scenario: Attempting to pluck from a primitive value fails. | ||
Given a WP install | ||
And I run `wp post meta set 1 meta-key simple-value` | ||
|
||
When I try `wp post meta pluck 1 meta-key foo` | ||
Then STDOUT should be empty | ||
And the return code should be 1 | ||
|
||
@pluck @pluck-numeric | ||
Scenario: A nested value can be retrieved from an integer key. | ||
Given a WP install | ||
And I run `wp post meta set 1 meta-key '[ "foo", "bar" ]' --format=json` | ||
|
||
When I run `wp post meta pluck 1 meta-key 0` | ||
Then STDOUT should be: | ||
""" | ||
foo | ||
""" | ||
|
||
@patch @patch-update @patch-arg | ||
Scenario: Nested values can be changed. | ||
Given a WP install | ||
And an input.json file: | ||
""" | ||
{ | ||
"foo": "bar" | ||
} | ||
""" | ||
And I run `wp post meta set 1 meta-key --format=json < input.json` | ||
|
||
When I run `wp post meta patch update 1 meta-key foo baz` | ||
Then STDOUT should be: | ||
""" | ||
Success: Updated custom field 'meta-key'. | ||
""" | ||
|
||
When I run `wp post meta get 1 meta-key --format=json` | ||
Then STDOUT should be JSON containing: | ||
""" | ||
{ | ||
"foo": "baz" | ||
} | ||
""" | ||
|
||
@patch @patch-update @patch-stdin | ||
Scenario: Nested values can be set with a value from STDIN. | ||
Given a WP install | ||
And an input.json file: | ||
""" | ||
{ | ||
"foo": { | ||
"bar": "baz" | ||
}, | ||
"bar": "bad" | ||
} | ||
""" | ||
And a patch file: | ||
""" | ||
new value | ||
""" | ||
And I run `wp post meta set 1 meta-key --format=json < input.json` | ||
|
||
When I run `wp post meta patch update 1 meta-key foo bar < patch` | ||
Then STDOUT should be: | ||
""" | ||
Success: Updated custom field 'meta-key'. | ||
""" | ||
|
||
When I run `wp post meta get 1 meta-key --format=json` | ||
Then STDOUT should be JSON containing: | ||
""" | ||
{ | ||
"foo": { | ||
"bar": "new value" | ||
}, | ||
"bar": "bad" | ||
} | ||
""" | ||
|
||
@patch @patch-update @patch-fail | ||
Scenario: Attempting to update a nested value fails if a parent's key does not exist. | ||
Given a WP install | ||
And an input.json file: | ||
""" | ||
{ | ||
"foo": { | ||
"bar": "baz" | ||
}, | ||
"bar": "bad" | ||
} | ||
""" | ||
And I run `wp post meta set 1 meta-key --format=json < input.json` | ||
|
||
When I try `wp post meta patch update 1 meta-key foo not-a-key new-value` | ||
Then STDOUT should be empty | ||
And STDERR should contain: | ||
""" | ||
No data exists for key "not-a-key" | ||
""" | ||
And the return code should be 1 | ||
|
||
@patch @patch-delete | ||
Scenario: A key can be deleted from a nested value. | ||
Given a WP install | ||
And an input.json file: | ||
""" | ||
{ | ||
"foo": { | ||
"bar": "baz", | ||
"abe": "lincoln" | ||
} | ||
} | ||
""" | ||
And I run `wp post meta set 1 meta-key --format=json < input.json` | ||
|
||
When I run `wp post meta patch delete 1 meta-key foo bar` | ||
Then STDOUT should be: | ||
""" | ||
Success: Updated custom field 'meta-key'. | ||
""" | ||
|
||
When I run `wp post meta get 1 meta-key --format=json` | ||
Then STDOUT should be JSON containing: | ||
""" | ||
{ | ||
"foo": { | ||
"abe": "lincoln" | ||
} | ||
} | ||
""" | ||
|
||
@patch @patch-fail @patch-delete @patch-delete-fail | ||
Scenario: A key cannot be deleted from a nested value from a non-existent key. | ||
Given a WP install | ||
And an input.json file: | ||
""" | ||
{ | ||
"foo": { | ||
"bar": "baz" | ||
} | ||
} | ||
""" | ||
And I run `wp post meta set 1 meta-key --format=json < input.json` | ||
|
||
When I try `wp post meta patch delete 1 meta-key foo not-a-key` | ||
Then STDOUT should be empty | ||
And STDERR should contain: | ||
""" | ||
No data exists for key "not-a-key" | ||
""" | ||
And the return code should be 1 | ||
|
||
@patch @patch-insert | ||
Scenario: A new key can be inserted into a nested value. | ||
Given a WP install | ||
And I run `wp post meta set 1 meta-key '{}' --format=json` | ||
|
||
When I run `wp post meta patch insert 1 meta-key foo bar` | ||
Then STDOUT should be: | ||
""" | ||
Success: Updated custom field 'meta-key'. | ||
""" | ||
|
||
When I run `wp post meta get 1 meta-key --format=json` | ||
Then STDOUT should be JSON containing: | ||
""" | ||
{ | ||
"foo": "bar" | ||
} | ||
""" | ||
|
||
@patch @patch-fail @patch-insert @patch-insert-fail | ||
Scenario: A new key cannot be inserted into a non-nested value. | ||
Given a WP install | ||
And I run `wp post meta set 1 meta-key 'a simple value'` | ||
|
||
When I try `wp post meta patch insert 1 meta-key foo bar` | ||
Then STDOUT should be empty | ||
And STDERR should contain: | ||
""" | ||
Cannot create key "foo" | ||
""" | ||
And the return code should be 1 | ||
|
||
When I run `wp post meta get 1 meta-key` | ||
Then STDOUT should be: | ||
""" | ||
a simple value | ||
""" | ||
|
||
@patch @patch-numeric | ||
Scenario: A nested value can be updated using an integer key. | ||
Given a WP install | ||
And I run `wp post meta set 1 meta-key '[ "foo", "bar" ]' --format=json` | ||
|
||
When I run `wp post meta patch update 1 meta-key 0 new` | ||
Then STDOUT should be: | ||
""" | ||
Success: Updated custom field 'meta-key'. | ||
""" | ||
|
||
When I run `wp post meta get 1 meta-key --format=json` | ||
Then STDOUT should be JSON containing: | ||
""" | ||
[ "new", "bar" ] | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there's three use/test cases missing:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Will add.
I believe this is covered already. See the
Will add. (Should be a notice that value did not change.) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/4.8/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
backupGlobals="false" | ||
beStrictAboutCoversAnnotation="true" | ||
beStrictAboutOutputDuringTests="true" | ||
beStrictAboutTestsThatDoNotTestAnything="true" | ||
beStrictAboutTodoAnnotatedTests="true" | ||
colors="true" | ||
verbose="true"> | ||
<testsuite> | ||
<directory suffix="Test.php">tests</directory> | ||
</testsuite> | ||
|
||
<filter> | ||
<whitelist processUncoveredFilesFromWhitelist="true"> | ||
<directory suffix=".php">src</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should set an explicit check for return code here too: