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

    r48911 r48937  
    6262        ob_end_clean();
    6363
    64         $this->assertEquals( 1, $this->hooks_called['the_time'] );
    65         $this->assertEquals( 2, $this->hooks_called['get_the_time'] );
     64        $this->assertSame( 1, $this->hooks_called['the_time'] );
     65        $this->assertSame( 2, $this->hooks_called['get_the_time'] );
    6666
    67         $this->assertEquals( 1, $this->hooks_called['the_modified_time'] );
    68         $this->assertEquals( 2, $this->hooks_called['get_the_modified_time'] );
     67        $this->assertSame( 1, $this->hooks_called['the_modified_time'] );
     68        $this->assertSame( 2, $this->hooks_called['get_the_modified_time'] );
    6969
    70         $this->assertEquals( 1, $this->hooks_called['the_date'] );
    71         $this->assertEquals( 2, $this->hooks_called['get_the_date'] );
     70        $this->assertSame( 1, $this->hooks_called['the_date'] );
     71        $this->assertSame( 2, $this->hooks_called['get_the_date'] );
    7272
    73         $this->assertEquals( 1, $this->hooks_called['the_modified_date'] );
    74         $this->assertEquals( 2, $this->hooks_called['get_the_modified_date'] );
     73        $this->assertSame( 1, $this->hooks_called['the_modified_date'] );
     74        $this->assertSame( 2, $this->hooks_called['get_the_modified_date'] );
    7575
    76         $this->assertEquals( 5, $this->hooks_called['get_post_time'] );
    77         $this->assertEquals( 5, $this->hooks_called['get_post_modified_time'] );
     76        $this->assertSame( 5, $this->hooks_called['get_post_time'] );
     77        $this->assertSame( 5, $this->hooks_called['get_post_modified_time'] );
    7878    }
    7979
     
    9191        the_date();
    9292        $actual = ob_get_clean();
    93         $this->assertEquals( '', $actual );
     93        $this->assertSame( '', $actual );
    9494
    9595        $GLOBALS['post'] = self::factory()->post->create_and_get(
     
    103103        $GLOBALS['previousday'] = '17.09.15';
    104104        the_date();
    105         $this->assertEquals( 'September 16, 2015', ob_get_clean() );
     105        $this->assertSame( 'September 16, 2015', ob_get_clean() );
    106106
    107107        ob_start();
     
    109109        $GLOBALS['previousday'] = '17.09.15';
    110110        the_date( 'Y' );
    111         $this->assertEquals( '2015', ob_get_clean() );
     111        $this->assertSame( '2015', ob_get_clean() );
    112112
    113113        ob_start();
     
    115115        $GLOBALS['previousday'] = '17.09.15';
    116116        the_date( 'Y', 'before ', ' after' );
    117         $this->assertEquals( 'before 2015 after', ob_get_clean() );
     117        $this->assertSame( 'before 2015 after', ob_get_clean() );
    118118
    119119        ob_start();
     
    121121        $GLOBALS['previousday'] = '17.09.15';
    122122        the_date( 'Y', 'before ', ' after', false );
    123         $this->assertEquals( '', ob_get_clean() );
     123        $this->assertSame( '', ob_get_clean() );
    124124    }
    125125
     
    131131        the_weekday_date();
    132132        $actual = ob_get_clean();
    133         $this->assertEquals( '', $actual );
     133        $this->assertSame( '', $actual );
    134134
    135135        $GLOBALS['post'] = self::factory()->post->create_and_get(
     
    143143        $GLOBALS['previousweekday'] = '17.09.15';
    144144        the_weekday_date();
    145         $this->assertEquals( 'Wednesday', ob_get_clean() );
     145        $this->assertSame( 'Wednesday', ob_get_clean() );
    146146
    147147        ob_start();
     
    149149        $GLOBALS['previousweekday'] = '17.09.15';
    150150        the_weekday_date( 'before ', ' after' );
    151         $this->assertEquals( 'before Wednesday after', ob_get_clean() );
     151        $this->assertSame( 'before Wednesday after', ob_get_clean() );
    152152    }
    153153}
Note: See TracChangeset for help on using the changeset viewer.