Make WordPress Core

Changeset 51480


Ignore:
Timestamp:
07/22/2021 05:39:03 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Tests: Modernize the WP_UnitTestCase_Base::assertEqualFields() method:

  • Use assertSame() instead of fail() to display a proper message in case of failure.
  • Add an optional $message parameter for consistency with other assertions.

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

See #53363.

File:
1 edited

Legend:

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

    r51479 r51480  
    656656     * Asserts that the given fields are present in the given object.
    657657     *
    658      * @param object $object The object to check.
    659      * @param array  $fields The fields to check.
    660      */
    661     public function assertEqualFields( $object, $fields ) {
     658     * @since UT (3.7.0)
     659     * @since 5.9.0 Added the `$message` parameter.
     660     *
     661     * @param object $object  The object to check.
     662     * @param array  $fields  The fields to check.
     663     * @param string $message Optional. Message to display when the assertion fails.
     664     */
     665    public function assertEqualFields( $object, $fields, $message = '' ) {
    662666        foreach ( $fields as $field_name => $field_value ) {
    663             if ( $object->$field_name !== $field_value ) {
    664                 $this->fail();
    665             }
     667            $this->assertSame( $object->$field_name, $field_value, $message . ' Field values do not match.' );
    666668        }
    667669    }
Note: See TracChangeset for help on using the changeset viewer.