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:
Sergey Biryukov
2020-09-04 07:01:00 +00:00
parent 5e2a75ef29
commit 8be943d06e
105 changed files with 757 additions and 729 deletions

View File

@@ -7,7 +7,7 @@ class Tests_TestHelpers extends WP_UnitTestCase {
/**
* @ticket 30522
*/
function data_assertEqualSets() {
function data_assertSameSets() {
return array(
array(
array( 1, 2, 3 ), // Test expected.
@@ -48,27 +48,27 @@ class Tests_TestHelpers extends WP_UnitTestCase {
}
/**
* @dataProvider data_assertEqualSets
* @dataProvider data_assertSameSets
* @ticket 30522
*/
function test_assertEqualSets( $expected, $actual, $exception ) {
function test_assertSameSets( $expected, $actual, $exception ) {
if ( $exception ) {
try {
$this->assertEqualSets( $expected, $actual );
$this->assertSameSets( $expected, $actual );
} catch ( PHPUnit_Framework_ExpectationFailedException $ex ) {
return;
}
$this->fail();
} else {
$this->assertEqualSets( $expected, $actual );
$this->assertSameSets( $expected, $actual );
}
}
/**
* @ticket 30522
*/
function data_assertEqualSetsWithIndex() {
function data_assertSameSetsWithIndex() {
return array(
array(
array( 1, 2, 3 ), // Test expected.
@@ -204,20 +204,20 @@ class Tests_TestHelpers extends WP_UnitTestCase {
);
}
/**
* @dataProvider data_assertEqualSetsWithIndex
* @dataProvider data_assertSameSetsWithIndex
* @ticket 30522
*/
function test_assertEqualSetsWithIndex( $expected, $actual, $exception ) {
function test_assertSameSetsWithIndex( $expected, $actual, $exception ) {
if ( $exception ) {
try {
$this->assertEqualSetsWithIndex( $expected, $actual );
$this->assertSameSetsWithIndex( $expected, $actual );
} catch ( PHPUnit_Framework_ExpectationFailedException $ex ) {
return;
}
$this->fail();
} else {
$this->assertEqualSetsWithIndex( $expected, $actual );
$this->assertSameSetsWithIndex( $expected, $actual );
}
}
@@ -312,7 +312,7 @@ class Tests_TestHelpers extends WP_UnitTestCase {
$this->assertSame( $expected['title'], $title );
// Only check arguments that are explicitly asked for.
$this->assertEqualSets( $expected['args'], array_intersect_key( $args, $expected['args'] ) );
$this->assertSameSets( $expected['args'], array_intersect_key( $args, $expected['args'] ) );
}
public function data_die_process_input() {