Make WordPress Core

Changeset 58051


Ignore:
Timestamp:
04/26/2024 03:49:19 PM (11 days ago)
Author:
SergeyBiryukov
Message:

Tests: Add more specific messages for a custom assertion in WP_Test_REST_TestCase.

All assertions in PHPUnit have a $message parameter. Setting this parameter allows to distinguish which assertion is failing when a test runs multiple assertions, making debugging of the tests easier.

Follow-up to [34928], [51478], [58039].

See #60426.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/testcase-rest-api.php

    r58039 r58051  
    2020        }
    2121
    22         $this->assertWPError( $response, $message );
    23         $this->assertSame( $code, $response->get_error_code(), $message );
     22        $this->assertWPError( $response, $message . ' Passed $response is not a WP_Error object.' );
     23        $this->assertSame( $code, $response->get_error_code(), $message . ' The expected error code does not match.' );
    2424
    2525        if ( null !== $status ) {
    2626            $data = $response->get_error_data();
    27             $this->assertArrayHasKey( 'status', $data, $message );
    28             $this->assertSame( $status, $data['status'], $message );
     27            $this->assertArrayHasKey( 'status', $data, $message . ' Passed $response does not include a status code.' );
     28            $this->assertSame( $status, $data['status'], $message . ' The expected status code does not match.' );
    2929        }
    3030    }
Note: See TracChangeset for help on using the changeset viewer.