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

    r48911 r48937  
    2525     */
    2626    function test_mysql2date_returns_gmt_or_unix_timestamp() {
    27         $this->assertEquals( '441013392', mysql2date( 'G', '1983-12-23 07:43:12' ) );
    28         $this->assertEquals( '441013392', mysql2date( 'U', '1983-12-23 07:43:12' ) );
     27        $this->assertSame( 441013392, mysql2date( 'G', '1983-12-23 07:43:12' ) );
     28        $this->assertSame( 441013392, mysql2date( 'U', '1983-12-23 07:43:12' ) );
    2929    }
    3030
     
    3939        $mysql    = $datetime->format( 'Y-m-d H:i:s' );
    4040
    41         $this->assertEquals( $rfc3339, mysql2date( DATE_RFC3339, $mysql ) );
    42         $this->assertEquals( $rfc3339, mysql2date( DATE_RFC3339, $mysql, false ) );
     41        $this->assertSame( $rfc3339, mysql2date( DATE_RFC3339, $mysql ) );
     42        $this->assertSame( $rfc3339, mysql2date( DATE_RFC3339, $mysql, false ) );
    4343    }
    4444
     
    5555        $mysql    = $datetime->format( 'Y-m-d H:i:s' );
    5656
    57         $this->assertEquals( $rfc3339, mysql2date( DATE_RFC3339, $mysql ) );
    58         $this->assertEquals( $rfc3339, mysql2date( DATE_RFC3339, $mysql, false ) );
     57        $this->assertSame( $rfc3339, mysql2date( DATE_RFC3339, $mysql ) );
     58        $this->assertSame( $rfc3339, mysql2date( DATE_RFC3339, $mysql, false ) );
    5959    }
    6060
     
    6969        $mysql        = $datetime->format( 'Y-m-d H:i:s' );
    7070
    71         $this->assertEquals( $wp_timestamp, mysql2date( 'U', $mysql, false ) );
    72         $this->assertEquals( $wp_timestamp, mysql2date( 'G', $mysql, false ) );
     71        $this->assertSame( $wp_timestamp, mysql2date( 'U', $mysql, false ) );
     72        $this->assertSame( $wp_timestamp, mysql2date( 'G', $mysql, false ) );
    7373    }
    7474
     
    8383        $mysql     = $datetime->format( 'Y-m-d H:i:s' );
    8484
    85         $this->assertEquals( $timestamp, mysql2date( 'U', $mysql, false ) );
    86         $this->assertEquals( $timestamp, mysql2date( 'G', $mysql, false ) );
     85        $this->assertSame( $timestamp, mysql2date( 'U', $mysql, false ) );
     86        $this->assertSame( $timestamp, mysql2date( 'G', $mysql, false ) );
    8787    }
    8888}
Note: See TracChangeset for help on using the changeset viewer.