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

    r48912 r48937  
    1414        $post_id = self::factory()->post->create( array( 'post_date' => '2014-03-01 16:35:00' ) );
    1515
    16         $this->assertEquals( '16:35:00', get_post_time( 'H:i:s', false, $post_id ) );
     16        $this->assertSame( '16:35:00', get_post_time( 'H:i:s', false, $post_id ) );
    1717    }
    1818
     
    3333        $post_id = self::factory()->post->create( array( 'post_date' => '2014-03-01 16:35:00' ) );
    3434
    35         $this->assertEquals( '16:35:00', get_post_modified_time( 'H:i:s', false, $post_id ) );
     35        $this->assertSame( '16:35:00', get_post_modified_time( 'H:i:s', false, $post_id ) );
    3636    }
    3737
     
    6565        );
    6666
    67         $this->assertEquals( $wp_timestamp, get_post_time( 'U', false, $post_id ) );
    68         $this->assertEquals( $wp_timestamp, get_post_time( 'G', false, $post_id ) );
    69         $this->assertEquals( $timestamp, get_post_time( 'U', true, $post_id ) );
    70         $this->assertEquals( $timestamp, get_post_time( 'G', true, $post_id ) );
    71         $this->assertEquals( $wp_timestamp, get_post_modified_time( 'U', false, $post_id ) );
    72         $this->assertEquals( $wp_timestamp, get_post_modified_time( 'G', false, $post_id ) );
    73         $this->assertEquals( $timestamp, get_post_modified_time( 'U', true, $post_id ) );
    74         $this->assertEquals( $timestamp, get_post_modified_time( 'G', true, $post_id ) );
     67        $this->assertSame( $wp_timestamp, get_post_time( 'U', false, $post_id ) );
     68        $this->assertSame( $wp_timestamp, get_post_time( 'G', false, $post_id ) );
     69        $this->assertSame( $timestamp, get_post_time( 'U', true, $post_id ) );
     70        $this->assertSame( $timestamp, get_post_time( 'G', true, $post_id ) );
     71        $this->assertSame( $wp_timestamp, get_post_modified_time( 'U', false, $post_id ) );
     72        $this->assertSame( $wp_timestamp, get_post_modified_time( 'G', false, $post_id ) );
     73        $this->assertSame( $timestamp, get_post_modified_time( 'U', true, $post_id ) );
     74        $this->assertSame( $timestamp, get_post_modified_time( 'G', true, $post_id ) );
    7575    }
    7676
     
    9393        );
    9494
    95         $this->assertEquals( $rfc3339, get_post_time( DATE_RFC3339, false, $post_id ) );
    96         $this->assertEquals( $rfc3339_utc, get_post_time( DATE_RFC3339, true, $post_id ) );
    97         $this->assertEquals( $rfc3339, get_post_time( DATE_RFC3339, false, $post_id, true ) );
    98         $this->assertEquals( $rfc3339_utc, get_post_time( DATE_RFC3339, true, $post_id, true ) );
    99         $this->assertEquals( $rfc3339, get_post_modified_time( DATE_RFC3339, false, $post_id ) );
    100         $this->assertEquals( $rfc3339_utc, get_post_modified_time( DATE_RFC3339, true, $post_id ) );
    101         $this->assertEquals( $rfc3339, get_post_modified_time( DATE_RFC3339, false, $post_id, true ) );
    102         $this->assertEquals( $rfc3339_utc, get_post_modified_time( DATE_RFC3339, true, $post_id, true ) );
     95        $this->assertSame( $rfc3339, get_post_time( DATE_RFC3339, false, $post_id ) );
     96        $this->assertSame( $rfc3339_utc, get_post_time( DATE_RFC3339, true, $post_id ) );
     97        $this->assertSame( $rfc3339, get_post_time( DATE_RFC3339, false, $post_id, true ) );
     98        $this->assertSame( $rfc3339_utc, get_post_time( DATE_RFC3339, true, $post_id, true ) );
     99        $this->assertSame( $rfc3339, get_post_modified_time( DATE_RFC3339, false, $post_id ) );
     100        $this->assertSame( $rfc3339_utc, get_post_modified_time( DATE_RFC3339, true, $post_id ) );
     101        $this->assertSame( $rfc3339, get_post_modified_time( DATE_RFC3339, false, $post_id, true ) );
     102        $this->assertSame( $rfc3339_utc, get_post_modified_time( DATE_RFC3339, true, $post_id, true ) );
    103103    }
    104104
     
    122122        update_option( 'timezone_string', 'Europe/Kiev' );
    123123
    124         $this->assertEquals( $rfc3339, get_post_time( DATE_RFC3339, true, $post_id ) );
    125         $this->assertEquals( $rfc3339, get_post_modified_time( DATE_RFC3339, true, $post_id ) );
     124        $this->assertSame( $rfc3339, get_post_time( DATE_RFC3339, true, $post_id ) );
     125        $this->assertSame( $rfc3339, get_post_modified_time( DATE_RFC3339, true, $post_id ) );
    126126    }
    127127}
Note: See TracChangeset for help on using the changeset viewer.