Make WordPress Core

Changeset 53536


Ignore:
Timestamp:
06/20/2022 05:27:15 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Tests: Always include the error message in assertNotWPError() and assertNotIXRError().

Previously, in case of failure, WP_UnitTestCase_Base::assertNotWPError() displayed the actual error message from the passed WP_Error object, but only if the $message parameter was empty.

This made the assertion less helpful, as the actual error message was lost in case there was a non-empty $message parameter passed to the method, as per the Writing PHP Tests guidelines:

All PHPUnit assertions, as well as all WordPress custom assertions, allow for a $message parameter to be passed. This message will be displayed when the assertion fails and can help immensely when debugging a test. This parameter should always be used if more than one assertion is used in a test method.

This commit ensures that the actual error message is always displayed, in addition to the passed $message parameter.

The same applies to WP_UnitTestCase_Base::assertNotIXRError().

Follow-up to [34638], [40417].

Props jrf, SergeyBiryukov.
See #55652.

File:
1 edited

Legend:

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

    r53521 r53536  
    655655         */
    656656        public function assertNotWPError( $actual, $message = '' ) {
    657                 if ( '' === $message && is_wp_error( $actual ) ) {
    658                         $message = $actual->get_error_message();
    659                 }
     657                if ( is_wp_error( $actual ) ) {
     658                        $message .= ' ' . $actual->get_error_message();
     659                }
     660
    660661                $this->assertNotInstanceOf( 'WP_Error', $actual, $message );
    661662        }
     
    678679         */
    679680        public function assertNotIXRError( $actual, $message = '' ) {
    680                 if ( '' === $message && $actual instanceof IXR_Error ) {
    681                         $message = $actual->message;
    682                 }
     681                if ( $actual instanceof IXR_Error ) {
     682                        $message .= ' ' . $actual->message;
     683                }
     684
    683685                $this->assertNotInstanceOf( 'IXR_Error', $actual, $message );
    684686        }
Note: See TracChangeset for help on using the changeset viewer.