Make WordPress Core


Ignore:
Timestamp:
09/04/2020 07:01:00 AM (4 years 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/term/getTerms.php

    r48937 r48939  
    3434        );
    3535
    36         $this->assertEqualSets( array( $term1 ), wp_list_pluck( $found, 'term_id' ) );
     36        $this->assertSameSets( array( $term1 ), wp_list_pluck( $found, 'term_id' ) );
    3737    }
    3838
     
    5353        );
    5454
    55         $this->assertEqualSets( array( $term ), $found );
     55        $this->assertSameSets( array( $term ), $found );
    5656    }
    5757
     
    6666        $found = get_terms( 'wptests_tax', 'hide_empty=0&fields=ids&update_term_meta_cache=0' );
    6767
    68         $this->assertEqualSets( array( $term ), $found );
     68        $this->assertSameSets( array( $term ), $found );
    6969    }
    7070
     
    7979        $found = get_terms( 'taxonomy=wptests_tax&hide_empty=0&fields=ids&update_term_meta_cache=0' );
    8080
    81         $this->assertEqualSets( array( $term ), $found );
     81        $this->assertSameSets( array( $term ), $found );
    8282    }
    8383
     
    244244            )
    245245        );
    246         $this->assertEqualSets( array( $term_id1, $term_id2 ), $terms_ids );
     246        $this->assertSameSets( array( $term_id1, $term_id2 ), $terms_ids );
    247247
    248248        $terms_name = get_terms(
     
    253253            )
    254254        );
    255         $this->assertEqualSets( array( 'WOO!', 'HOO!' ), $terms_name );
     255        $this->assertSameSets( array( 'WOO!', 'HOO!' ), $terms_name );
    256256
    257257        $terms_id_name = get_terms(
     
    420420            )
    421421        );
    422         $this->assertEqualSets( array( $term_id1, $term_id2 ), $terms );
     422        $this->assertSameSets( array( $term_id1, $term_id2 ), $terms );
    423423    }
    424424
     
    448448            )
    449449        );
    450         $this->assertEqualSets( array( $term_id1 ), $terms );
     450        $this->assertSameSets( array( $term_id1 ), $terms );
    451451
    452452        $terms2 = get_terms(
     
    458458            )
    459459        );
    460         $this->assertEqualSets( array( $term_id1, $term_id2 ), $terms2 );
     460        $this->assertSameSets( array( $term_id1, $term_id2 ), $terms2 );
    461461
    462462        $terms3 = get_terms(
     
    468468            )
    469469        );
    470         $this->assertEqualSets( array( $term_id1 ), $terms3 );
     470        $this->assertSameSets( array( $term_id1 ), $terms3 );
    471471
    472472        $terms4 = get_terms(
     
    478478            )
    479479        );
    480         $this->assertEqualSets( array( $term_id1, $term_id2 ), $terms4 );
     480        $this->assertSameSets( array( $term_id1, $term_id2 ), $terms4 );
    481481
    482482        $terms5 = get_terms(
     
    508508            )
    509509        );
    510         $this->assertEqualSets( array( $term_id1, $term_id2 ), $terms7 );
     510        $this->assertSameSets( array( $term_id1, $term_id2 ), $terms7 );
    511511
    512512        $terms8 = get_terms(
     
    518518            )
    519519        );
    520         $this->assertEqualSets( array( $term_id1, $term_id2 ), $terms8 );
     520        $this->assertSameSets( array( $term_id1, $term_id2 ), $terms8 );
    521521    }
    522522
     
    846846        );
    847847
    848         $this->assertEqualSets( array( $t3 ), $found );
     848        $this->assertSameSets( array( $t3 ), $found );
    849849    }
    850850
     
    883883        $result = _get_term_children( $c1, array( $c1, $c2, $c3 ), 'category' );
    884884
    885         $this->assertEqualSets( array( $c2, $c3 ), $result );
     885        $this->assertSameSets( array( $c2, $c3 ), $result );
    886886    }
    887887
     
    902902        $result = _get_term_children( $c1->term_id, array( $c1, $c2, $c3 ), 'category' );
    903903
    904         $this->assertEqualSets( array( $c2, $c3 ), $result );
     904        $this->assertSameSets( array( $c2, $c3 ), $result );
    905905    }
    906906
     
    977977        );
    978978
    979         $this->assertEqualSets( array( $t3, $t1 ), $found );
     979        $this->assertSameSets( array( $t3, $t1 ), $found );
    980980    }
    981981
     
    10021002            )
    10031003        );
    1004         $this->assertEqualSets( array( $t ), $found );
     1004        $this->assertSameSets( array( $t ), $found );
    10051005
    10061006        // Array format.
     
    10131013            )
    10141014        );
    1015         $this->assertEqualSets( array( $t ), $found );
     1015        $this->assertSameSets( array( $t ), $found );
    10161016    }
    10171017
     
    10441044        );
    10451045
    1046         $this->assertEqualSets( array( $t ), $found );
     1046        $this->assertSameSets( array( $t ), $found );
    10471047    }
    10481048
     
    10831083
    10841084        $expected = array( $australia, $china, $tanzania );
    1085         $this->assertEqualSets( $expected, $terms );
     1085        $this->assertSameSets( $expected, $terms );
    10861086    }
    10871087
     
    11751175        );
    11761176
    1177         $this->assertEqualSets( array( $montreal, $nepean, $toronto, $pei ), $terms );
     1177        $this->assertSameSets( array( $montreal, $nepean, $toronto, $pei ), $terms );
    11781178    }
    11791179
     
    12441244        );
    12451245
    1246         $this->assertEqualSets( array( $laval ), $terms );
     1246        $this->assertSameSets( array( $laval ), $terms );
    12471247    }
    12481248
     
    12781278        );
    12791279
    1280         $this->assertEqualSets( array( $t2, $t4 ), $found );
     1280        $this->assertSameSets( array( $t2, $t4 ), $found );
    12811281    }
    12821282
     
    13061306        _unregister_taxonomy( 'hierarchical_fields' );
    13071307
    1308         $this->assertEqualSets( $expected, $found );
     1308        $this->assertSameSets( $expected, $found );
    13091309    }
    13101310
     
    13321332        _unregister_taxonomy( 'hierarchical_fields' );
    13331333
    1334         $this->assertEqualSets( $expected, $found );
     1334        $this->assertSameSets( $expected, $found );
    13351335    }
    13361336
     
    13581358        _unregister_taxonomy( 'hierarchical_fields' );
    13591359
    1360         $this->assertEqualSets( $expected, $found );
     1360        $this->assertSameSets( $expected, $found );
    13611361    }
    13621362
     
    13861386        _unregister_taxonomy( 'hierarchical_fields' );
    13871387
    1388         $this->assertEqualSets( $expected, $found );
     1388        $this->assertSameSets( $expected, $found );
    13891389    }
    13901390
     
    14121412        _unregister_taxonomy( 'hierarchical_fields' );
    14131413
    1414         $this->assertEqualSets( $expected, $found );
     1414        $this->assertSameSets( $expected, $found );
    14151415    }
    14161416
     
    14381438        _unregister_taxonomy( 'hierarchical_fields' );
    14391439
    1440         $this->assertEqualSets( $expected, $found );
     1440        $this->assertSameSets( $expected, $found );
    14411441    }
    14421442
     
    16081608        _unregister_taxonomy( 'hierarchical_fields' );
    16091609
    1610         $this->assertEqualSetsWithIndex( $expected, $found );
     1610        $this->assertSameSetsWithIndex( $expected, $found );
    16111611    }
    16121612
     
    16371637        _unregister_taxonomy( 'hierarchical_fields' );
    16381638
    1639         $this->assertEqualSetsWithIndex( $expected, $found );
     1639        $this->assertSameSetsWithIndex( $expected, $found );
    16401640    }
    16411641
     
    16631663        _unregister_taxonomy( 'hierarchical_fields' );
    16641664
    1665         $this->assertEqualSetsWithIndex( $expected, $found );
     1665        $this->assertSameSetsWithIndex( $expected, $found );
    16661666    }
    16671667
     
    16911691        _unregister_taxonomy( 'hierarchical_fields' );
    16921692
    1693         $this->assertEqualSetsWithIndex( $expected, $found );
     1693        $this->assertSameSetsWithIndex( $expected, $found );
    16941694    }
    16951695
     
    17201720        _unregister_taxonomy( 'hierarchical_fields' );
    17211721
    1722         $this->assertEqualSetsWithIndex( $expected, $found );
     1722        $this->assertSameSetsWithIndex( $expected, $found );
    17231723    }
    17241724
     
    17461746        _unregister_taxonomy( 'hierarchical_fields' );
    17471747
    1748         $this->assertEqualSetsWithIndex( $expected, $found );
     1748        $this->assertSameSetsWithIndex( $expected, $found );
    17491749    }
    17501750
     
    19581958        );
    19591959
    1960         $this->assertEqualSets( array( $terms[1], $terms[2], $terms[0] ), $found );
     1960        $this->assertSameSets( array( $terms[1], $terms[2], $terms[0] ), $found );
    19611961    }
    19621962
     
    19961996        );
    19971997
    1998         $this->assertEqualSets( array( $terms[1], $terms[2], $terms[0] ), $found );
     1998        $this->assertSameSets( array( $terms[1], $terms[2], $terms[0] ), $found );
    19991999    }
    20002000
     
    20262026        );
    20272027
    2028         $this->assertEqualSets( array( $terms[1], $terms[2], $terms[0] ), $found );
     2028        $this->assertSameSets( array( $terms[1], $terms[2], $terms[0] ), $found );
    20292029
    20302030        $found = get_terms(
     
    20452045        );
    20462046
    2047         $this->assertEqualSets( array( $terms[1], $terms[2], $terms[0] ), $found );
     2047        $this->assertSameSets( array( $terms[1], $terms[2], $terms[0] ), $found );
    20482048
    20492049        // Matches the first meta query clause.
     
    20702070        );
    20712071
    2072         $this->assertEqualSets( array( $terms[1], $terms[2], $terms[0] ), $found );
     2072        $this->assertSameSets( array( $terms[1], $terms[2], $terms[0] ), $found );
    20732073
    20742074        // Matches the meta query clause corresponding to the 'meta_key' param.
     
    20952095        );
    20962096
    2097         $this->assertEqualSets( array( $terms[1], $terms[0], $terms[2] ), $found );
     2097        $this->assertSameSets( array( $terms[1], $terms[0], $terms[2] ), $found );
    20982098    }
    20992099
     
    21252125        );
    21262126
    2127         $this->assertEqualSets( array( $terms[1], $terms[2], $terms[0] ), $found );
     2127        $this->assertSameSets( array( $terms[1], $terms[2], $terms[0] ), $found );
    21282128
    21292129        $found = get_terms(
     
    21442144        );
    21452145
    2146         $this->assertEqualSets( array( $terms[1], $terms[2], $terms[0] ), $found );
     2146        $this->assertSameSets( array( $terms[1], $terms[2], $terms[0] ), $found );
    21472147
    21482148        $found = get_terms(
     
    21682168        );
    21692169
    2170         $this->assertEqualSets( array( $terms[1], $terms[2], $terms[0] ), $found );
     2170        $this->assertSameSets( array( $terms[1], $terms[2], $terms[0] ), $found );
    21712171
    21722172        $found = get_terms(
     
    21922192        );
    21932193
    2194         $this->assertEqualSets( array( $terms[1], $terms[0], $terms[2] ), $found );
     2194        $this->assertSameSets( array( $terms[1], $terms[0], $terms[2] ), $found );
    21952195    }
    21962196
     
    22292229        );
    22302230
    2231         $this->assertEqualSets( array( $terms[1], $terms[2], $terms[0] ), $found );
     2231        $this->assertSameSets( array( $terms[1], $terms[2], $terms[0] ), $found );
    22322232
    22332233        $found = get_terms(
     
    22522252        );
    22532253
    2254         $this->assertEqualSets( array( $terms[1], $terms[0], $terms[2] ), $found );
     2254        $this->assertSameSets( array( $terms[1], $terms[0], $terms[2] ), $found );
    22552255
    22562256        $expected = get_terms(
     
    22932293        );
    22942294
    2295         $this->assertEqualSets( $expected, $found );
     2295        $this->assertSameSets( $expected, $found );
    22962296    }
    22972297
     
    23332333        );
    23342334        $actual   = wp_list_pluck( $terms, 'term_id' );
    2335         $this->assertEqualSets( $expected, $actual );
     2335        $this->assertSameSets( $expected, $actual );
    23362336    }
    23372337
     
    23592359
    23602360        $actual = wp_list_pluck( $terms, 'term_id' );
    2361         $this->assertEqualSets( $expected, $actual );
     2361        $this->assertSameSets( $expected, $actual );
    23622362    }
    23632363
     
    23972397        );
    23982398        $actual   = wp_list_pluck( $terms, 'term_id' );
    2399         $this->assertEqualSets( $expected, $actual );
     2399        $this->assertSameSets( $expected, $actual );
    24002400    }
    24012401
     
    24192419        );
    24202420        $actual   = wp_list_pluck( $terms, 'term_id' );
    2421         $this->assertEqualSets( $expected, $actual );
     2421        $this->assertSameSets( $expected, $actual );
    24222422    }
    24232423
     
    24712471        );
    24722472
    2473         $this->assertEqualSets( array( $t3 ), $found );
     2473        $this->assertSameSets( array( $t3 ), $found );
    24742474    }
    24752475
     
    25132513        );
    25142514        $actual   = wp_list_pluck( $terms, 'term_id' );
    2515         $this->assertEqualSets( $expected, $actual );
     2515        $this->assertSameSets( $expected, $actual );
    25162516    }
    25172517
     
    25502550        );
    25512551
    2552         $this->assertEqualSets( array( $t1, $t2, $t3 ), wp_list_pluck( $found, 'term_id' ) );
     2552        $this->assertSameSets( array( $t1, $t2, $t3 ), wp_list_pluck( $found, 'term_id' ) );
    25532553
    25542554        foreach ( $found as $f ) {
     
    25882588        );
    25892589
    2590         $this->assertEqualSets( array( $c1, $c2, $c3 ), wp_list_pluck( $terms, 'term_id' ) );
     2590        $this->assertSameSets( array( $c1, $c2, $c3 ), wp_list_pluck( $terms, 'term_id' ) );
    25912591
    25922592        foreach ( $terms as $term ) {
     
    26232623        );
    26242624
    2625         $this->assertEqualSets( array( $t1, $t2, $t3 ), wp_list_pluck( $found, 'term_id' ) );
     2625        $this->assertSameSets( array( $t1, $t2, $t3 ), wp_list_pluck( $found, 'term_id' ) );
    26262626
    26272627        foreach ( $found as $f ) {
     
    27202720        );
    27212721
    2722         $this->assertEqualSets( array( $terms[0], $terms[1] ), $found );
     2722        $this->assertSameSets( array( $terms[0], $terms[1] ), $found );
    27232723    }
    27242724
     
    27472747        );
    27482748
    2749         $this->assertEqualSets( array( $terms[0] ), $found );
     2749        $this->assertSameSets( array( $terms[0] ), $found );
    27502750    }
    27512751
     
    28722872            )
    28732873        );
    2874         $this->assertEqualSets( $terms, $found );
     2874        $this->assertSameSets( $terms, $found );
    28752875    }
    28762876
     
    28942894            )
    28952895        );
    2896         $this->assertEqualSets( array( $terms[1] ), $found );
     2896        $this->assertSameSets( array( $terms[1] ), $found );
    28972897    }
    28982898
     
    29162916            )
    29172917        );
    2918         $this->assertEqualSets( array( $terms[1] ), $found );
     2918        $this->assertSameSets( array( $terms[1] ), $found );
    29192919    }
    29202920
     
    29382938            )
    29392939        );
    2940         $this->assertEqualSets( array(), $found );
     2940        $this->assertSameSets( array(), $found );
    29412941    }
    29422942
     
    29862986        );
    29872987
    2988         $this->assertEqualSets( array( $term_id ), wp_list_pluck( $found, 'term_id' ) );
     2988        $this->assertSameSets( array( $term_id ), wp_list_pluck( $found, 'term_id' ) );
    29892989    }
    29902990
     
    30223022        );
    30233023
    3024         $this->assertEqualSets( array( $term_id1, $term_id2 ), wp_list_pluck( $found, 'term_id' ) );
     3024        $this->assertSameSets( array( $term_id1, $term_id2 ), wp_list_pluck( $found, 'term_id' ) );
    30253025    }
    30263026
Note: See TracChangeset for help on using the changeset viewer.