WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (17 months ago)
Author:
SergeyBiryukov
Message:

Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests.

This ensures that not only the return values match the expected results, but also that their type is the same.

Going forward, stricter type checking by using assertSame() should generally be preferred to assertEquals() where appropriate, to make the tests more reliable.

Props johnbillion, jrf, SergeyBiryukov.
See #38266.

File:
1 edited

Legend:

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

    r48908 r48937  
    661661
    662662    /**
    663      * Asserts that two values are equal, with EOL differences discarded.
    664      *
    665      * @since 5.4.0
     663     * Asserts that two values have the same type and value, with EOL differences discarded.
     664     *
     665     * @since 5.6.0
    666666     *
    667667     * @param string $expected The expected value.
    668668     * @param string $actual   The actual value.
    669669     */
     670    public function assertSameIgnoreEOL( $expected, $actual ) {
     671        $this->assertSame( str_replace( "\r\n", "\n", $expected ), str_replace( "\r\n", "\n", $actual ) );
     672    }
     673
     674    /**
     675     * Asserts that two values are equal, with EOL differences discarded.
     676     *
     677     * @since 5.4.0
     678     * @since 5.6.0 Turned into an alias for `::assertSameIgnoreEOL()`.
     679     *
     680     * @param string $expected The expected value.
     681     * @param string $actual   The actual value.
     682     */
    670683    public function assertEqualsIgnoreEOL( $expected, $actual ) {
    671         $this->assertEquals( str_replace( "\r\n", "\n", $expected ), str_replace( "\r\n", "\n", $actual ) );
     684        $this->assertSameIgnoreEOL( $expected, $actual );
    672685    }
    673686
Note: See TracChangeset for help on using the changeset viewer.