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/meta/slashes.php

    r47122 r48937  
    7272        $post = get_post( $id );
    7373
    74         $this->assertEquals( $this->slash_6, get_post_meta( $id, 'slash_test_0', true ) );
    75         $this->assertEquals( $this->slash_1, get_post_meta( $id, 'slash_test_1', true ) );
    76         $this->assertEquals( $this->slash_3, get_post_meta( $id, 'slash_test_2', true ) );
    77         $this->assertEquals( $this->slash_4, get_post_meta( $id, 'slash_test_3', true ) );
     74        $this->assertSame( $this->slash_6, get_post_meta( $id, 'slash_test_0', true ) );
     75        $this->assertSame( $this->slash_1, get_post_meta( $id, 'slash_test_1', true ) );
     76        $this->assertSame( $this->slash_3, get_post_meta( $id, 'slash_test_2', true ) );
     77        $this->assertSame( $this->slash_4, get_post_meta( $id, 'slash_test_3', true ) );
    7878
    7979        $_POST                  = array();
     
    102102        $post = get_post( $id );
    103103
    104         $this->assertEquals( $this->slash_2, get_post_meta( $id, 'slash_test_1', true ) );
    105         $this->assertEquals( $this->slash_4, get_post_meta( $id, 'slash_test_2', true ) );
    106         $this->assertEquals( $this->slash_5, get_post_meta( $id, 'slash_test_3', true ) );
     104        $this->assertSame( $this->slash_2, get_post_meta( $id, 'slash_test_1', true ) );
     105        $this->assertSame( $this->slash_4, get_post_meta( $id, 'slash_test_2', true ) );
     106        $this->assertSame( $this->slash_5, get_post_meta( $id, 'slash_test_3', true ) );
    107107    }
    108108
     
    116116        add_post_meta( $id, 'slash_test_3', addslashes( $this->slash_4 ) );
    117117
    118         $this->assertEquals( $this->slash_1, get_post_meta( $id, 'slash_test_1', true ) );
    119         $this->assertEquals( $this->slash_3, get_post_meta( $id, 'slash_test_2', true ) );
    120         $this->assertEquals( $this->slash_4, get_post_meta( $id, 'slash_test_3', true ) );
     118        $this->assertSame( $this->slash_1, get_post_meta( $id, 'slash_test_1', true ) );
     119        $this->assertSame( $this->slash_3, get_post_meta( $id, 'slash_test_2', true ) );
     120        $this->assertSame( $this->slash_4, get_post_meta( $id, 'slash_test_3', true ) );
    121121    }
    122122
     
    130130        update_post_meta( $id, 'slash_test_3', addslashes( $this->slash_4 ) );
    131131
    132         $this->assertEquals( $this->slash_1, get_post_meta( $id, 'slash_test_1', true ) );
    133         $this->assertEquals( $this->slash_3, get_post_meta( $id, 'slash_test_2', true ) );
    134         $this->assertEquals( $this->slash_4, get_post_meta( $id, 'slash_test_3', true ) );
     132        $this->assertSame( $this->slash_1, get_post_meta( $id, 'slash_test_1', true ) );
     133        $this->assertSame( $this->slash_3, get_post_meta( $id, 'slash_test_2', true ) );
     134        $this->assertSame( $this->slash_4, get_post_meta( $id, 'slash_test_3', true ) );
    135135    }
    136136
     
    145145        add_comment_meta( $id, 'slash_test_3', $this->slash_5 );
    146146
    147         $this->assertEquals( wp_unslash( $this->slash_1 ), get_comment_meta( $id, 'slash_test_1', true ) );
    148         $this->assertEquals( wp_unslash( $this->slash_3 ), get_comment_meta( $id, 'slash_test_2', true ) );
    149         $this->assertEquals( wp_unslash( $this->slash_5 ), get_comment_meta( $id, 'slash_test_3', true ) );
     147        $this->assertSame( wp_unslash( $this->slash_1 ), get_comment_meta( $id, 'slash_test_1', true ) );
     148        $this->assertSame( wp_unslash( $this->slash_3 ), get_comment_meta( $id, 'slash_test_2', true ) );
     149        $this->assertSame( wp_unslash( $this->slash_5 ), get_comment_meta( $id, 'slash_test_3', true ) );
    150150
    151151        add_comment_meta( $id, 'slash_test_4', $this->slash_2 );
     
    153153        add_comment_meta( $id, 'slash_test_6', $this->slash_6 );
    154154
    155         $this->assertEquals( wp_unslash( $this->slash_2 ), get_comment_meta( $id, 'slash_test_4', true ) );
    156         $this->assertEquals( wp_unslash( $this->slash_4 ), get_comment_meta( $id, 'slash_test_5', true ) );
    157         $this->assertEquals( wp_unslash( $this->slash_6 ), get_comment_meta( $id, 'slash_test_6', true ) );
     155        $this->assertSame( wp_unslash( $this->slash_2 ), get_comment_meta( $id, 'slash_test_4', true ) );
     156        $this->assertSame( wp_unslash( $this->slash_4 ), get_comment_meta( $id, 'slash_test_5', true ) );
     157        $this->assertSame( wp_unslash( $this->slash_6 ), get_comment_meta( $id, 'slash_test_6', true ) );
    158158    }
    159159
     
    172172        update_comment_meta( $id, 'slash_test_3', $this->slash_5 );
    173173
    174         $this->assertEquals( wp_unslash( $this->slash_1 ), get_comment_meta( $id, 'slash_test_1', true ) );
    175         $this->assertEquals( wp_unslash( $this->slash_3 ), get_comment_meta( $id, 'slash_test_2', true ) );
    176         $this->assertEquals( wp_unslash( $this->slash_5 ), get_comment_meta( $id, 'slash_test_3', true ) );
     174        $this->assertSame( wp_unslash( $this->slash_1 ), get_comment_meta( $id, 'slash_test_1', true ) );
     175        $this->assertSame( wp_unslash( $this->slash_3 ), get_comment_meta( $id, 'slash_test_2', true ) );
     176        $this->assertSame( wp_unslash( $this->slash_5 ), get_comment_meta( $id, 'slash_test_3', true ) );
    177177
    178178        update_comment_meta( $id, 'slash_test_1', $this->slash_2 );
     
    180180        update_comment_meta( $id, 'slash_test_3', $this->slash_6 );
    181181
    182         $this->assertEquals( wp_unslash( $this->slash_2 ), get_comment_meta( $id, 'slash_test_1', true ) );
    183         $this->assertEquals( wp_unslash( $this->slash_4 ), get_comment_meta( $id, 'slash_test_2', true ) );
    184         $this->assertEquals( wp_unslash( $this->slash_6 ), get_comment_meta( $id, 'slash_test_3', true ) );
     182        $this->assertSame( wp_unslash( $this->slash_2 ), get_comment_meta( $id, 'slash_test_1', true ) );
     183        $this->assertSame( wp_unslash( $this->slash_4 ), get_comment_meta( $id, 'slash_test_2', true ) );
     184        $this->assertSame( wp_unslash( $this->slash_6 ), get_comment_meta( $id, 'slash_test_3', true ) );
    185185    }
    186186
     
    195195        add_user_meta( $id, 'slash_test_3', $this->slash_5 );
    196196
    197         $this->assertEquals( wp_unslash( $this->slash_1 ), get_user_meta( $id, 'slash_test_1', true ) );
    198         $this->assertEquals( wp_unslash( $this->slash_3 ), get_user_meta( $id, 'slash_test_2', true ) );
    199         $this->assertEquals( wp_unslash( $this->slash_5 ), get_user_meta( $id, 'slash_test_3', true ) );
     197        $this->assertSame( wp_unslash( $this->slash_1 ), get_user_meta( $id, 'slash_test_1', true ) );
     198        $this->assertSame( wp_unslash( $this->slash_3 ), get_user_meta( $id, 'slash_test_2', true ) );
     199        $this->assertSame( wp_unslash( $this->slash_5 ), get_user_meta( $id, 'slash_test_3', true ) );
    200200
    201201        add_user_meta( $id, 'slash_test_4', $this->slash_2 );
     
    203203        add_user_meta( $id, 'slash_test_6', $this->slash_6 );
    204204
    205         $this->assertEquals( wp_unslash( $this->slash_2 ), get_user_meta( $id, 'slash_test_4', true ) );
    206         $this->assertEquals( wp_unslash( $this->slash_4 ), get_user_meta( $id, 'slash_test_5', true ) );
    207         $this->assertEquals( wp_unslash( $this->slash_6 ), get_user_meta( $id, 'slash_test_6', true ) );
     205        $this->assertSame( wp_unslash( $this->slash_2 ), get_user_meta( $id, 'slash_test_4', true ) );
     206        $this->assertSame( wp_unslash( $this->slash_4 ), get_user_meta( $id, 'slash_test_5', true ) );
     207        $this->assertSame( wp_unslash( $this->slash_6 ), get_user_meta( $id, 'slash_test_6', true ) );
    208208    }
    209209
     
    222222        update_user_meta( $id, 'slash_test_3', $this->slash_5 );
    223223
    224         $this->assertEquals( wp_unslash( $this->slash_1 ), get_user_meta( $id, 'slash_test_1', true ) );
    225         $this->assertEquals( wp_unslash( $this->slash_3 ), get_user_meta( $id, 'slash_test_2', true ) );
    226         $this->assertEquals( wp_unslash( $this->slash_5 ), get_user_meta( $id, 'slash_test_3', true ) );
     224        $this->assertSame( wp_unslash( $this->slash_1 ), get_user_meta( $id, 'slash_test_1', true ) );
     225        $this->assertSame( wp_unslash( $this->slash_3 ), get_user_meta( $id, 'slash_test_2', true ) );
     226        $this->assertSame( wp_unslash( $this->slash_5 ), get_user_meta( $id, 'slash_test_3', true ) );
    227227
    228228        update_user_meta( $id, 'slash_test_1', $this->slash_2 );
     
    230230        update_user_meta( $id, 'slash_test_3', $this->slash_6 );
    231231
    232         $this->assertEquals( wp_unslash( $this->slash_2 ), get_user_meta( $id, 'slash_test_1', true ) );
    233         $this->assertEquals( wp_unslash( $this->slash_4 ), get_user_meta( $id, 'slash_test_2', true ) );
    234         $this->assertEquals( wp_unslash( $this->slash_6 ), get_user_meta( $id, 'slash_test_3', true ) );
     232        $this->assertSame( wp_unslash( $this->slash_2 ), get_user_meta( $id, 'slash_test_1', true ) );
     233        $this->assertSame( wp_unslash( $this->slash_4 ), get_user_meta( $id, 'slash_test_2', true ) );
     234        $this->assertSame( wp_unslash( $this->slash_6 ), get_user_meta( $id, 'slash_test_3', true ) );
    235235    }
    236236}
Note: See TracChangeset for help on using the changeset viewer.