WordPress.org

Make WordPress Core

Changeset 51698


Ignore:
Timestamp:
08/30/2021 08:40:05 PM (3 months ago)
Author:
hellofromTonya
Message:

Tests: Do whitespace replacement in assertDiscardWhitespace() only when string.

The assertDiscardWhitespace() method uses assertEquals() under the hood, meaning that in reality any type of actual/expected value should be accepted by the function. Fixed the documentation to reflect that.

At the same time, only strings can contain whitespace differences. So the whitespace replacement should only be done when string values are passed.

This change (a) prevents potential passing null to non-nullable errors on PHP 8.1, if either of the inputs would turn out to be null and (b) increases tests stability.

Follow-up to [35003], [44902].

Props jrf.
See #53363.

File:
1 edited

Legend:

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

    r51697 r51698  
    702702     * @since 5.9.0 Added the `$message` parameter.
    703703     *
    704      * @param string $expected The expected value.
    705      * @param string $actual   The actual value.
     704     * @param mixed $expected The expected value.
     705     * @param mixed $actual   The actual value.
    706706     * @param string $message  Optional. Message to display when the assertion fails.
    707707     */
    708708    public function assertDiscardWhitespace( $expected, $actual, $message = '' ) {
    709         $this->assertEquals( preg_replace( '/\s*/', '', $expected ), preg_replace( '/\s*/', '', $actual ), $message );
     709        if ( is_string( $expected ) ) {
     710            $expected = preg_replace( '/\s*/', '', $expected );
     711        }
     712
     713        if ( is_string( $actual ) ) {
     714            $actual = preg_replace( '/\s*/', '', $actual );
     715        }
     716
     717        $this->assertEquals( $expected, $actual, $message );
    710718    }
    711719
Note: See TracChangeset for help on using the changeset viewer.