wordpress/tests/phpunit/includes/testcase-rest-api.php
Sergey Biryukov b92491b8d2 Coding Standards: Use instanceof keyword instead of the is_a() function.
This is a micro-optimization that removes a few unnecessary function calls.

Follow-up to [31188], [34369], [38986], [41159], [43211], [43230], [44606], [45757].

Props ayeshrajans, jrf, rajinsharwar, costdev, mukesh27, SergeyBiryukov.
Fixes #58943.

git-svn-id: https://develop.svn.wordpress.org/trunk@56352 602fd350-edb4-49c9-b593-d223f7449a82
2023-08-03 12:08:30 +00:00

20 lines
513 B
PHP

<?php
abstract class WP_Test_REST_TestCase extends WP_UnitTestCase {
protected function assertErrorResponse( $code, $response, $status = null ) {
if ( $response instanceof WP_REST_Response ) {
$response = $response->as_error();
}
$this->assertWPError( $response );
$this->assertSame( $code, $response->get_error_code() );
if ( null !== $status ) {
$data = $response->get_error_data();
$this->assertArrayHasKey( 'status', $data );
$this->assertSame( $status, $data['status'] );
}
}
}