[wp-trac] [WordPress Trac] #40270: Incorrect error assertions in some REST API tests

WordPress Trac noreply at wordpress.org
Mon Mar 27 02:33:32 UTC 2017


#40270: Incorrect error assertions in some REST API tests
--------------------------+------------------------------
 Reporter:  dlh           |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  REST API      |     Version:
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------
Description changed by dlh:

Old description:

> The `test_delete_item()` and `test_delete_item_skip_trash()` methods in
> `WP_Test_REST_Posts_Controller` contain the assertion
> `$this->assertNotInstanceOf( 'WP_Error', $response );`.
>
> If I'm reading correctly, these assertions will always pass because they
> check a `WP_REST_Response` object. Instead, the assertions should check
> `$response->as_error()`, as happens in `WP_Test_REST_Users_Controller`.
>
> The attached patch updates these assertions, as well as some similar
> assertions in `WP_Test_REST_Post_Type_Controller_Testcase`.
>
> In the post type assertions, it looks as though the `$response` can be a
> `WP_REST_Response`, so it passes `assertNotInstanceOf( 'WP_Error' )` but
> is still capable of returning a `WP_Error` via `as_error()`.
>
> The rest of the assertions in those post type methods might make
> `as_error()` check unnecessary, though.

New description:

 The `test_delete_item()` and `test_delete_item_skip_trash()` methods in
 `WP_Test_REST_Posts_Controller` contain the assertion
 `$this->assertNotInstanceOf( 'WP_Error', $response );`.

 If I'm reading correctly, these assertions will always pass because they
 check a `WP_REST_Response` object. Instead, the assertions should check
 `$response->as_error()`, as happens in `WP_Test_REST_Users_Controller`.

 The attached patch updates these assertions, as well as some similar
 assertions in `WP_Test_REST_Post_Type_Controller_Testcase`.

 In the post type assertions, it looks as though the `$response` can be a
 `WP_REST_Response`, so it passes `assertNotInstanceOf( 'WP_Error' )` but
 is still capable of returning a `WP_Error` via `as_error()`.

 The rest of the assertions in those post type methods might make the
 `as_error()` check unnecessary, though.

--

--
Ticket URL: <https://core.trac.wordpress.org/ticket/40270#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list