mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-05 05:04:31 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@48939 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -684,6 +684,20 @@ abstract class WP_UnitTestCase_Base extends PHPUnit\Framework\TestCase {
|
||||
$this->assertSameIgnoreEOL( $expected, $actual );
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the contents of two un-keyed, single arrays are the same, without accounting for the order of elements.
|
||||
*
|
||||
* @since 5.6.0
|
||||
*
|
||||
* @param array $expected Expected array.
|
||||
* @param array $actual Array to check.
|
||||
*/
|
||||
public function assertSameSets( $expected, $actual ) {
|
||||
sort( $expected );
|
||||
sort( $actual );
|
||||
$this->assertSame( $expected, $actual );
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the contents of two un-keyed, single arrays are equal, without accounting for the order of elements.
|
||||
*
|
||||
@@ -698,6 +712,20 @@ abstract class WP_UnitTestCase_Base extends PHPUnit\Framework\TestCase {
|
||||
$this->assertEquals( $expected, $actual );
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the contents of two keyed, single arrays are the same, without accounting for the order of elements.
|
||||
*
|
||||
* @since 5.6.0
|
||||
*
|
||||
* @param array $expected Expected array.
|
||||
* @param array $actual Array to check.
|
||||
*/
|
||||
public function assertSameSetsWithIndex( $expected, $actual ) {
|
||||
ksort( $expected );
|
||||
ksort( $actual );
|
||||
$this->assertSame( $expected, $actual );
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the contents of two keyed, single arrays are equal, without accounting for the order of elements.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user