Skip to content

Commit

Permalink
Return a proper WP_Error object when failing to update a comment (#514
Browse files Browse the repository at this point in the history
)
  • Loading branch information
danielbachhuber authored Oct 16, 2024
1 parent 9dad075 commit 50d20fa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions features/comment.feature
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ Feature: Manage WordPress comments
"""
And the return code should be 1

Scenario: Updating an invalid comment should return an error
Given a WP install

When I try `wp comment update 22 --comment_author=Foo`
Then the return code should be 1
And STDERR should contain:
"""
Warning: Could not update comment.
"""

Scenario: Get details about an existing comment
When I run `wp comment get 1`
Then STDOUT should be a table containing rows:
Expand Down
2 changes: 1 addition & 1 deletion src/Comment_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function update( $args, $assoc_args ) {
$assoc_args,
function ( $params ) {
if ( ! wp_update_comment( $params ) ) {
return new WP_Error( 'Could not update comment.' );
return new WP_Error( 'db_error', 'Could not update comment.' );
}

return true;
Expand Down

0 comments on commit 50d20fa

Please sign in to comment.