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/meta/deleteMetadata.php

    r48937 r48939  
    1111        }
    1212        $m = get_metadata( 'post', 12345, 'foo', false );
    13         $this->assertEqualSets( $vals, $m );
     13        $this->assertSameSets( $vals, $m );
    1414
    1515        delete_metadata( 'post', 12345, 'foo' );
    1616        $m = get_metadata( 'post', 12345, 'foo', false );
    17         $this->assertEqualSets( array(), $m );
     17        $this->assertSameSets( array(), $m );
    1818    }
    1919
     
    2424        }
    2525        $m = get_metadata( 'post', 12345, 'foo', false );
    26         $this->assertEqualSets( $vals, $m );
     26        $this->assertSameSets( $vals, $m );
    2727
    2828        delete_metadata( 'post', 12345, 'foo', '1' );
     
    3030        $expected = array_diff( $vals, array( '1' ) );
    3131
    32         $this->assertEqualSets( $expected, $m );
     32        $this->assertSameSets( $expected, $m );
    3333    }
    3434
     
    4242        }
    4343        $m = get_metadata( 'post', 12345, 'foo', false );
    44         $this->assertEqualSets( $vals, $m );
     44        $this->assertSameSets( $vals, $m );
    4545
    4646        delete_metadata( 'post', 12345, 'foo', '0' );
     
    4848        $expected = array_diff( $vals, array( '0' ) );
    4949
    50         $this->assertEqualSets( $expected, $m );
     50        $this->assertSameSets( $expected, $m );
    5151    }
    5252
     
    6262        }
    6363        $m = get_metadata( 'post', 12345, 'foo', false );
    64         $this->assertEqualSets( $vals, $m );
     64        $this->assertSameSets( $vals, $m );
    6565
    6666        delete_metadata( 'post', 12345, 'foo', '' );
    6767        $m = get_metadata( 'post', 12345, 'foo', false );
    68         $this->assertEqualSets( array(), $m );
     68        $this->assertSameSets( array(), $m );
    6969    }
    7070
     
    7878        }
    7979        $m = get_metadata( 'post', 12345, 'foo', false );
    80         $this->assertEqualSets( $vals, $m );
     80        $this->assertSameSets( $vals, $m );
    8181
    8282        delete_metadata( 'post', 12345, 'foo', null );
    8383        $m = get_metadata( 'post', 12345, 'foo', false );
    84         $this->assertEqualSets( array(), $m );
     84        $this->assertSameSets( array(), $m );
    8585    }
    8686
     
    9494        }
    9595        $m = get_metadata( 'post', 12345, 'foo', false );
    96         $this->assertEqualSets( $vals, $m );
     96        $this->assertSameSets( $vals, $m );
    9797
    9898        delete_metadata( 'post', 12345, 'foo', false );
    9999        $m = get_metadata( 'post', 12345, 'foo', false );
    100         $this->assertEqualSets( array(), $m );
     100        $this->assertSameSets( array(), $m );
    101101    }
    102102
Note: See TracChangeset for help on using the changeset viewer.