Make WordPress Core


Ignore:
Timestamp:
09/04/2020 07:01:00 AM (6 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/includes/abstract-testcase.php

    r48937 r48939  
    686686
    687687        /**
     688         * Asserts that the contents of two un-keyed, single arrays are the same, without accounting for the order of elements.
     689         *
     690         * @since 5.6.0
     691         *
     692         * @param array $expected Expected array.
     693         * @param array $actual   Array to check.
     694         */
     695        public function assertSameSets( $expected, $actual ) {
     696                sort( $expected );
     697                sort( $actual );
     698                $this->assertSame( $expected, $actual );
     699        }
     700
     701        /**
    688702         * Asserts that the contents of two un-keyed, single arrays are equal, without accounting for the order of elements.
    689703         *
    … …  
    697711                sort( $actual );
    698712                $this->assertEquals( $expected, $actual );
     713        }
     714
     715        /**
     716         * Asserts that the contents of two keyed, single arrays are the same, without accounting for the order of elements.
     717         *
     718         * @since 5.6.0
     719         *
     720         * @param array $expected Expected array.
     721         * @param array $actual   Array to check.
     722         */
     723        public function assertSameSetsWithIndex( $expected, $actual ) {
     724                ksort( $expected );
     725                ksort( $actual );
     726                $this->assertSame( $expected, $actual );
    699727        }
    700728
Note: See TracChangeset for help on using the changeset viewer.