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

    r48937 r48939  
    5555        );
    5656
    57         $this->assertEqualSets( array( $p1, $p2 ), wp_list_pluck( $posts, 'ID' ) );
     57        $this->assertSameSets( array( $p1, $p2 ), wp_list_pluck( $posts, 'ID' ) );
    5858    }
    5959
     
    7878        );
    7979
    80         $this->assertEqualSets( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
     80        $this->assertSameSets( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
    8181    }
    8282
     
    119119        );
    120120
    121         $this->assertEqualSets( array( $p3 ), wp_list_pluck( $posts, 'ID' ) );
     121        $this->assertSameSets( array( $p3 ), wp_list_pluck( $posts, 'ID' ) );
    122122    }
    123123
     
    291291        );
    292292
    293         $this->assertEqualSets( array( $p1, $p2 ), $before_posts );
    294         $this->assertEqualSets( array( $p1, $p2 ), $after_posts );
     293        $this->assertSameSets( array( $p1, $p2 ), $before_posts );
     294        $this->assertSameSets( array( $p1, $p2 ), $after_posts );
    295295    }
    296296
     
    375375        );
    376376
    377         $this->assertEqualSets( array( $p1, $p2 ), $before_posts );
    378         $this->assertEqualSets( array( $p1, $p2 ), $after_posts );
     377        $this->assertSameSets( array( $p1, $p2 ), $before_posts );
     378        $this->assertSameSets( array( $p1, $p2 ), $after_posts );
    379379    }
    380380
     
    459459        );
    460460
    461         $this->assertEqualSets( array( $p1, $p2 ), $before_posts );
    462         $this->assertEqualSets( array( $p1, $p2 ), $after_posts );
     461        $this->assertSameSets( array( $p1, $p2 ), $before_posts );
     462        $this->assertSameSets( array( $p1, $p2 ), $after_posts );
    463463    }
    464464
     
    543543        );
    544544
    545         $this->assertEqualSets( array( $p1, $p2 ), $before_posts );
    546         $this->assertEqualSets( array( $p1, $p2 ), $after_posts );
     545        $this->assertSameSets( array( $p1, $p2 ), $before_posts );
     546        $this->assertSameSets( array( $p1, $p2 ), $after_posts );
    547547    }
    548548
     
    627627        );
    628628
    629         $this->assertEqualSets( array( $p1, $p2 ), $before_posts );
    630         $this->assertEqualSets( array( $p1, $p2 ), $after_posts );
     629        $this->assertSameSets( array( $p1, $p2 ), $before_posts );
     630        $this->assertSameSets( array( $p1, $p2 ), $after_posts );
    631631    }
    632632
     
    868868        );
    869869
    870         $this->assertEqualSets( array( $p2, $p3, $p4 ), wp_list_pluck( $posts, 'ID' ) );
     870        $this->assertSameSets( array( $p2, $p3, $p4 ), wp_list_pluck( $posts, 'ID' ) );
    871871    }
    872872
     
    10851085        $expected = array( $p1, $p2 );
    10861086
    1087         $this->assertEqualSets( $expected, $q->posts );
     1087        $this->assertSameSets( $expected, $q->posts );
    10881088    }
    10891089
     
    11641164
    11651165        $expected = array( $p1, $p4, $p5 );
    1166         $this->assertEqualSets( $expected, $q->posts );
     1166        $this->assertSameSets( $expected, $q->posts );
    11671167    }
    11681168}
Note: See TracChangeset for help on using the changeset viewer.