diff --git a/tests/phpunit/tests/post/getPages.php b/tests/phpunit/tests/post/getPages.php index dad85ddc69367..dd29b9c380efd 100644 --- a/tests/phpunit/tests/post/getPages.php +++ b/tests/phpunit/tests/post/getPages.php @@ -55,18 +55,14 @@ public function test_get_pages_cache() { $time1 = wp_cache_get( 'last_changed', 'posts' ); $this->assertNotEmpty( $time1 ); $num_queries = get_num_queries(); - foreach ( $pages as $page ) { - $this->assertInstanceOf( 'WP_Post', $page ); - } + $this->assertContainsOnlyInstancesOf( 'WP_Post', $pages ); // Again. num_queries and last_changed should remain the same. $pages = get_pages(); $this->assertCount( 3, $pages ); $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) ); $this->assertSame( $num_queries, get_num_queries() ); - foreach ( $pages as $page ) { - $this->assertInstanceOf( 'WP_Post', $page ); - } + $this->assertContainsOnlyInstancesOf( 'WP_Post', $pages ); // Again with different args. last_changed should not increment because of // different args to get_pages(). num_queries should bump by 1. @@ -74,9 +70,7 @@ public function test_get_pages_cache() { $this->assertCount( 2, $pages ); $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) ); $this->assertSame( $num_queries + 1, get_num_queries() ); - foreach ( $pages as $page ) { - $this->assertInstanceOf( 'WP_Post', $page ); - } + $this->assertContainsOnlyInstancesOf( 'WP_Post', $pages ); $num_queries = get_num_queries(); @@ -85,18 +79,14 @@ public function test_get_pages_cache() { $this->assertCount( 2, $pages ); $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) ); $this->assertSame( $num_queries, get_num_queries() ); - foreach ( $pages as $page ) { - $this->assertInstanceOf( 'WP_Post', $page ); - } + $this->assertContainsOnlyInstancesOf( 'WP_Post', $pages ); // Do the first query again. The interim queries should not affect it. $pages = get_pages(); $this->assertCount( 3, $pages ); $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) ); $this->assertSame( $num_queries, get_num_queries() ); - foreach ( $pages as $page ) { - $this->assertInstanceOf( 'WP_Post', $page ); - } + $this->assertContainsOnlyInstancesOf( 'WP_Post', $pages ); // Force last_changed to increment. clean_post_cache( $pages[0]->ID ); @@ -109,9 +99,7 @@ public function test_get_pages_cache() { $this->assertCount( 2, $pages ); $this->assertSame( $time2, wp_cache_get( 'last_changed', 'posts' ) ); $this->assertSame( $num_queries + 1, get_num_queries() ); - foreach ( $pages as $page ) { - $this->assertInstanceOf( 'WP_Post', $page ); - } + $this->assertContainsOnlyInstancesOf( 'WP_Post', $pages ); $last_changed = wp_cache_get( 'last_changed', 'posts' ); @@ -129,9 +117,7 @@ public function test_get_pages_cache() { $this->assertCount( 2, $pages ); $this->assertSame( $last_changed, wp_cache_get( 'last_changed', 'posts' ) ); $this->assertSame( $num_queries + 1, get_num_queries() ); - foreach ( $pages as $page ) { - $this->assertInstanceOf( 'WP_Post', $page ); - } + $this->assertContainsOnlyInstancesOf( 'WP_Post', $pages ); } /** diff --git a/tests/phpunit/tests/post/wpPostType.php b/tests/phpunit/tests/post/wpPostType.php index 23ec325a65a54..78832de574603 100644 --- a/tests/phpunit/tests/post/wpPostType.php +++ b/tests/phpunit/tests/post/wpPostType.php @@ -9,9 +9,7 @@ public function test_instances() { $this->assertNotEmpty( $wp_post_types ); - foreach ( $wp_post_types as $post_type ) { - $this->assertInstanceOf( 'WP_Post_Type', $post_type ); - } + $this->assertContainsOnlyInstancesOf( 'WP_Post_Type', $wp_post_types ); } public function test_add_supports_defaults() { diff --git a/tests/phpunit/tests/term/getTerms.php b/tests/phpunit/tests/term/getTerms.php index 6162b28e38f06..dc5855bafc1e8 100644 --- a/tests/phpunit/tests/term/getTerms.php +++ b/tests/phpunit/tests/term/getTerms.php @@ -2876,9 +2876,7 @@ public function test_should_return_wp_term_objects() { $this->assertNotEmpty( $found ); - foreach ( $found as $term ) { - $this->assertInstanceOf( 'WP_Term', $term ); - } + $this->assertContainsOnlyInstancesOf( 'WP_Term', $found ); } /** @@ -2914,9 +2912,7 @@ public function test_should_return_wp_term_objects_when_pulling_from_the_cache() $this->assertNotEmpty( $found ); - foreach ( $found as $term ) { - $this->assertInstanceOf( 'WP_Term', $term ); - } + $this->assertContainsOnlyInstancesOf( 'WP_Term', $found ); } /** diff --git a/tests/phpunit/tests/term/wpGetObjectTerms.php b/tests/phpunit/tests/term/wpGetObjectTerms.php index 128e4a19a8bdb..a8483f8a770a2 100644 --- a/tests/phpunit/tests/term/wpGetObjectTerms.php +++ b/tests/phpunit/tests/term/wpGetObjectTerms.php @@ -781,9 +781,7 @@ public function test_should_return_wp_term_objects_for_fields_all() { ); $this->assertNotEmpty( $found ); - foreach ( $found as $f ) { - $this->assertInstanceOf( 'WP_Term', $f ); - } + $this->assertContainsOnlyInstancesOf( 'WP_Term', $found ); } /** @@ -804,9 +802,7 @@ public function test_should_return_wp_term_objects_for_fields_all_with_object_id ); $this->assertNotEmpty( $found ); - foreach ( $found as $f ) { - $this->assertInstanceOf( 'WP_Term', $f ); - } + $this->assertContainsOnlyInstancesOf( 'WP_Term', $found ); } /** diff --git a/tests/phpunit/tests/term/wpTaxonomy.php b/tests/phpunit/tests/term/wpTaxonomy.php index 845497ad0672a..a35078dc3141d 100644 --- a/tests/phpunit/tests/term/wpTaxonomy.php +++ b/tests/phpunit/tests/term/wpTaxonomy.php @@ -9,9 +9,7 @@ public function test_instances() { $this->assertNotEmpty( $wp_taxonomies ); - foreach ( $wp_taxonomies as $taxonomy ) { - $this->assertInstanceOf( 'WP_Taxonomy', $taxonomy ); - } + $this->assertContainsOnlyInstancesOf( 'WP_Taxonomy', $wp_taxonomies ); } public function test_does_not_add_query_var_if_not_public() { diff --git a/tests/phpunit/tests/user/query.php b/tests/phpunit/tests/user/query.php index bb6d9e391f4a9..5978f4bf55e58 100644 --- a/tests/phpunit/tests/user/query.php +++ b/tests/phpunit/tests/user/query.php @@ -138,9 +138,7 @@ public function test_get_all() { // +1 for the default user created during installation. $this->assertCount( 13, $users ); - foreach ( $users as $user ) { - $this->assertInstanceOf( 'WP_User', $user ); - } + $this->assertContainsOnlyInstancesOf( 'WP_User', $users ); $users = new WP_User_Query( array( @@ -150,9 +148,7 @@ public function test_get_all() { ); $users = $users->get_results(); $this->assertCount( 13, $users ); - foreach ( $users as $user ) { - $this->assertInstanceOf( 'WP_User', $user ); - } + $this->assertContainsOnlyInstancesOf( 'WP_User', $users ); } /** @@ -1416,9 +1412,7 @@ public function test_get_multiple_roles_should_only_match_users_who_have_each_ro $this->assertCount( 2, $users ); - foreach ( $users as $user ) { - $this->assertInstanceOf( 'WP_User', $user ); - } + $this->assertContainsOnlyInstancesOf( 'WP_User', $users ); } /** @@ -1430,9 +1424,7 @@ public function test_get_multiple_roles_or() { // +1 for the default user created during installation. $this->assertCount( 8, $users ); - foreach ( $users as $user ) { - $this->assertInstanceOf( 'WP_User', $user ); - } + $this->assertContainsOnlyInstancesOf( 'WP_User', $users ); } /**