Make WordPress Core

Changeset 50986


Ignore:
Timestamp:
05/25/2021 01:07:43 AM (4 years ago)
Author:
SergeyBiryukov
Message:

Tests: Minimize the chances of signature conflicts for assertEqualsWithDelta().

The PHPUnit 7.5+ method assertEqualsWithDelta() was polyfilled for PHPUnit < 7.5, but also overloaded for PHPUnit 7.5 itself, which was not necessary and created a higher chance of signature conflicts, especially when the WP test suite is used as a basis for integration tests with plugins/themes.

This change removes the unnecessary overloading for PHPUnit 7.5+ and simplifies the overloaded method for PHPUnit < 7.5, including removing the IsEqual() class alias declaration, no longer needed.

Follow-up to [48952].

Props jrf.
See #52625.

Location:
trunk/tests/phpunit/includes
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/bootstrap.php

    r49571 r50986  
    194194_delete_all_posts();
    195195
    196 if ( version_compare( tests_get_phpunit_version(), '7.0', '>=' ) ) {
     196if ( version_compare( tests_get_phpunit_version(), '7.5', '>=' ) ) {
    197197    require __DIR__ . '/phpunit7/testcase.php';
    198198} else {
  • trunk/tests/phpunit/includes/phpunit6/compat.php

    r48952 r50986  
    1212    class_alias( 'PHPUnit\Framework\Warning', 'PHPUnit_Framework_Warning' );
    1313    class_alias( 'PHPUnit\Framework\AssertionFailedError', 'PHPUnit_Framework_AssertionFailedError' );
    14     class_alias( 'PHPUnit\Framework\Constraint\IsEqual', 'PHPUnit_Framework_Constraint_IsEqual' );
    1514    class_alias( 'PHPUnit\Framework\TestSuite', 'PHPUnit_Framework_TestSuite' );
    1615    class_alias( 'PHPUnit\Framework\TestListener', 'PHPUnit_Framework_TestListener' );
  • trunk/tests/phpunit/includes/phpunit7/testcase.php

    r49037 r50986  
    1212 * All WordPress unit tests should inherit from this class.
    1313 */
    14 class WP_UnitTestCase extends WP_UnitTestCase_Base {
    15 
    16     /**
    17      * Asserts that two variables are equal (with delta).
    18      *
    19      * This method has been backported from a more recent PHPUnit version,
    20      * as tests running on PHP 5.6 use PHPUnit 5.7.x.
    21      *
    22      * @since 5.6.0
    23      *
    24      * @param mixed  $expected First value to compare.
    25      * @param mixed  $actual   Second value to compare.
    26      * @param float  $delta    Allowed numerical distance between two values to consider them equal.
    27      * @param string $message  Optional. Message to display when the assertion fails.
    28      *
    29      * @throws ExpectationFailedException
    30      * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
    31      */
    32     public static function assertEqualsWithDelta( $expected, $actual, float $delta, string $message = '' ): void {
    33         $constraint = new PHPUnit\Framework\Constraint\IsEqual(
    34             $expected,
    35             $delta
    36         );
    37 
    38         static::assertThat( $actual, $constraint, $message );
    39     }
    40 }
     14class WP_UnitTestCase extends WP_UnitTestCase_Base {}
  • trunk/tests/phpunit/includes/testcase.php

    r48953 r50986  
    3131     */
    3232    public static function assertEqualsWithDelta( $expected, $actual, $delta, $message = '' ) {
    33         $constraint = new PHPUnit_Framework_Constraint_IsEqual(
    34             $expected,
    35             $delta
    36         );
    37 
    38         static::assertThat( $actual, $constraint, $message );
     33        static::assertEquals( $expected, $actual, $message, $delta );
    3934    }
    4035}
Note: See TracChangeset for help on using the changeset viewer.