Make WordPress Core


Ignore:
Timestamp:
09/07/2020 03:12:17 AM (4 years ago)
Author:
SergeyBiryukov
Message:

Tests: Add a polyfill for assertEqualsWithDelta() to WP_UnitTestCase and use it where appropriate.

assertEqualsWithDelta() was added in PHPUnit 7.5, while WordPress still supports PHPUnit 5.4.x as the minimum version.

See #38266.

File:
1 edited

Legend:

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

    r47198 r48952  
    1717     * Asserts that a condition is not false.
    1818     *
    19      * This method has been backported from a more recent PHPUnit version, as tests running on PHP 5.2 use
    20      * PHPUnit 3.6.x.
     19     * This method has been backported from a more recent PHPUnit version,
     20     * as tests running on PHP 5.2 use PHPUnit 3.6.x.
    2121     *
    2222     * @since 4.7.4
     
    3030        self::assertThat( $condition, self::logicalNot( self::isFalse() ), $message );
    3131    }
     32
     33    /**
     34     * Asserts that two variables are equal (with delta).
     35     *
     36     * This method has been backported from a more recent PHPUnit version,
     37     * as tests running on PHP 5.6 use PHPUnit 5.7.x.
     38     *
     39     * @since 5.6.0
     40     *
     41     * @param mixed  $expected First value to compare.
     42     * @param mixed  $actual   Second value to compare.
     43     * @param float  $delta    Allowed numerical distance between two values to consider them equal.
     44     * @param string $message  Optional. Message to display when the assertion fails.
     45     *
     46     * @throws ExpectationFailedException
     47     * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
     48     */
     49    public static function assertEqualsWithDelta( $expected, $actual, float $delta, string $message = '' ): void {
     50        $constraint = new PHPUnit\Framework\Constraint\IsEqual(
     51            $expected,
     52            $delta
     53        );
     54
     55        static::assertThat( $actual, $constraint, $message );
     56    }
    3257}
Note: See TracChangeset for help on using the changeset viewer.