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/includes/helpers.php

    r47122 r48939  
    88     * @ticket 30522
    99     */
    10     function data_assertEqualSets() {
     10    function data_assertSameSets() {
    1111        return array(
    1212            array(
     
    4949
    5050    /**
    51      * @dataProvider data_assertEqualSets
     51     * @dataProvider data_assertSameSets
    5252     * @ticket 30522
    5353     */
    54     function test_assertEqualSets( $expected, $actual, $exception ) {
     54    function test_assertSameSets( $expected, $actual, $exception ) {
    5555        if ( $exception ) {
    5656            try {
    57                 $this->assertEqualSets( $expected, $actual );
     57                $this->assertSameSets( $expected, $actual );
    5858            } catch ( PHPUnit_Framework_ExpectationFailedException $ex ) {
    5959                return;
     
    6262            $this->fail();
    6363        } else {
    64             $this->assertEqualSets( $expected, $actual );
     64            $this->assertSameSets( $expected, $actual );
    6565        }
    6666    }
     
    6969     * @ticket 30522
    7070     */
    71     function data_assertEqualSetsWithIndex() {
     71    function data_assertSameSetsWithIndex() {
    7272        return array(
    7373            array(
     
    205205    }
    206206    /**
    207      * @dataProvider data_assertEqualSetsWithIndex
     207     * @dataProvider data_assertSameSetsWithIndex
    208208     * @ticket 30522
    209209     */
    210     function test_assertEqualSetsWithIndex( $expected, $actual, $exception ) {
     210    function test_assertSameSetsWithIndex( $expected, $actual, $exception ) {
    211211        if ( $exception ) {
    212212            try {
    213                 $this->assertEqualSetsWithIndex( $expected, $actual );
     213                $this->assertSameSetsWithIndex( $expected, $actual );
    214214            } catch ( PHPUnit_Framework_ExpectationFailedException $ex ) {
    215215                return;
     
    218218            $this->fail();
    219219        } else {
    220             $this->assertEqualSetsWithIndex( $expected, $actual );
     220            $this->assertSameSetsWithIndex( $expected, $actual );
    221221        }
    222222    }
     
    313313
    314314        // Only check arguments that are explicitly asked for.
    315         $this->assertEqualSets( $expected['args'], array_intersect_key( $args, $expected['args'] ) );
     315        $this->assertSameSets( $expected['args'], array_intersect_key( $args, $expected['args'] ) );
    316316    }
    317317
Note: See TracChangeset for help on using the changeset viewer.