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/dateI18n.php

    r48937 r48952  
    1717        $wp_timestamp = $datetime->getTimestamp() + $datetime->getOffset();
    1818
    19         $this->assertEquals( $wp_timestamp, date_i18n( 'U', 'invalid' ), '', 5 );
     19        $this->assertEqualsWithDelta( $wp_timestamp, date_i18n( 'U', 'invalid' ), 5, 'The dates should be equal' );
    2020    }
    2121
     
    3939
    4040    public function test_should_format_date() {
    41         $this->assertEquals( strtotime( gmdate( 'Y-m-d H:i:s' ) ), strtotime( date_i18n( 'Y-m-d H:i:s' ) ), 'The dates should be equal', 2 );
     41        $this->assertEqualsWithDelta( strtotime( gmdate( 'Y-m-d H:i:s' ) ), strtotime( date_i18n( 'Y-m-d H:i:s' ) ), 2, 'The dates should be equal' );
    4242    }
    4343
     
    4747
    4848    public function test_date_should_be_in_gmt() {
    49         $this->assertEquals( strtotime( gmdate( DATE_RFC3339 ) ), strtotime( date_i18n( DATE_RFC3339, false, true ) ), 'The dates should be equal', 2 );
     49        $this->assertEqualsWithDelta( strtotime( gmdate( DATE_RFC3339 ) ), strtotime( date_i18n( DATE_RFC3339, false, true ) ), 2, 'The dates should be equal' );
    5050    }
    5151
     
    5353        update_option( 'timezone_string', 'America/Regina' );
    5454
    55         $this->assertEquals( strtotime( gmdate( 'Y-m-d H:i:s', time() + get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ), strtotime( date_i18n( 'Y-m-d H:i:s' ) ), 'The dates should be equal', 2 );
     55        $this->assertEqualsWithDelta( strtotime( gmdate( 'Y-m-d H:i:s', time() + get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ), strtotime( date_i18n( 'Y-m-d H:i:s' ) ), 2, 'The dates should be equal' );
    5656    }
    5757
     
    5959        update_option( 'timezone_string', 'America/Regina' );
    6060
    61         $this->assertEquals( strtotime( gmdate( DATE_RFC3339 ) ), strtotime( date_i18n( DATE_RFC3339, false, true ) ), 'The dates should be equal', 2 );
     61        $this->assertEqualsWithDelta( strtotime( gmdate( DATE_RFC3339 ) ), strtotime( date_i18n( DATE_RFC3339, false, true ) ), 2, 'The dates should be equal' );
    6262    }
    6363
     
    122122        update_option( 'timezone_string', 'America/Regina' );
    123123
    124         $this->assertEquals( strtotime( date_i18n( $full ) ), strtotime( date_i18n( $short ) ), 'The dates should be equal', 2 );
     124        $this->assertEqualsWithDelta( strtotime( date_i18n( $full ) ), strtotime( date_i18n( $short ) ), 2, 'The dates should be equal' );
    125125        $this->assertSame( $short, date_i18n( '\\' . $short ) );
    126126    }
     
    149149        $wp_timestamp = $timestamp + $datetime->getOffset();
    150150
    151         $this->assertEquals( $wp_timestamp, date_i18n( 'U' ), 'The dates should be equal', 2 );
    152         $this->assertEquals( $timestamp, date_i18n( 'U', false, true ), 'The dates should be equal', 2 );
     151        $this->assertEqualsWithDelta( $wp_timestamp, date_i18n( 'U' ), 2, 'The dates should be equal' );
     152        $this->assertEqualsWithDelta( $timestamp, date_i18n( 'U', false, true ), 2, 'The dates should be equal' );
    153153        $this->assertSame( $wp_timestamp, date_i18n( 'U', $wp_timestamp ) );
    154154    }
Note: See TracChangeset for help on using the changeset viewer.