WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (15 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/comment/wpCountComments.php

    r46586 r48937  
    66        $count = wp_count_comments();
    77
    8         $this->assertEquals( 0, $count->approved );
    9         $this->assertEquals( 0, $count->moderated );
    10         $this->assertEquals( 0, $count->spam );
    11         $this->assertEquals( 0, $count->trash );
    12         $this->assertEquals( 0, $count->{'post-trashed'} );
    13         $this->assertEquals( 0, $count->total_comments );
    14         $this->assertEquals( 0, $count->all );
     8        $this->assertSame( 0, $count->approved );
     9        $this->assertSame( 0, $count->moderated );
     10        $this->assertSame( 0, $count->spam );
     11        $this->assertSame( 0, $count->trash );
     12        $this->assertSame( 0, $count->{'post-trashed'} );
     13        $this->assertSame( 0, $count->total_comments );
     14        $this->assertSame( 0, $count->all );
    1515    }
    1616
     
    2424        $count = wp_count_comments();
    2525
    26         $this->assertEquals( 1, $count->approved );
    27         $this->assertEquals( 0, $count->moderated );
    28         $this->assertEquals( 0, $count->spam );
    29         $this->assertEquals( 0, $count->trash );
    30         $this->assertEquals( 0, $count->{'post-trashed'} );
    31         $this->assertEquals( 1, $count->total_comments );
    32         $this->assertEquals( 1, $count->all );
     26        $this->assertSame( 1, $count->approved );
     27        $this->assertSame( 0, $count->moderated );
     28        $this->assertSame( 0, $count->spam );
     29        $this->assertSame( 0, $count->trash );
     30        $this->assertSame( 0, $count->{'post-trashed'} );
     31        $this->assertSame( 1, $count->total_comments );
     32        $this->assertSame( 1, $count->all );
    3333    }
    3434
     
    4242        $count = wp_count_comments();
    4343
    44         $this->assertEquals( 0, $count->approved );
    45         $this->assertEquals( 1, $count->moderated );
    46         $this->assertEquals( 0, $count->spam );
    47         $this->assertEquals( 0, $count->trash );
    48         $this->assertEquals( 0, $count->{'post-trashed'} );
    49         $this->assertEquals( 1, $count->total_comments );
    50         $this->assertEquals( 1, $count->all );
     44        $this->assertSame( 0, $count->approved );
     45        $this->assertSame( 1, $count->moderated );
     46        $this->assertSame( 0, $count->spam );
     47        $this->assertSame( 0, $count->trash );
     48        $this->assertSame( 0, $count->{'post-trashed'} );
     49        $this->assertSame( 1, $count->total_comments );
     50        $this->assertSame( 1, $count->all );
    5151    }
    5252
     
    6060        $count = wp_count_comments();
    6161
    62         $this->assertEquals( 0, $count->approved );
    63         $this->assertEquals( 0, $count->moderated );
    64         $this->assertEquals( 1, $count->spam );
    65         $this->assertEquals( 0, $count->trash );
    66         $this->assertEquals( 0, $count->{'post-trashed'} );
    67         $this->assertEquals( 1, $count->total_comments );
    68         $this->assertEquals( 0, $count->all );
     62        $this->assertSame( 0, $count->approved );
     63        $this->assertSame( 0, $count->moderated );
     64        $this->assertSame( 1, $count->spam );
     65        $this->assertSame( 0, $count->trash );
     66        $this->assertSame( 0, $count->{'post-trashed'} );
     67        $this->assertSame( 1, $count->total_comments );
     68        $this->assertSame( 0, $count->all );
    6969    }
    7070
     
    7878        $count = wp_count_comments();
    7979
    80         $this->assertEquals( 0, $count->approved );
    81         $this->assertEquals( 0, $count->moderated );
    82         $this->assertEquals( 0, $count->spam );
    83         $this->assertEquals( 1, $count->trash );
    84         $this->assertEquals( 0, $count->{'post-trashed'} );
    85         $this->assertEquals( 0, $count->total_comments );
    86         $this->assertEquals( 0, $count->all );
     80        $this->assertSame( 0, $count->approved );
     81        $this->assertSame( 0, $count->moderated );
     82        $this->assertSame( 0, $count->spam );
     83        $this->assertSame( 1, $count->trash );
     84        $this->assertSame( 0, $count->{'post-trashed'} );
     85        $this->assertSame( 0, $count->total_comments );
     86        $this->assertSame( 0, $count->all );
    8787    }
    8888
     
    9696        $count = wp_count_comments();
    9797
    98         $this->assertEquals( 0, $count->approved );
    99         $this->assertEquals( 0, $count->moderated );
    100         $this->assertEquals( 0, $count->spam );
    101         $this->assertEquals( 0, $count->trash );
    102         $this->assertEquals( 1, $count->{'post-trashed'} );
    103         $this->assertEquals( 0, $count->total_comments );
    104         $this->assertEquals( 0, $count->all );
     98        $this->assertSame( 0, $count->approved );
     99        $this->assertSame( 0, $count->moderated );
     100        $this->assertSame( 0, $count->spam );
     101        $this->assertSame( 0, $count->trash );
     102        $this->assertSame( 1, $count->{'post-trashed'} );
     103        $this->assertSame( 0, $count->total_comments );
     104        $this->assertSame( 0, $count->all );
    105105    }
    106106
     
    120120        $count1 = wp_count_comments( $post_id );
    121121
    122         $this->assertEquals( 1, $count1->approved );
    123         $this->assertEquals( 0, $count1->moderated );
    124         $this->assertEquals( 0, $count1->spam );
    125         $this->assertEquals( 0, $count1->trash );
    126         $this->assertEquals( 0, $count1->{'post-trashed'} );
    127         $this->assertEquals( 1, $count1->total_comments );
    128         $this->assertEquals( 1, $count1->all );
     122        $this->assertSame( 1, $count1->approved );
     123        $this->assertSame( 0, $count1->moderated );
     124        $this->assertSame( 0, $count1->spam );
     125        $this->assertSame( 0, $count1->trash );
     126        $this->assertSame( 0, $count1->{'post-trashed'} );
     127        $this->assertSame( 1, $count1->total_comments );
     128        $this->assertSame( 1, $count1->all );
    129129
    130130        $all_count1 = wp_count_comments();
    131131
    132         $this->assertEquals( 1, $all_count1->approved );
    133         $this->assertEquals( 0, $all_count1->moderated );
    134         $this->assertEquals( 0, $all_count1->spam );
    135         $this->assertEquals( 0, $all_count1->trash );
    136         $this->assertEquals( 0, $all_count1->{'post-trashed'} );
    137         $this->assertEquals( 1, $all_count1->total_comments );
    138         $this->assertEquals( 1, $all_count1->all );
     132        $this->assertSame( 1, $all_count1->approved );
     133        $this->assertSame( 0, $all_count1->moderated );
     134        $this->assertSame( 0, $all_count1->spam );
     135        $this->assertSame( 0, $all_count1->trash );
     136        $this->assertSame( 0, $all_count1->{'post-trashed'} );
     137        $this->assertSame( 1, $all_count1->total_comments );
     138        $this->assertSame( 1, $all_count1->all );
    139139
    140140        wp_spam_comment( $comment_id );
     
    142142        $count2 = wp_count_comments( $post_id );
    143143
    144         $this->assertEquals( 0, $count2->approved );
    145         $this->assertEquals( 0, $count2->moderated );
    146         $this->assertEquals( 1, $count2->spam );
    147         $this->assertEquals( 0, $count2->trash );
    148         $this->assertEquals( 0, $count2->{'post-trashed'} );
    149         $this->assertEquals( 1, $count2->total_comments );
    150         $this->assertEquals( 0, $count2->all );
     144        $this->assertSame( 0, $count2->approved );
     145        $this->assertSame( 0, $count2->moderated );
     146        $this->assertSame( 1, $count2->spam );
     147        $this->assertSame( 0, $count2->trash );
     148        $this->assertSame( 0, $count2->{'post-trashed'} );
     149        $this->assertSame( 1, $count2->total_comments );
     150        $this->assertSame( 0, $count2->all );
    151151
    152152        $all_count2 = wp_count_comments();
    153153
    154         $this->assertEquals( 0, $all_count2->approved );
    155         $this->assertEquals( 0, $all_count2->moderated );
    156         $this->assertEquals( 1, $all_count2->spam );
    157         $this->assertEquals( 0, $all_count2->trash );
    158         $this->assertEquals( 0, $all_count2->{'post-trashed'} );
    159         $this->assertEquals( 1, $all_count2->total_comments );
    160         $this->assertEquals( 0, $all_count2->all );
     154        $this->assertSame( 0, $all_count2->approved );
     155        $this->assertSame( 0, $all_count2->moderated );
     156        $this->assertSame( 1, $all_count2->spam );
     157        $this->assertSame( 0, $all_count2->trash );
     158        $this->assertSame( 0, $all_count2->{'post-trashed'} );
     159        $this->assertSame( 1, $all_count2->total_comments );
     160        $this->assertSame( 0, $all_count2->all );
    161161
    162162        wp_trash_comment( $comment_id );
     
    164164        $count3 = wp_count_comments( $post_id );
    165165
    166         $this->assertEquals( 0, $count3->approved );
    167         $this->assertEquals( 0, $count3->moderated );
    168         $this->assertEquals( 0, $count3->spam );
    169         $this->assertEquals( 1, $count3->trash );
    170         $this->assertEquals( 0, $count3->{'post-trashed'} );
    171         $this->assertEquals( 0, $count3->total_comments );
    172         $this->assertEquals( 0, $count3->all );
     166        $this->assertSame( 0, $count3->approved );
     167        $this->assertSame( 0, $count3->moderated );
     168        $this->assertSame( 0, $count3->spam );
     169        $this->assertSame( 1, $count3->trash );
     170        $this->assertSame( 0, $count3->{'post-trashed'} );
     171        $this->assertSame( 0, $count3->total_comments );
     172        $this->assertSame( 0, $count3->all );
    173173
    174174        $all_count3 = wp_count_comments();
    175175
    176         $this->assertEquals( 0, $all_count3->approved );
    177         $this->assertEquals( 0, $all_count3->moderated );
    178         $this->assertEquals( 0, $all_count3->spam );
    179         $this->assertEquals( 1, $all_count3->trash );
    180         $this->assertEquals( 0, $all_count3->{'post-trashed'} );
    181         $this->assertEquals( 0, $all_count3->total_comments );
    182         $this->assertEquals( 0, $all_count3->all );
     176        $this->assertSame( 0, $all_count3->approved );
     177        $this->assertSame( 0, $all_count3->moderated );
     178        $this->assertSame( 0, $all_count3->spam );
     179        $this->assertSame( 1, $all_count3->trash );
     180        $this->assertSame( 0, $all_count3->{'post-trashed'} );
     181        $this->assertSame( 0, $all_count3->total_comments );
     182        $this->assertSame( 0, $all_count3->all );
    183183
    184184        wp_untrash_comment( $comment_id );
     
    186186        $count4 = wp_count_comments( $post_id );
    187187
    188         $this->assertEquals( 0, $count4->approved );
    189         $this->assertEquals( 0, $count4->moderated );
    190         $this->assertEquals( 1, $count4->spam );
    191         $this->assertEquals( 0, $count4->trash );
    192         $this->assertEquals( 0, $count4->{'post-trashed'} );
    193         $this->assertEquals( 1, $count4->total_comments );
    194         $this->assertEquals( 0, $count4->all );
     188        $this->assertSame( 0, $count4->approved );
     189        $this->assertSame( 0, $count4->moderated );
     190        $this->assertSame( 1, $count4->spam );
     191        $this->assertSame( 0, $count4->trash );
     192        $this->assertSame( 0, $count4->{'post-trashed'} );
     193        $this->assertSame( 1, $count4->total_comments );
     194        $this->assertSame( 0, $count4->all );
    195195
    196196        $all_count4 = wp_count_comments();
    197197
    198         $this->assertEquals( 0, $all_count4->approved );
    199         $this->assertEquals( 0, $all_count4->moderated );
    200         $this->assertEquals( 1, $all_count4->spam );
    201         $this->assertEquals( 0, $all_count4->trash );
    202         $this->assertEquals( 0, $all_count4->{'post-trashed'} );
    203         $this->assertEquals( 1, $all_count4->total_comments );
    204         $this->assertEquals( 0, $all_count4->all );
     198        $this->assertSame( 0, $all_count4->approved );
     199        $this->assertSame( 0, $all_count4->moderated );
     200        $this->assertSame( 1, $all_count4->spam );
     201        $this->assertSame( 0, $all_count4->trash );
     202        $this->assertSame( 0, $all_count4->{'post-trashed'} );
     203        $this->assertSame( 1, $all_count4->total_comments );
     204        $this->assertSame( 0, $all_count4->all );
    205205    }
    206206}
Note: See TracChangeset for help on using the changeset viewer.