WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/04/2020 07:01:00 AM (17 months ago)
Author:
SergeyBiryukov
Message:

Tests: Introduce assertSameSets() and assertSameSetsWithIndex(), and use them where appropriate.

This ensures that not only the array values being compared are equal, but also that their type is the same.

These new methods replace most of the existing instances of assertEqualSets() and assertEqualSetsWithIndex().

Going forward, stricter type checking by using assertSameSets() or assertSameSetsWithIndex() should generally be preferred, to make the tests more reliable.

Follow-up to [48937].

See #38266.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/comment/query.php

    r48937 r48939  
    6161        );
    6262
    63         $this->assertEqualSets( array( $c1, $c2, $c3, $c4, $c5 ), $found );
     63        $this->assertSameSets( array( $c1, $c2, $c3, $c4, $c5 ), $found );
    6464    }
    6565
     
    8080        );
    8181
    82         $this->assertEqualSets( array( $c1 ), $found );
     82        $this->assertSameSets( array( $c1 ), $found );
    8383    }
    8484
     
    130130        );
    131131
    132         $this->assertEqualSets( array( $c1, $c2, $c3, $c4, $c5 ), $found );
     132        $this->assertSameSets( array( $c1, $c2, $c3, $c4, $c5 ), $found );
    133133    }
    134134
     
    180180        );
    181181
    182         $this->assertEqualSets( array( $c1 ), $found );
     182        $this->assertSameSets( array( $c1 ), $found );
    183183    }
    184184
     
    220220        );
    221221
    222         $this->assertEqualSets( array( $c2, $c3 ), $found );
     222        $this->assertSameSets( array( $c2, $c3 ), $found );
    223223
    224224    }
     
    261261        );
    262262
    263         $this->assertEqualSets( array( $c2, $c3 ), $found );
     263        $this->assertSameSets( array( $c2, $c3 ), $found );
    264264
    265265    }
     
    312312        );
    313313
    314         $this->assertEqualSets( array( $c2, $c3 ), $found );
     314        $this->assertSameSets( array( $c2, $c3 ), $found );
    315315    }
    316316
     
    371371        );
    372372
    373         $this->assertEqualSets( array( $c1, $c4, $c6 ), $found );
     373        $this->assertSameSets( array( $c1, $c4, $c6 ), $found );
    374374    }
    375375
     
    428428        );
    429429
    430         $this->assertEqualSets( array( $c1, $c2, $c3, $c4, $c6 ), $found );
     430        $this->assertSameSets( array( $c1, $c2, $c3, $c4, $c6 ), $found );
    431431    }
    432432
     
    486486        );
    487487
    488         $this->assertEqualSets( array( $c1 ), $found );
     488        $this->assertSameSets( array( $c1 ), $found );
    489489    }
    490490
     
    544544        );
    545545
    546         $this->assertEqualSets( array( $c2, $c3 ), $found );
     546        $this->assertSameSets( array( $c2, $c3 ), $found );
    547547    }
    548548
     
    601601        );
    602602
    603         $this->assertEqualSets( array( $c1, $c2, $c3, $c4, $c6 ), $found );
     603        $this->assertSameSets( array( $c1, $c2, $c3, $c4, $c6 ), $found );
    604604    }
    605605
     
    651651        );
    652652
    653         $this->assertEqualSets( array( $c1, $c2, $c3 ), $found );
     653        $this->assertSameSets( array( $c1, $c2, $c3 ), $found );
    654654    }
    655655
     
    687687        );
    688688
    689         $this->assertEqualSets( array( $c1, $c2, $c3 ), $found );
     689        $this->assertSameSets( array( $c1, $c2, $c3 ), $found );
    690690    }
    691691
     
    795795        );
    796796
    797         $this->assertEqualSets( array( $c2, $c3 ), $found );
     797        $this->assertSameSets( array( $c2, $c3 ), $found );
    798798    }
    799799
     
    839839        );
    840840
    841         $this->assertEqualSets( array( $c3, $c2 ), $found );
     841        $this->assertSameSets( array( $c3, $c2 ), $found );
    842842    }
    843843
     
    955955        );
    956956
    957         $this->assertEqualSets( array( $c3, $c2 ), $found );
     957        $this->assertSameSets( array( $c3, $c2 ), $found );
    958958    }
    959959
     
    989989        );
    990990
    991         $this->assertEqualSets( array( $c1, $c2 ), $found );
     991        $this->assertSameSets( array( $c1, $c2 ), $found );
    992992    }
    993993
     
    11071107        );
    11081108
    1109         $this->assertEqualSets( array( $c1, $c3 ), $found );
     1109        $this->assertSameSets( array( $c1, $c3 ), $found );
    11101110    }
    11111111
     
    11371137        );
    11381138
    1139         $this->assertEqualSets( array( $c1, $c3 ), $found );
     1139        $this->assertSameSets( array( $c1, $c3 ), $found );
    11401140    }
    11411141
     
    11711171        );
    11721172
    1173         $this->assertEqualSets( array( $c1, $c2, $c3 ), $found );
     1173        $this->assertSameSets( array( $c1, $c2, $c3 ), $found );
    11741174    }
    11751175
     
    12051205        );
    12061206
    1207         $this->assertEqualSets( array( $c1, $c2 ), $found );
     1207        $this->assertSameSets( array( $c1, $c2 ), $found );
    12081208    }
    12091209
     
    12391239        );
    12401240
    1241         $this->assertEqualSets( array( $c1, $c2 ), $found );
     1241        $this->assertSameSets( array( $c1, $c2 ), $found );
    12421242    }
    12431243
     
    16881688        );
    16891689
    1690         $this->assertEqualSets( array( $c1, $c2 ), $comments );
     1690        $this->assertSameSets( array( $c1, $c2 ), $comments );
    16911691    }
    16921692
     
    17241724        $comment_ids = get_comments( array( 'fields' => 'ids' ) );
    17251725        $this->assertCount( 3, $comment_ids );
    1726         $this->assertEqualSets( array( $comment_1, $comment_2, $comment_3 ), $comment_ids );
     1726        $this->assertSameSets( array( $comment_1, $comment_2, $comment_3 ), $comment_ids );
    17271727    }
    17281728
     
    17601760        );
    17611761
    1762         $this->assertEqualSets( array( $comment_1, $comment_3 ), $comment_ids );
     1762        $this->assertSameSets( array( $comment_1, $comment_3 ), $comment_ids );
    17631763    }
    17641764
     
    17961796        );
    17971797
    1798         $this->assertEqualSets( array( $comment_1 ), $comment_ids );
     1798        $this->assertSameSets( array( $comment_1 ), $comment_ids );
    17991799    }
    18001800
     
    18361836        );
    18371837
    1838         $this->assertEqualSets( array( $c1, $c2 ), $comment_ids );
     1838        $this->assertSameSets( array( $c1, $c2 ), $comment_ids );
    18391839    }
    18401840
     
    18761876        );
    18771877
    1878         $this->assertEqualSets( array( $c3 ), $comment_ids );
     1878        $this->assertSameSets( array( $c3 ), $comment_ids );
    18791879    }
    18801880
     
    19191919        );
    19201920
    1921         $this->assertEqualSets( array( $c1, $c2 ), $comment_ids );
     1921        $this->assertSameSets( array( $c1, $c2 ), $comment_ids );
    19221922    }
    19231923
     
    19621962        );
    19631963
    1964         $this->assertEqualSets( array( $c3 ), $comment_ids );
     1964        $this->assertSameSets( array( $c3 ), $comment_ids );
    19651965    }
    19661966
     
    20102010        );
    20112011
    2012         $this->assertEqualSets( array( $c1, $c3 ), $comment_ids );
     2012        $this->assertSameSets( array( $c1, $c3 ), $comment_ids );
    20132013    }
    20142014
     
    20582058        );
    20592059
    2060         $this->assertEqualSets( array( $c3, $c4 ), $comment_ids );
     2060        $this->assertSameSets( array( $c3, $c4 ), $comment_ids );
    20612061    }
    20622062
     
    20892089
    20902090        $comment_ids = get_comments( array( 'fields' => 'ids' ) );
    2091         $this->assertEqualSets( array( $comment_1, $comment_2, $comment_3 ), $comment_ids );
     2091        $this->assertSameSets( array( $comment_1, $comment_2, $comment_3 ), $comment_ids );
    20922092    }
    20932093
     
    21332133        );
    21342134
    2135         $this->assertEqualSets( array( $c1, $c2, $c3 ), $found );
     2135        $this->assertSameSets( array( $c1, $c2, $c3 ), $found );
    21362136    }
    21372137
     
    21842184        );
    21852185
    2186         $this->assertEqualSets( array( $c1, $c2, $c3, $c5 ), $found );
     2186        $this->assertSameSets( array( $c1, $c2, $c3, $c5 ), $found );
    21872187    }
    21882188
     
    22352235        );
    22362236
    2237         $this->assertEqualSets( array( $c1, $c2, $c3, $c5 ), $found );
     2237        $this->assertSameSets( array( $c1, $c2, $c3, $c5 ), $found );
    22382238    }
    22392239
     
    22852285        );
    22862286
    2287         $this->assertEqualSets( array( $c1, $c2, $c3 ), $found );
     2287        $this->assertSameSets( array( $c1, $c2, $c3 ), $found );
    22882288    }
    22892289
     
    23442344        );
    23452345
    2346         $this->assertEqualSets( array( $c1, $c2, $c3, $c5 ), $found );
     2346        $this->assertSameSets( array( $c1, $c2, $c3, $c5 ), $found );
    23472347    }
    23482348
     
    24032403        );
    24042404
    2405         $this->assertEqualSets( array( $c1, $c2, $c3, $c5 ), $found );
     2405        $this->assertSameSets( array( $c1, $c2, $c3, $c5 ), $found );
    24062406    }
    24072407
     
    24762476        );
    24772477
    2478         $this->assertEqualSets( array( $c1, $c2, $c3, $c4, $c5 ), $found );
     2478        $this->assertSameSets( array( $c1, $c2, $c3, $c4, $c5 ), $found );
    24792479    }
    24802480
     
    30563056        );
    30573057
    3058         $this->assertEqualSets( $c2, $found );
     3058        $this->assertSameSets( $c2, $found );
    30593059
    30603060        _unregister_post_type( 'post-type-1' );
     
    30833083        );
    30843084
    3085         $this->assertEqualSets( $c2, $found );
     3085        $this->assertSameSets( $c2, $found );
    30863086
    30873087        _unregister_post_type( 'post-type-1' );
     
    31133113        );
    31143114
    3115         $this->assertEqualSets( array_merge( $c1, $c3 ), $found );
     3115        $this->assertSameSets( array_merge( $c1, $c3 ), $found );
    31163116    }
    31173117
     
    31313131        );
    31323132
    3133         $this->assertEqualSets( $c2, $found );
     3133        $this->assertSameSets( $c2, $found );
    31343134    }
    31353135
     
    31523152        );
    31533153
    3154         $this->assertEqualSets( $c2, $found );
     3154        $this->assertSameSets( $c2, $found );
    31553155    }
    31563156
     
    31753175        );
    31763176
    3177         $this->assertEqualSets( array_merge( $c1, $c3 ), $found );
     3177        $this->assertSameSets( array_merge( $c1, $c3 ), $found );
    31783178    }
    31793179
     
    31933193        );
    31943194
    3195         $this->assertEqualSets( $c2, $found );
     3195        $this->assertSameSets( $c2, $found );
    31963196    }
    31973197
     
    32143214        );
    32153215
    3216         $this->assertEqualSets( $c2, $found );
     3216        $this->assertSameSets( $c2, $found );
    32173217    }
    32183218
     
    32373237        );
    32383238
    3239         $this->assertEqualSets( array_merge( $c1, $c3 ), $found );
     3239        $this->assertSameSets( array_merge( $c1, $c3 ), $found );
    32403240    }
    32413241
     
    32603260            )
    32613261        );
    3262         $this->assertEqualSets( array_merge( $c1, $c2 ), $found );
     3262        $this->assertSameSets( array_merge( $c1, $c2 ), $found );
    32633263    }
    32643264
     
    32833283            )
    32843284        );
    3285         $this->assertEqualSets( array_merge( $c1, $c2 ), $found );
     3285        $this->assertSameSets( array_merge( $c1, $c2 ), $found );
    32863286    }
    32873287
     
    33033303            )
    33043304        );
    3305         $this->assertEqualSets( array_merge( $c1, $c2 ), $found );
     3305        $this->assertSameSets( array_merge( $c1, $c2 ), $found );
    33063306    }
    33073307
     
    33233323            )
    33243324        );
    3325         $this->assertEqualSets( array_merge( $c1, $c2 ), $found );
     3325        $this->assertSameSets( array_merge( $c1, $c2 ), $found );
    33263326    }
    33273327
     
    34473447        remove_action( 'pre_get_comments', array( $this, 'modify_meta_query' ) );
    34483448
    3449         $this->assertEqualSets( array( $comments[1] ), $q->comments );
     3449        $this->assertSameSets( array( $comments[1] ), $q->comments );
    34503450    }
    34513451
     
    34853485        remove_action( 'pre_get_comments', array( $this, 'modify_meta_params' ) );
    34863486
    3487         $this->assertEqualSets( array( $comments[1] ), $q->comments );
     3487        $this->assertSameSets( array( $comments[1] ), $q->comments );
    34883488    }
    34893489
     
    35193519        );
    35203520
    3521         $this->assertEqualSets( array( $c2 ), $ids->comments );
     3521        $this->assertSameSets( array( $c2 ), $ids->comments );
    35223522    }
    35233523
     
    35613561        );
    35623562
    3563         $this->assertEqualSets( array( $c3, $c4 ), $ids->comments );
     3563        $this->assertSameSets( array( $c3, $c4 ), $ids->comments );
    35643564    }
    35653565
     
    35913591        );
    35923592
    3593         $this->assertEqualSets( array( $c1 ), $ids->comments );
     3593        $this->assertSameSets( array( $c1 ), $ids->comments );
    35943594    }
    35953595
     
    36343634        );
    36353635
    3636         $this->assertEqualSets( array( $c1, $c2 ), $ids->comments );
     3636        $this->assertSameSets( array( $c1, $c2 ), $ids->comments );
    36373637    }
    36383638
     
    41624162        $q2_ids      = wp_list_pluck( $q2->comments, 'comment_ID' );
    41634163
    4164         $this->assertEqualSets( $q1_ids, $q2_ids );
     4164        $this->assertSameSets( $q1_ids, $q2_ids );
    41654165        $this->assertSame( $num_queries, $wpdb->num_queries );
    41664166    }
     
    42244224        );
    42254225        $q2_ids = wp_list_pluck( $q2->comments, 'comment_ID' );
    4226         $this->assertEqualSets( $q1_ids, $q2_ids );
     4226        $this->assertSameSets( $q1_ids, $q2_ids );
    42274227    }
    42284228
     
    42884288        $found_1    = $found[ $c1 ];
    42894289        $children_1 = $found_1->get_children();
    4290         $this->assertEqualSets( array( $c2 ), array_keys( $children_1 ) );
     4290        $this->assertSameSets( array( $c2 ), array_keys( $children_1 ) );
    42914291
    42924292        $found_3    = $found[ $c3 ];
    42934293        $children_3 = $found_3->get_children();
    4294         $this->assertEqualSets( array( $c4, $c5 ), array_keys( $children_3 ) );
     4294        $this->assertSameSets( array( $c4, $c5 ), array_keys( $children_3 ) );
    42954295    }
    42964296
     
    44424442
    44434443        $this->assertSame( $num_queries, $wpdb->num_queries );
    4444         $this->assertEqualSets( array( $c ), $q->comments );
     4444        $this->assertSameSets( array( $c ), $q->comments );
    44454445    }
    44464446
     
    44824482        $num_queries++;
    44834483        $this->assertSame( $num_queries, $wpdb->num_queries );
    4484         $this->assertEqualSets( array( $c ), $q->comments );
     4484        $this->assertSameSets( array( $c ), $q->comments );
    44854485    }
    44864486
     
    45154515        $num_queries++;
    45164516        $this->assertSame( $num_queries, $wpdb->num_queries );
    4517         $this->assertEqualSets( array(), $q->comments );
     4517        $this->assertSameSets( array(), $q->comments );
    45184518    }
    45194519
     
    45484548        $num_queries++;
    45494549        $this->assertSame( $num_queries, $wpdb->num_queries );
    4550         $this->assertEqualSets( array(), $q->comments );
     4550        $this->assertSameSets( array(), $q->comments );
    45514551    }
    45524552
     
    45834583        $num_queries++;
    45844584        $this->assertSame( $num_queries, $wpdb->num_queries );
    4585         $this->assertEqualSets( array( $c ), $q->comments );
     4585        $this->assertSameSets( array( $c ), $q->comments );
    45864586    }
    45874587
     
    46164616        $num_queries++;
    46174617        $this->assertSame( $num_queries, $wpdb->num_queries );
    4618         $this->assertEqualSets( array(), $q->comments );
     4618        $this->assertSameSets( array(), $q->comments );
    46194619    }
    46204620
     
    46514651        $num_queries++;
    46524652        $this->assertSame( $num_queries, $wpdb->num_queries );
    4653         $this->assertEqualSets( array( $c ), $q->comments );
     4653        $this->assertSameSets( array( $c ), $q->comments );
    46544654    }
    46554655
     
    47674767        );
    47684768
    4769         $this->assertEqualSets( $c1, $cached );
     4769        $this->assertSameSets( $c1, $cached );
    47704770
    47714771        foreach ( $c2 as $cid ) {
     
    47864786        );
    47874787
    4788         $this->assertEqualSets( array_merge( $c1, $c2 ), $found );
     4788        $this->assertSameSets( array_merge( $c1, $c2 ), $found );
    47894789    }
    47904790
     
    48164816        );
    48174817
    4818         $this->assertEqualSets( array_merge( $c1, $c2 ), $cached );
     4818        $this->assertSameSets( array_merge( $c1, $c2 ), $cached );
    48194819
    48204820        foreach ( $c2 as $cid ) {
     
    48354835        );
    48364836
    4837         $this->assertEqualSets( $c1, $found );
     4837        $this->assertSameSets( $c1, $found );
    48384838    }
    48394839
     
    48654865        );
    48664866
    4867         $this->assertEqualSets( array_merge( $c1, $c2 ), $cached );
     4867        $this->assertSameSets( array_merge( $c1, $c2 ), $cached );
    48684868
    48694869        foreach ( $c2 as $cid ) {
     
    48844884        );
    48854885
    4886         $this->assertEqualSets( $c1, $found );
     4886        $this->assertSameSets( $c1, $found );
    48874887    }
    48884888
Note: See TracChangeset for help on using the changeset viewer.