Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (4 years 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/getTheModifiedDate.php

    r48924 r48937  
    2424        $expected = '2016-01-21';
    2525        $actual   = get_the_modified_date( $format, $post_id );
    26         $this->assertEquals( $expected, $actual );
     26        $this->assertSame( $expected, $actual );
    2727    }
    2828
     
    4747        $format   = 'Y-m-d';
    4848        $actual   = get_the_modified_date( $format );
    49         $this->assertEquals( $expected, $actual );
     49        $this->assertSame( $expected, $actual );
    5050    }
    5151
     
    6464        add_filter( 'get_the_modified_date', array( $this, '_filter_get_the_modified_date_failure' ) );
    6565        $actual = get_the_modified_date();
    66         $this->assertEquals( $expected, $actual );
     66        $this->assertSame( $expected, $actual );
    6767        remove_filter( 'get_the_modified_date', array( $this, '_filter_get_the_modified_date_failure' ) );
    6868    }
     
    7171        $expected = false;
    7272        $actual   = $the_date;
    73         $this->assertEquals( $expected, $actual );
     73        $this->assertSame( $expected, $actual );
    7474
    7575        if ( false === $the_date ) {
     
    9595        $post_id = self::factory()->post->create( array( 'post_date' => '2020-08-31 23:14:00' ) );
    9696
    97         $this->assertEquals( 'August 31, 2020', get_the_modified_date( '', $post_id ) );
    98         $this->assertEquals( 'August 31, 2020', get_the_modified_date( false, $post_id ) );
     97        $this->assertSame( 'August 31, 2020', get_the_modified_date( '', $post_id ) );
     98        $this->assertSame( 'August 31, 2020', get_the_modified_date( false, $post_id ) );
    9999    }
    100100
     
    113113        $post_id  = $this->factory->post->create( $details );
    114114        $format   = 'G';
    115         $expected = '1453390476';
     115        $expected = 1453390476;
    116116        $actual   = get_the_modified_time( $format, $post_id );
    117         $this->assertEquals( $expected, $actual );
     117        $this->assertSame( $expected, $actual );
    118118    }
    119119
     
    135135        $GLOBALS['post'] = $post;
    136136
    137         $expected = '1453390476';
     137        $expected = 1453390476;
    138138        $format   = 'G';
    139139        $actual   = get_the_modified_time( $format );
    140         $this->assertEquals( $expected, $actual );
     140        $this->assertSame( $expected, $actual );
    141141    }
    142142
     
    155155        add_filter( 'get_the_modified_time', array( $this, '_filter_get_the_modified_time_failure' ) );
    156156        $actual = get_the_modified_time();
    157         $this->assertEquals( $expected, $actual );
     157        $this->assertSame( $expected, $actual );
    158158        remove_filter( 'get_the_modified_time', array( $this, '_filter_get_the_modified_time_failure' ) );
    159159    }
     
    162162        $expected = false;
    163163        $actual   = $the_time;
    164         $this->assertEquals( $expected, $actual );
     164        $this->assertSame( $expected, $actual );
    165165
    166166        if ( false === $the_time ) {
     
    186186        $post_id = self::factory()->post->create( array( 'post_date' => '2020-08-31 23:14:00' ) );
    187187
    188         $this->assertEquals( '11:14 pm', get_the_modified_time( '', $post_id ) );
    189         $this->assertEquals( '11:14 pm', get_the_modified_time( false, $post_id ) );
     188        $this->assertSame( '11:14 pm', get_the_modified_time( '', $post_id ) );
     189        $this->assertSame( '11:14 pm', get_the_modified_time( false, $post_id ) );
    190190    }
    191191}
Note: See TracChangeset for help on using the changeset viewer.