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/query/metaQuery.php

    r48937 r48939  
    2929
    3030        $expected = array( $p1, $p2 );
    31         $this->assertEqualSets( $expected, $query->posts );
     31        $this->assertSameSets( $expected, $query->posts );
    3232    }
    3333
     
    5555
    5656        $expected = array( $p2, $p3 );
    57         $this->assertEqualSets( $expected, $query->posts );
     57        $this->assertSameSets( $expected, $query->posts );
    5858    }
    5959
     
    7979
    8080        $expected = array( $p1 );
    81         $this->assertEqualSets( $expected, $query->posts );
     81        $this->assertSameSets( $expected, $query->posts );
    8282    }
    8383
     
    104104
    105105        $expected = array( $p1 );
    106         $this->assertEqualSets( $expected, $query->posts );
     106        $this->assertSameSets( $expected, $query->posts );
    107107    }
    108108
     
    131131
    132132        $expected = array( $p2 );
    133         $this->assertEqualSets( $expected, $query->posts );
     133        $this->assertSameSets( $expected, $query->posts );
    134134    }
    135135
     
    160160
    161161        $expected = array( $p1 );
    162         $this->assertEqualSets( $expected, $query->posts );
     162        $this->assertSameSets( $expected, $query->posts );
    163163
    164164        // <=
     
    179179
    180180        $expected = array( $p1, $p2 );
    181         $this->assertEqualSets( $expected, $query->posts );
     181        $this->assertSameSets( $expected, $query->posts );
    182182
    183183        // >=
     
    198198
    199199        $expected = array( $p2, $p3 );
    200         $this->assertEqualSets( $expected, $query->posts );
     200        $this->assertSameSets( $expected, $query->posts );
    201201
    202202        // >
     
    217217
    218218        $expected = array( $p3 );
    219         $this->assertEqualSets( $expected, $query->posts );
     219        $this->assertSameSets( $expected, $query->posts );
    220220    }
    221221
     
    242242
    243243        $expected = array( $p1 );
    244         $this->assertEqualSets( $expected, $query->posts );
     244        $this->assertSameSets( $expected, $query->posts );
    245245    }
    246246
     
    269269
    270270        $expected = array( $p2 );
    271         $this->assertEqualSets( $expected, $query->posts );
     271        $this->assertSameSets( $expected, $query->posts );
    272272    }
    273273
     
    298298
    299299        $expected = array( $p2 );
    300         $this->assertEqualSets( $expected, $query->posts );
     300        $this->assertSameSets( $expected, $query->posts );
    301301
    302302        $query = new WP_Query(
     
    317317
    318318        $expected = array( $p1, $p3 );
    319         $this->assertEqualSets( $expected, $query->posts );
     319        $this->assertSameSets( $expected, $query->posts );
    320320    }
    321321
     
    343343
    344344        $expected = array( $p2 );
    345         $this->assertEqualSets( $expected, $query->posts );
     345        $this->assertSameSets( $expected, $query->posts );
    346346
    347347        // RLIKE is a synonym for REGEXP.
     
    362362
    363363        $expected = array( $p2 );
    364         $this->assertEqualSets( $expected, $query->posts );
     364        $this->assertSameSets( $expected, $query->posts );
    365365    }
    366366
     
    388388
    389389        $expected = array( $p1 );
    390         $this->assertEqualSets( $expected, $query->posts );
     390        $this->assertSameSets( $expected, $query->posts );
    391391    }
    392392
     
    468468
    469469        $expected = array( $post_id, $post_id2, $post_id3, $post_id4 );
    470         $this->assertEqualSets( $expected, $query->posts );
     470        $this->assertSameSets( $expected, $query->posts );
    471471    }
    472472
     
    524524
    525525        $expected = array( $post_id7 );
    526         $this->assertEqualSets( $expected, $query->posts );
     526        $this->assertSameSets( $expected, $query->posts );
    527527
    528528        $query = new WP_Query(
     
    544544
    545545        $expected = array( $post_id2, $post_id6, $post_id7 );
    546         $this->assertEqualSets( $expected, $query->posts );
     546        $this->assertSameSets( $expected, $query->posts );
    547547    }
    548548
     
    567567        );
    568568
    569         $this->assertEqualSets( array( $posts[0], $posts[2] ), $query->posts );
     569        $this->assertSameSets( array( $posts[0], $posts[2] ), $query->posts );
    570570    }
    571571
     
    591591        );
    592592
    593         $this->assertEqualSets( array( $posts[2] ), $query->posts );
     593        $this->assertSameSets( array( $posts[2] ), $query->posts );
    594594    }
    595595
     
    615615        );
    616616
    617         $this->assertEqualSets( array( $posts[1] ), $query->posts );
     617        $this->assertSameSets( array( $posts[1] ), $query->posts );
    618618    }
    619619
     
    652652
    653653        $expected = array( $post_id2, $post_id3, $post_id4 );
    654         $this->assertEqualSets( $expected, $query->posts );
     654        $this->assertSameSets( $expected, $query->posts );
    655655
    656656        $query = new WP_Query(
     
    735735
    736736        $expected = array( $posts[1], $posts[2], $posts[3] );
    737         $this->assertEqualSets( $expected, $query->posts );
     737        $this->assertSameSets( $expected, $query->posts );
    738738    }
    739739
     
    770770
    771771        $expected = array( $posts[1], $posts[2] );
    772         $this->assertEqualSets( $expected, $query->posts );
     772        $this->assertSameSets( $expected, $query->posts );
    773773    }
    774774
     
    805805
    806806        $expected = array( $posts[0], $posts[1] );
    807         $this->assertEqualSets( $expected, $query->posts );
     807        $this->assertSameSets( $expected, $query->posts );
    808808    }
    809809
     
    840840
    841841        $expected = array( $posts[0], $posts[1] );
    842         $this->assertEqualSets( $expected, $query->posts );
     842        $this->assertSameSets( $expected, $query->posts );
    843843    }
    844844
     
    875875
    876876        $expected = array( $posts[1], $posts[2] );
    877         $this->assertEqualSets( $expected, $query->posts );
     877        $this->assertSameSets( $expected, $query->posts );
    878878    }
    879879
     
    911911
    912912        $expected = array( $posts[0], $posts[2] );
    913         $this->assertEqualSets( $expected, $query->posts );
     913        $this->assertSameSets( $expected, $query->posts );
    914914    }
    915915
     
    948948
    949949        $expected = array( $posts[3] );
    950         $this->assertEqualSets( $expected, $query->posts );
     950        $this->assertSameSets( $expected, $query->posts );
    951951    }
    952952
     
    985985
    986986        $expected = array( $posts[1] );
    987         $this->assertEqualSets( $expected, $query->posts );
     987        $this->assertSameSets( $expected, $query->posts );
    988988    }
    989989
     
    10211021
    10221022        $expected = array( $posts[3] );
    1023         $this->assertEqualSets( $expected, $query->posts );
     1023        $this->assertSameSets( $expected, $query->posts );
    10241024    }
    10251025
     
    10641064
    10651065        $expected = array( $posts[2] );
    1066         $this->assertEqualSets( $expected, $query->posts );
     1066        $this->assertSameSets( $expected, $query->posts );
    10671067    }
    10681068
     
    11001100
    11011101        $expected = array( $posts[3] );
    1102         $this->assertEqualSets( $expected, $query->posts );
     1102        $this->assertSameSets( $expected, $query->posts );
    11031103    }
    11041104
     
    11361136
    11371137        $expected = array( $posts[3] );
    1138         $this->assertEqualSets( $expected, $query->posts );
     1138        $this->assertSameSets( $expected, $query->posts );
    11391139    }
    11401140
     
    11681168            )
    11691169        );
    1170         $this->assertEqualSets( array( $post_3 ), $query->posts );
     1170        $this->assertSameSets( array( $post_3 ), $query->posts );
    11711171
    11721172        $query = new WP_Query(
     
    11851185            )
    11861186        );
    1187         $this->assertEqualSets( array( $post_4 ), $query->posts );
     1187        $this->assertSameSets( array( $post_4 ), $query->posts );
    11881188
    11891189        $query = new WP_Query(
     
    12021202            )
    12031203        );
    1204         $this->assertEqualSets( array( $post_3, $post_4 ), $query->posts );
     1204        $this->assertSameSets( array( $post_3, $post_4 ), $query->posts );
    12051205
    12061206        $query = new WP_Query(
     
    12191219            )
    12201220        );
    1221         $this->assertEqualSets( array( $post_1 ), $query->posts, 'ID' );
     1221        $this->assertSameSets( array( $post_1 ), $query->posts, 'ID' );
    12221222
    12231223        $query = new WP_Query(
     
    12361236            )
    12371237        );
    1238         $this->assertEqualSets( array( $post_1, $post_2, $post_3 ), $query->posts );
     1238        $this->assertSameSets( array( $post_1, $post_2, $post_3 ), $query->posts );
    12391239
    12401240        $query = new WP_Query(
     
    12531253            )
    12541254        );
    1255         $this->assertEqualSets( array( $post_3 ), $query->posts );
     1255        $this->assertSameSets( array( $post_3 ), $query->posts );
    12561256
    12571257        $query = new WP_Query(
     
    12701270            )
    12711271        );
    1272         $this->assertEqualSets( array( $post_1, $post_2, $post_4 ), $query->posts );
     1272        $this->assertSameSets( array( $post_1, $post_2, $post_4 ), $query->posts );
    12731273
    12741274        $query = new WP_Query(
     
    12871287            )
    12881288        );
    1289         $this->assertEqualSets( array( $post_1, $post_3 ), $query->posts );
     1289        $this->assertSameSets( array( $post_1, $post_3 ), $query->posts );
    12901290
    12911291        $query = new WP_Query(
     
    13041304            )
    13051305        );
    1306         $this->assertEqualSets( array( $post_2, $post_4 ), $query->posts );
     1306        $this->assertSameSets( array( $post_2, $post_4 ), $query->posts );
    13071307
    13081308        $query = new WP_Query(
     
    13171317            )
    13181318        );
    1319         $this->assertEqualSets( array( $post_4, $post_3, $post_2, $post_1 ), $query->posts );
     1319        $this->assertSameSets( array( $post_4, $post_3, $post_2, $post_1 ), $query->posts );
    13201320    }
    13211321
     
    14621462
    14631463        $expected = array( $p1, $p3 );
    1464         $this->assertEqualSets( $expected, $query->posts );
     1464        $this->assertSameSets( $expected, $query->posts );
    14651465    }
    14661466
     
    15121512
    15131513        $expected = array( $p1, $p3 );
    1514         $this->assertEqualSets( $expected, $query->posts );
     1514        $this->assertSameSets( $expected, $query->posts );
    15151515    }
    15161516
     
    15411541        }
    15421542        $posts = wp_list_pluck( $query->posts, 'ID' );
    1543         $this->assertEqualSets( array( $post_id2, $post_id3 ), $posts );
     1543        $this->assertSameSets( array( $post_id2, $post_id3 ), $posts );
    15441544
    15451545        $args = array(
     
    15571557        }
    15581558        $posts = wp_list_pluck( $query->posts, 'ID' );
    1559         $this->assertEqualSets( array( $post_id, $post_id4, $post_id5 ), $posts );
     1559        $this->assertSameSets( array( $post_id, $post_id4, $post_id5 ), $posts );
    15601560    }
    15611561
     
    15851585        $this->assertSame( 2, count( $posts ) );
    15861586        $posts = wp_list_pluck( $posts, 'ID' );
    1587         $this->assertEqualSets( array( $post_id, $post_id3 ), $posts );
     1587        $this->assertSameSets( array( $post_id, $post_id3 ), $posts );
    15881588
    15891589        $posts = get_posts(
     
    16011601        }
    16021602        $posts = wp_list_pluck( $posts, 'ID' );
    1603         $this->assertEqualSets( array( $post_id, $post_id3 ), $posts );
     1603        $this->assertSameSets( array( $post_id, $post_id3 ), $posts );
    16041604    }
    16051605
     
    16321632        }
    16331633        $posts = wp_list_pluck( $posts, 'ID' );
    1634         $this->assertEqualSets( array( $post_id, $post_id2 ), $posts );
     1634        $this->assertSameSets( array( $post_id, $post_id2 ), $posts );
    16351635    }
    16361636
     
    16791679        }
    16801680        $posts = wp_list_pluck( $posts, 'ID' );
    1681         $this->assertEqualSets( array( $post_id, $post_id5 ), $posts );
     1681        $this->assertSameSets( array( $post_id, $post_id5 ), $posts );
    16821682
    16831683        $posts = get_posts(
     
    16931693        }
    16941694        $posts = wp_list_pluck( $posts, 'ID' );
    1695         $this->assertEqualSets( array( $post_id, $post_id5 ), $posts );
     1695        $this->assertSameSets( array( $post_id, $post_id5 ), $posts );
    16961696
    16971697        $posts = get_posts( array( 'meta_value' => 0 ) );
     
    17021702        }
    17031703        $posts = wp_list_pluck( $posts, 'ID' );
    1704         $this->assertEqualSets( array( $post_id, $post_id3, $post_id4, $post_id5, $post_id6 ), $posts );
     1704        $this->assertSameSets( array( $post_id, $post_id3, $post_id4, $post_id5, $post_id6 ), $posts );
    17051705
    17061706        $posts = get_posts( array( 'meta_value' => '0' ) );
     
    17111711        }
    17121712        $posts = wp_list_pluck( $posts, 'ID' );
    1713         $this->assertEqualSets( array( $post_id, $post_id3, $post_id4, $post_id5, $post_id6 ), $posts );
     1713        $this->assertSameSets( array( $post_id, $post_id3, $post_id4, $post_id5, $post_id6 ), $posts );
    17141714    }
    17151715
     
    18471847        );
    18481848
    1849         $this->assertEqualSets( array( 'foo_key', 'foo_key-1', 'foo_key-2' ), array_keys( $q->meta_query->get_clauses() ) );
     1849        $this->assertSameSets( array( 'foo_key', 'foo_key-1', 'foo_key-2' ), array_keys( $q->meta_query->get_clauses() ) );
    18501850    }
    18511851
     
    18721872        );
    18731873
    1874         $this->assertEqualSets( array( $posts[0], $posts[2] ), $q->posts );
     1874        $this->assertSameSets( array( $posts[0], $posts[2] ), $q->posts );
    18751875    }
    18761876
     
    18931893        );
    18941894
    1895         $this->assertEqualSets( array( $posts[0], $posts[2] ), $q->posts );
     1895        $this->assertSameSets( array( $posts[0], $posts[2] ), $q->posts );
    18961896    }
    18971897
     
    19201920        );
    19211921
    1922         $this->assertEqualSets( array( $posts[0] ), $q->posts );
     1922        $this->assertSameSets( array( $posts[0] ), $q->posts );
    19231923
    19241924    }
     
    19481948        );
    19491949
    1950         $this->assertEqualSets( array( $posts[0], $posts[1] ), $q->posts );
     1950        $this->assertSameSets( array( $posts[0], $posts[1] ), $q->posts );
    19511951    }
    19521952
     
    19751975        );
    19761976
    1977         $this->assertEqualSets( array( $posts[0], $posts[2] ), $q->posts );
     1977        $this->assertSameSets( array( $posts[0], $posts[2] ), $q->posts );
    19781978    }
    19791979
     
    20002000        );
    20012001
    2002         $this->assertEqualSets( array( $posts[1], $posts[2] ), $q->posts );
     2002        $this->assertSameSets( array( $posts[1], $posts[2] ), $q->posts );
    20032003    }
    20042004
     
    20272027        );
    20282028
    2029         $this->assertEqualSets( array( $posts[1] ), $q->posts );
     2029        $this->assertSameSets( array( $posts[1] ), $q->posts );
    20302030    }
    20312031
     
    20542054        );
    20552055
    2056         $this->assertEqualSets( array( $posts[0], $posts[1] ), $q->posts );
     2056        $this->assertSameSets( array( $posts[0], $posts[1] ), $q->posts );
    20572057    }
    20582058
     
    20812081        );
    20822082
    2083         $this->assertEqualSets( array( $posts[2] ), $q->posts );
     2083        $this->assertSameSets( array( $posts[2] ), $q->posts );
    20842084    }
    20852085
     
    21072107        );
    21082108
    2109         $this->assertEqualSets( array( $posts[0], $posts[2] ), $q->posts );
     2109        $this->assertSameSets( array( $posts[0], $posts[2] ), $q->posts );
    21102110
    21112111        $q = new WP_Query(
     
    21222122        );
    21232123
    2124         $this->assertEqualSets( array( $posts[0] ), $q->posts );
     2124        $this->assertSameSets( array( $posts[0] ), $q->posts );
    21252125    }
    21262126
     
    21492149        );
    21502150
    2151         $this->assertEqualSets( array( $posts[1] ), $q->posts );
     2151        $this->assertSameSets( array( $posts[1] ), $q->posts );
    21522152
    21532153        $q = new WP_Query(
     
    21642164        );
    21652165
    2166         $this->assertEqualSets( array( $posts[1], $posts[2] ), $q->posts );
     2166        $this->assertSameSets( array( $posts[1], $posts[2] ), $q->posts );
    21672167    }
    21682168}
Note: See TracChangeset for help on using the changeset viewer.