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/tests/date/currentTime.php

    r47118 r48952  
    1717        $wp_timestamp = $timestamp + 6 * HOUR_IN_SECONDS;
    1818
    19         $this->assertEquals( strtotime( gmdate( $format ) ), strtotime( current_time( $format, true ) ), 'The dates should be equal', 2 );
    20         $this->assertEquals( strtotime( gmdate( $format, $wp_timestamp ) ), strtotime( current_time( $format ) ), 'The dates should be equal', 2 );
     19        $this->assertEqualsWithDelta( strtotime( gmdate( $format ) ), strtotime( current_time( $format, true ) ), 2, 'The dates should be equal' );
     20        $this->assertEqualsWithDelta( strtotime( gmdate( $format, $wp_timestamp ) ), strtotime( current_time( $format ) ), 2, 'The dates should be equal' );
    2121    }
    2222
     
    3131        $wp_timestamp = $timestamp + 6 * HOUR_IN_SECONDS;
    3232
    33         $this->assertEquals( strtotime( gmdate( $format ) ), strtotime( current_time( 'mysql', true ) ), 'The dates should be equal', 2 );
    34         $this->assertEquals( strtotime( gmdate( $format, $wp_timestamp ) ), strtotime( current_time( 'mysql' ) ), 'The dates should be equal', 2 );
     33        $this->assertEqualsWithDelta( strtotime( gmdate( $format ) ), strtotime( current_time( 'mysql', true ) ), 2, 'The dates should be equal' );
     34        $this->assertEqualsWithDelta( strtotime( gmdate( $format, $wp_timestamp ) ), strtotime( current_time( 'mysql' ) ), 2, 'The dates should be equal' );
    3535    }
    3636
     
    4545
    4646        // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.RequestedUTC
    47         $this->assertEquals( $timestamp, current_time( 'timestamp', true ), 'The dates should be equal', 2 );
     47        $this->assertEqualsWithDelta( $timestamp, current_time( 'timestamp', true ), 2, 'The dates should be equal' );
    4848        // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
    49         $this->assertEquals( $wp_timestamp, current_time( 'timestamp' ), 'The dates should be equal', 2 );
     49        $this->assertEqualsWithDelta( $wp_timestamp, current_time( 'timestamp' ), 2, 'The dates should be equal' );
    5050    }
    5151
     
    7171        $current_time     = current_time( $format );
    7272
    73         $this->assertEquals( strtotime( gmdate( $format ) ), strtotime( $current_time_custom_timezone_gmt ), 'The dates should be equal', 2 );
    74         $this->assertEquals( strtotime( $datetime->format( $format ) ), strtotime( $current_time_custom_timezone ), 'The dates should be equal', 2 );
    75         $this->assertEquals( strtotime( gmdate( $format ) ), strtotime( $current_time_gmt ), 'The dates should be equal', 2 );
    76         $this->assertEquals( strtotime( $datetime->format( $format ) ), strtotime( $current_time ), 'The dates should be equal', 2 );
     73        $this->assertEqualsWithDelta( strtotime( gmdate( $format ) ), strtotime( $current_time_custom_timezone_gmt ), 2, 'The dates should be equal' );
     74        $this->assertEqualsWithDelta( strtotime( $datetime->format( $format ) ), strtotime( $current_time_custom_timezone ), 2, 'The dates should be equal' );
     75        $this->assertEqualsWithDelta( strtotime( gmdate( $format ) ), strtotime( $current_time_gmt ), 2, 'The dates should be equal' );
     76        $this->assertEqualsWithDelta( strtotime( $datetime->format( $format ) ), strtotime( $current_time ), 2, 'The dates should be equal' );
    7777    }
    7878
     
    8989
    9090        // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.RequestedUTC
    91         $this->assertEquals( $timestamp, current_time( 'timestamp', true ), 'The dates should be equal', 2 );
     91        $this->assertEqualsWithDelta( $timestamp, current_time( 'timestamp', true ), 2, 'The dates should be equal' );
    9292        // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.RequestedUTC
    93         $this->assertEquals( $timestamp, current_time( 'U', true ), 'The dates should be equal', 2 );
     93        $this->assertEqualsWithDelta( $timestamp, current_time( 'U', true ), 2, 'The dates should be equal' );
    9494
    9595        // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
    96         $this->assertEquals( $wp_timestamp, current_time( 'timestamp' ), 'The dates should be equal', 2 );
     96        $this->assertEqualsWithDelta( $wp_timestamp, current_time( 'timestamp' ), 2, 'The dates should be equal' );
    9797        // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
    98         $this->assertEquals( $wp_timestamp, current_time( 'U' ), 'The dates should be equal', 2 );
     98        $this->assertEqualsWithDelta( $wp_timestamp, current_time( 'U' ), 2, 'The dates should be equal' );
    9999
    100100        // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
     
    114114        $datetime_utc->setTimezone( new DateTimeZone( 'UTC' ) );
    115115
    116         $this->assertEquals( strtotime( $datetime_local->format( DATE_W3C ) ), strtotime( current_time( DATE_W3C ) ), 'The dates should be equal', 2 );
    117         $this->assertEquals( strtotime( $datetime_utc->format( DATE_W3C ) ), strtotime( current_time( DATE_W3C, true ) ), 'The dates should be equal', 2 );
     116        $this->assertEqualsWithDelta( strtotime( $datetime_local->format( DATE_W3C ) ), strtotime( current_time( DATE_W3C ) ), 2, 'The dates should be equal' );
     117        $this->assertEqualsWithDelta( strtotime( $datetime_utc->format( DATE_W3C ) ), strtotime( current_time( DATE_W3C, true ) ), 2, 'The dates should be equal' );
    118118    }
    119119}
Note: See TracChangeset for help on using the changeset viewer.