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

@@ -168,7 +168,7 @@ if ( is_multisite() ) :
$result = array_keys( get_object_vars( $site ) );
$this->assertEqualSets( $this->get_fields( $get_all ), $result );
$this->assertSameSets( $this->get_fields( $get_all ), $result );
}
/**
@@ -190,7 +190,7 @@ if ( is_multisite() ) :
$result[] = $key;
}
$this->assertEqualSets( $this->get_fields( $get_all ), $result );
$this->assertSameSets( $this->get_fields( $get_all ), $result );
}
public function data_get_all() {

View File

@@ -109,7 +109,7 @@ if ( is_multisite() ) :
)
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_network_query_by_network__in_with_multiple_ids() {
@@ -123,7 +123,7 @@ if ( is_multisite() ) :
)
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_network_query_by_network__in_and_count_with_multiple_ids() {
@@ -156,7 +156,7 @@ if ( is_multisite() ) :
)
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_network_query_by_network__not_in_with_multiple_ids() {
@@ -174,7 +174,7 @@ if ( is_multisite() ) :
)
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_network_query_by_domain() {
@@ -190,7 +190,7 @@ if ( is_multisite() ) :
self::$network_ids['www.w.org/foo/'],
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_network_query_by_domain__in_with_single_domain() {
@@ -206,7 +206,7 @@ if ( is_multisite() ) :
self::$network_ids['make.wordpress.org/'],
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_network_query_by_domain__in_with_multiple_domains() {
@@ -223,7 +223,7 @@ if ( is_multisite() ) :
self::$network_ids['make.wordpress.org/'],
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_network_query_by_domain__in_with_multiple_domains_and_number() {
@@ -240,7 +240,7 @@ if ( is_multisite() ) :
self::$network_ids['wordpress.org/'],
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_network_query_by_domain__in_with_multiple_domains_and_number_and_offset() {
@@ -258,7 +258,7 @@ if ( is_multisite() ) :
self::$network_ids['make.wordpress.org/'],
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_network_query_by_domain__not_in_with_single_domain() {
@@ -277,7 +277,7 @@ if ( is_multisite() ) :
self::$network_ids['www.wordpress.net/'],
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_network_query_by_domain__not_in_with_multiple_domains() {
@@ -295,7 +295,7 @@ if ( is_multisite() ) :
self::$network_ids['www.wordpress.net/'],
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_network_query_by_domain__not_in_with_multiple_domains_and_number() {
@@ -313,7 +313,7 @@ if ( is_multisite() ) :
self::$network_ids['make.wordpress.org/'],
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_network_query_by_domain__not_in_with_multiple_domains_and_number_and_offset() {
@@ -332,7 +332,7 @@ if ( is_multisite() ) :
self::$network_ids['www.wordpress.net/'],
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_network_query_by_path_with_expected_results() {
@@ -351,7 +351,7 @@ if ( is_multisite() ) :
self::$network_ids['www.wordpress.net/'],
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_network_query_by_path_and_number_and_offset_with_expected_results() {
@@ -370,7 +370,7 @@ if ( is_multisite() ) :
self::$network_ids['www.wordpress.net/'],
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_network_query_by_path_with_no_expected_results() {
@@ -398,7 +398,7 @@ if ( is_multisite() ) :
self::$network_ids['www.wordpress.net/'],
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_network_query_by_search_with_text_in_path() {
@@ -414,7 +414,7 @@ if ( is_multisite() ) :
self::$network_ids['www.w.org/foo/'],
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_network_query_by_path_order_by_domain_desc() {

View File

@@ -1574,7 +1574,7 @@ if ( is_multisite() ) :
public function test_wp_normalize_site_data( $data, $expected ) {
$result = wp_normalize_site_data( $data );
$this->assertEqualSetsWithIndex( $expected, $result );
$this->assertSameSetsWithIndex( $expected, $result );
}
public function data_wp_normalize_site_data() {
@@ -1657,7 +1657,7 @@ if ( is_multisite() ) :
if ( empty( $expected_errors ) ) {
$this->assertEmpty( $result->errors );
} else {
$this->assertEqualSets( $expected_errors, array_keys( $result->errors ) );
$this->assertSameSets( $expected_errors, array_keys( $result->errors ) );
}
}
@@ -1955,8 +1955,8 @@ if ( is_multisite() ) :
$update_result = $this->get_listen_to_site_status_hooks_result();
// Check both insert and update results.
$this->assertEqualSetsWithIndex( $insert_expected, $insert_result );
$this->assertEqualSetsWithIndex( $update_expected, $update_result );
$this->assertSameSetsWithIndex( $insert_expected, $insert_result );
$this->assertSameSetsWithIndex( $update_expected, $update_result );
}
public function data_site_status_hook_triggers() {
@@ -2187,7 +2187,7 @@ if ( is_multisite() ) :
wp_uninitialize_site( self::$uninitialized_site_id );
$this->assertTrue( $result );
$this->assertEqualSets(
$this->assertSameSets(
array(
'administrator',
'editor',
@@ -2351,7 +2351,7 @@ if ( is_multisite() ) :
$passed_args = $this->wp_initialize_site_args;
$this->wp_initialize_site_args = null;
$this->assertEqualSetsWithIndex( $args, $passed_args );
$this->assertSameSetsWithIndex( $args, $passed_args );
}
public function filter_wp_initialize_site_args_catch_args( $args ) {

View File

@@ -121,7 +121,7 @@ if ( is_multisite() ) :
'foo1' => array( 'baz' ),
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_get_with_key_should_fetch_all_for_key() {
@@ -136,7 +136,7 @@ if ( is_multisite() ) :
$found = get_site_meta( self::$site_id, 'foo' );
$expected = array( 'bar', 'baz' );
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_get_should_respect_single_true() {
@@ -299,7 +299,7 @@ if ( is_multisite() ) :
)
);
$this->assertEqualSets( array( self::$site_id ), $found );
$this->assertSameSets( array( self::$site_id ), $found );
add_site_meta( self::$site_id2, 'foo', 'bar' );
@@ -315,7 +315,7 @@ if ( is_multisite() ) :
)
);
$this->assertEqualSets( array( self::$site_id, self::$site_id2 ), $found );
$this->assertSameSets( array( self::$site_id, self::$site_id2 ), $found );
}
/**
@@ -342,7 +342,7 @@ if ( is_multisite() ) :
)
);
$this->assertEqualSets( array( self::$site_id ), $found );
$this->assertSameSets( array( self::$site_id ), $found );
update_site_meta( self::$site_id2, 'foo', 'bar' );
@@ -358,7 +358,7 @@ if ( is_multisite() ) :
)
);
$this->assertEqualSets( array( self::$site_id, self::$site_id2 ), $found );
$this->assertSameSets( array( self::$site_id, self::$site_id2 ), $found );
}
/**
@@ -385,7 +385,7 @@ if ( is_multisite() ) :
)
);
$this->assertEqualSets( array( self::$site_id, self::$site_id2 ), $found );
$this->assertSameSets( array( self::$site_id, self::$site_id2 ), $found );
delete_site_meta( self::$site_id2, 'foo', 'bar' );
@@ -401,7 +401,7 @@ if ( is_multisite() ) :
)
);
$this->assertEqualSets( array( self::$site_id ), $found );
$this->assertSameSets( array( self::$site_id ), $found );
}
}

View File

@@ -123,7 +123,7 @@ if ( is_multisite() ) :
)
);
$this->assertEqualSets( array( self::$site_ids['www.w.org/'] ), $found );
$this->assertSameSets( array( self::$site_ids['www.w.org/'] ), $found );
}
public function test_wp_site_query_by_number() {
@@ -149,7 +149,7 @@ if ( is_multisite() ) :
)
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_site_query_by_site__in_with_multiple_ids() {
@@ -163,7 +163,7 @@ if ( is_multisite() ) :
)
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
/**
@@ -199,7 +199,7 @@ if ( is_multisite() ) :
)
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_site_query_by_site__not_in_with_multiple_ids() {
@@ -217,7 +217,7 @@ if ( is_multisite() ) :
)
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_site_query_by_network_id_with_order() {
@@ -265,7 +265,7 @@ if ( is_multisite() ) :
self::$site_ids['make.wordpress.org/foo/'],
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_site_query_by_network_id_with_no_existing_sites() {
@@ -296,7 +296,7 @@ if ( is_multisite() ) :
self::$site_ids['www.w.org/make/'],
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_site_query_by_domain_and_offset() {
@@ -315,7 +315,7 @@ if ( is_multisite() ) :
self::$site_ids['www.w.org/make/'],
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_site_query_by_domain_and_number_and_offset() {
@@ -334,7 +334,7 @@ if ( is_multisite() ) :
self::$site_ids['www.w.org/foo/bar/'],
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_site_query_by_domain__in_with_single_domain() {
@@ -351,7 +351,7 @@ if ( is_multisite() ) :
self::$site_ids['make.wordpress.org/foo/'],
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_site_query_by_domain__in_with_multiple_domains() {
@@ -371,7 +371,7 @@ if ( is_multisite() ) :
self::$site_ids['make.wordpress.org/foo/'],
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_site_query_by_domain__not_in_with_single_domain() {
@@ -392,7 +392,7 @@ if ( is_multisite() ) :
self::$site_ids['make.wordpress.org/foo/'],
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_site_query_by_domain__not_in_with_multiple_domains() {
@@ -410,7 +410,7 @@ if ( is_multisite() ) :
self::$site_ids['make.wordpress.org/foo/'],
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_site_query_by_path_with_expected_results() {
@@ -427,7 +427,7 @@ if ( is_multisite() ) :
self::$site_ids['www.w.org/foo/bar/'],
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_site_query_by_path_with_no_expected_results() {
@@ -455,7 +455,7 @@ if ( is_multisite() ) :
)
);
$this->assertEqualSets( array_values( self::$site_ids ), $found );
$this->assertSameSets( array_values( self::$site_ids ), $found );
}
public function test_wp_site_query_by_mature() {
@@ -469,7 +469,7 @@ if ( is_multisite() ) :
)
);
$this->assertEqualSets( array_values( self::$site_ids ), $found );
$this->assertSameSets( array_values( self::$site_ids ), $found );
}
public function test_wp_site_query_by_spam() {
@@ -483,7 +483,7 @@ if ( is_multisite() ) :
)
);
$this->assertEqualSets( array_values( self::$site_ids ), $found );
$this->assertSameSets( array_values( self::$site_ids ), $found );
}
public function test_wp_site_query_by_deleted() {
@@ -497,7 +497,7 @@ if ( is_multisite() ) :
)
);
$this->assertEqualSets( array_values( self::$site_ids ), $found );
$this->assertSameSets( array_values( self::$site_ids ), $found );
}
public function test_wp_site_query_by_deleted_with_no_results() {
@@ -523,7 +523,7 @@ if ( is_multisite() ) :
)
);
$this->assertEqualSets( array_values( self::$site_ids ), $found );
$this->assertSameSets( array_values( self::$site_ids ), $found );
}
public function test_wp_site_query_by_lang_id_with_zero() {
@@ -537,7 +537,7 @@ if ( is_multisite() ) :
)
);
$this->assertEqualSets( array_diff( array_values( self::$site_ids ), array( self::$site_ids['www.w.org/make/'] ) ), $found );
$this->assertSameSets( array_diff( array_values( self::$site_ids ), array( self::$site_ids['www.w.org/make/'] ) ), $found );
}
public function test_wp_site_query_by_lang_id() {
@@ -553,7 +553,7 @@ if ( is_multisite() ) :
self::$site_ids['www.w.org/make/'],
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_site_query_by_lang_id_with_no_results() {
@@ -581,7 +581,7 @@ if ( is_multisite() ) :
self::$site_ids['www.w.org/make/'],
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_site_query_by_lang__in_with_multiple_ids() {
@@ -595,7 +595,7 @@ if ( is_multisite() ) :
)
);
$this->assertEqualSets( array_values( self::$site_ids ), $found );
$this->assertSameSets( array_values( self::$site_ids ), $found );
}
public function test_wp_site_query_by_lang__not_in() {
@@ -611,7 +611,7 @@ if ( is_multisite() ) :
self::$site_ids['www.w.org/make/'],
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_site_query_by_lang__not_in_with_multiple_ids() {
@@ -640,7 +640,7 @@ if ( is_multisite() ) :
self::$site_ids['make.wordpress.org/foo/'],
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_site_query_by_search_with_text_in_path() {
@@ -660,7 +660,7 @@ if ( is_multisite() ) :
self::$site_ids['www.w.org/foo/bar/'],
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_site_query_by_search_with_text_in_path_and_domain() {
@@ -678,7 +678,7 @@ if ( is_multisite() ) :
self::$site_ids['www.w.org/make/'],
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_site_query_by_search_with_text_in_path_and_domain_order_by_domain_desc() {
@@ -751,7 +751,7 @@ if ( is_multisite() ) :
self::$site_ids['make.wordpress.org/foo/'],
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_site_query_by_search_with_wildcard_in_text_exclude_path_from_search() {
@@ -769,7 +769,7 @@ if ( is_multisite() ) :
self::$site_ids['make.wordpress.org/foo/'],
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
public function test_wp_site_query_by_search_with_wildcard_in_text_exclude_domain_from_search() {
@@ -786,7 +786,7 @@ if ( is_multisite() ) :
self::$site_ids['www.w.org/make/'],
);
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
/**
@@ -905,7 +905,7 @@ if ( is_multisite() ) :
if ( $strict ) {
$this->assertSame( $expected, $found );
} else {
$this->assertEqualSets( $expected, $found );
$this->assertSameSets( $expected, $found );
}
}

View File

@@ -93,7 +93,7 @@ if ( is_multisite() ) :
$items = wp_list_pluck( $this->table->items, 'blog_id' );
$items = array_map( 'intval', $items );
$this->assertEqualSets( array( 1 ) + self::$site_ids, $items );
$this->assertSameSets( array( 1 ) + self::$site_ids, $items );
}
public function test_ms_sites_list_table_subdirectory_path_search_items() {
@@ -119,7 +119,7 @@ if ( is_multisite() ) :
self::$site_ids['www.w.org/foo/bar/'],
);
$this->assertEqualSets( $expected, $items );
$this->assertSameSets( $expected, $items );
}
public function test_ms_sites_list_table_subdirectory_multiple_path_search_items() {
@@ -141,7 +141,7 @@ if ( is_multisite() ) :
self::$site_ids['www.w.org/foo/bar/'],
);
$this->assertEqualSets( $expected, $items );
$this->assertSameSets( $expected, $items );
}
public function test_ms_sites_list_table_invalid_path_search_items() {
@@ -178,7 +178,7 @@ if ( is_multisite() ) :
self::$site_ids['atest.example.org/'],
);
$this->assertEqualSets( $expected, $items );
$this->assertSameSets( $expected, $items );
}
public function test_ms_sites_list_table_subdomain_domain_search_items_with_trailing_wildcard() {
@@ -202,7 +202,7 @@ if ( is_multisite() ) :
self::$site_ids['atest.example.org/'],
);
$this->assertEqualSets( $expected, $items );
$this->assertSameSets( $expected, $items );
}
public function test_ms_sites_list_table_subdirectory_path_search_items_with_trailing_wildcard() {
@@ -228,7 +228,7 @@ if ( is_multisite() ) :
self::$site_ids['www.w.org/foo/bar/'],
);
$this->assertEqualSets( $expected, $items );
$this->assertSameSets( $expected, $items );
}
}
endif;