WordPress.org

Make WordPress Core

Changeset 51481


Ignore:
Timestamp:
07/22/2021 06:49:24 PM (4 months ago)
Author:
SergeyBiryukov
Message:

Tests: Use better assertions in WP_UnitTestCase_Base::assertEqualFields():

  • Check if the object attribute exists before checking its value.
  • Mention the field name in error messages in case of failure.

Follow-up to [51478], [51479], [51480].

Props jrf.
See #53363.

File:
1 edited

Legend:

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

    r51480 r51481  
    665665    public function assertEqualFields( $object, $fields, $message = '' ) {
    666666        foreach ( $fields as $field_name => $field_value ) {
    667             $this->assertSame( $object->$field_name, $field_value, $message . ' Field values do not match.' );
     667            $this->assertObjectHasAttribute( $field_name, $object, $message . " Property $field_name does not exist on the object." );
     668            $this->assertSame( $field_value, $object->$field_name, $message . " Value of property $field_name is not $field_value." );
    668669        }
    669670    }
Note: See TracChangeset for help on using the changeset viewer.