From 725bd04a4f81ec6123fe31157cda173542aa2e84 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 15 Aug 2020 17:34:31 +0200 Subject: [PATCH] Tests: replace `assert[Not]InternalType( 'object', $var )` with `assertIs[Not]Object()` The `assertInternalType()` and `assertNotInternalType()` methods were soft deprecated in PHPUnit 7.5, hard deprecated in PHPUnit 8.0 and the functionality was removed in PHPUnit 9.0. The more specific `assertIsArray()`, `assertIsNotArray()`, `assertIsBool()`, `assertIsNotBool()`, `assertIsFloat()`, `assertIsNotFloat()`, `assertIsInt()`, `assertIsNotInt()`, `assertIsNumeric()`, `assertIsNotNumeric()`, `assertIsObject()`, `assertIsNotObject()`, `assertIsResource()`, `assertIsNotResource()`, `assertIsString()`, `assertIsNotString()`, `assertIsScalar()`, `assertIsNotScalar()`, `assertIsCallable()`, `assertIsNotCallable()`, `assertIsIterable()`, `assertIsNotIterable()` methods were introduced as replacements in PHPUnit 7.5. Ref: * https://github.com/sebastianbergmann/phpunit/blob/7.5.20/ChangeLog-7.5.md#750---2018-12-07 * https://github.com/sebastianbergmann/phpunit/issues/3368 --- tests/phpunit/tests/adminbar.php | 2 +- tests/phpunit/tests/customize/nav-menu-setting.php | 2 +- tests/phpunit/tests/db.php | 2 +- tests/phpunit/tests/includes/factory.php | 2 +- tests/phpunit/tests/media/getAttachmentTaxonomies.php | 4 ++-- tests/phpunit/tests/oembed/controller.php | 10 +++++----- tests/phpunit/tests/post/getPageByPath.php | 2 +- tests/phpunit/tests/post/getPostTypeLabels.php | 3 +-- tests/phpunit/tests/post/types.php | 4 ++-- tests/phpunit/tests/taxonomy.php | 4 ++-- tests/phpunit/tests/taxonomy/getObjectTaxonomies.php | 4 ++-- tests/phpunit/tests/term/getTerm.php | 4 ++-- tests/phpunit/tests/term/wpGetObjectTerms.php | 2 +- tests/phpunit/tests/term/wpInsertTerm.php | 2 +- 14 files changed, 23 insertions(+), 24 deletions(-) diff --git a/tests/phpunit/tests/adminbar.php b/tests/phpunit/tests/adminbar.php index d63ba6461e98..4a4895ef433e 100644 --- a/tests/phpunit/tests/adminbar.php +++ b/tests/phpunit/tests/adminbar.php @@ -166,7 +166,7 @@ public function test_admin_bar_contains_correct_links_for_users_with_no_role_on_ // Get primary blog. $primary = get_active_blog_for_user( self::$editor_id ); - $this->assertInternalType( 'object', $primary ); + $this->assertIsObject( $primary ); // No Site menu as the user isn't a member of this blog. $this->assertNull( $node_site_name ); diff --git a/tests/phpunit/tests/customize/nav-menu-setting.php b/tests/phpunit/tests/customize/nav-menu-setting.php index 446f9804b01c..6d3e100e60e4 100644 --- a/tests/phpunit/tests/customize/nav-menu-setting.php +++ b/tests/phpunit/tests/customize/nav-menu-setting.php @@ -305,7 +305,7 @@ function test_preview_deleted() { $this->wp_customize->set_post_value( $setting_id, false ); $this->assertIsArray( $setting->value() ); - $this->assertInternalType( 'object', wp_get_nav_menu_object( $menu_id ) ); + $this->assertIsObject( wp_get_nav_menu_object( $menu_id ) ); $setting->preview(); $this->assertFalse( $setting->value() ); $this->assertFalse( wp_get_nav_menu_object( $menu_id ) ); diff --git a/tests/phpunit/tests/db.php b/tests/phpunit/tests/db.php index 37232065e105..889f656f2a52 100644 --- a/tests/phpunit/tests/db.php +++ b/tests/phpunit/tests/db.php @@ -568,7 +568,7 @@ function test_get_row() { $this->assertNotEmpty( $wpdb->insert_id ); $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->users WHERE ID = %d", $wpdb->insert_id ) ); - $this->assertInternalType( 'object', $row ); + $this->assertIsObject( $row ); $this->assertEquals( 'Walter Sobchak', $row->display_name ); } diff --git a/tests/phpunit/tests/includes/factory.php b/tests/phpunit/tests/includes/factory.php index 24dbef625f76..1c9b13c9583b 100644 --- a/tests/phpunit/tests/includes/factory.php +++ b/tests/phpunit/tests/includes/factory.php @@ -35,7 +35,7 @@ function test_the_taxonomy_argument_overrules_the_factory_taxonomy() { public function test_term_factory_create_and_get_should_return_term_object() { register_taxonomy( 'wptests_tax', 'post' ); $term = self::factory()->term->create_and_get( array( 'taxonomy' => 'wptests_tax' ) ); - $this->assertInternalType( 'object', $term ); + $this->assertIsObject( $term ); $this->assertNotEmpty( $term->term_id ); } } diff --git a/tests/phpunit/tests/media/getAttachmentTaxonomies.php b/tests/phpunit/tests/media/getAttachmentTaxonomies.php index f777d5d0601a..bf1549ff2b4a 100644 --- a/tests/phpunit/tests/media/getAttachmentTaxonomies.php +++ b/tests/phpunit/tests/media/getAttachmentTaxonomies.php @@ -119,7 +119,7 @@ public function test_should_respect_output_objects() { $found = get_attachment_taxonomies( $attachment, 'objects' ); $this->assertSame( array( 'wptests_tax2' ), array_keys( $found ) ); - $this->assertInternalType( 'object', $found['wptests_tax2'] ); + $this->assertIsObject( $found['wptests_tax2'] ); $this->assertSame( 'wptests_tax2', $found['wptests_tax2']->name ); } @@ -143,7 +143,7 @@ public function test_should_return_unique_taxonomies_for_output_objects() { $found = get_attachment_taxonomies( $attachment, 'objects' ); $this->assertSame( array( 'wptests_tax2' ), array_keys( $found ) ); - $this->assertInternalType( 'object', $found['wptests_tax2'] ); + $this->assertIsObject( $found['wptests_tax2'] ); $this->assertSame( 'wptests_tax2', $found['wptests_tax2']->name ); } } diff --git a/tests/phpunit/tests/oembed/controller.php b/tests/phpunit/tests/oembed/controller.php index a0603f961299..16dbde78b6ea 100644 --- a/tests/phpunit/tests/oembed/controller.php +++ b/tests/phpunit/tests/oembed/controller.php @@ -602,7 +602,7 @@ public function test_proxy_with_valid_oembed_provider() { $data = $response->get_data(); $this->assertNotEmpty( $data ); - $this->assertInternalType( 'object', $data ); + $this->assertIsObject( $data ); $this->assertEquals( 'YouTube', $data->provider_name ); $this->assertEquals( 'https://i.ytimg.com/vi/' . self::YOUTUBE_VIDEO_ID . '/hqdefault.jpg', $data->thumbnail_url ); $this->assertEquals( $data->width, $request['maxwidth'] ); @@ -629,7 +629,7 @@ public function test_proxy_with_classic_embed_provider() { $data = $response->get_data(); $this->assertNotEmpty( $data ); - $this->assertInternalType( 'object', $data ); + $this->assertIsObject( $data ); $this->assertInternalType( 'string', $data->html ); $this->assertIsArray( $data->scripts ); } @@ -742,7 +742,7 @@ function test_proxy_with_static_front_page_url() { $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); - $this->assertInternalType( 'object', $data ); + $this->assertIsObject( $data ); $data = (array) $data; @@ -785,7 +785,7 @@ public function test_proxy_filters_result_of_untrusted_oembed_provider() { $data = $response->get_data(); $this->assertEquals( 1, $this->oembed_result_filter_count ); - $this->assertInternalType( 'object', $data ); + $this->assertIsObject( $data ); $this->assertEquals( 'Untrusted', $data->provider_name ); $this->assertEquals( self::UNTRUSTED_PROVIDER_URL, $data->provider_url ); $this->assertEquals( 'rich', $data->type ); @@ -808,7 +808,7 @@ public function test_proxy_does_not_filter_result_of_trusted_oembed_provider() { $data = $response->get_data(); $this->assertEquals( 1, $this->oembed_result_filter_count ); - $this->assertInternalType( 'object', $data ); + $this->assertIsObject( $data ); $this->assertStringStartsWith( 'Unfiltered', $data->html ); } diff --git a/tests/phpunit/tests/post/getPageByPath.php b/tests/phpunit/tests/post/getPageByPath.php index f5fe67b4457a..e31b516054df 100644 --- a/tests/phpunit/tests/post/getPageByPath.php +++ b/tests/phpunit/tests/post/getPageByPath.php @@ -306,7 +306,7 @@ public function test_output_param_should_be_obeyed_for_cached_value() { $this->assertSame( $page, $found->ID ); $object = get_page_by_path( 'foo', OBJECT ); - $this->assertInternalType( 'object', $object ); + $this->assertIsObject( $object ); $this->assertSame( $page, $object->ID ); $array_n = get_page_by_path( 'foo', ARRAY_N ); diff --git a/tests/phpunit/tests/post/getPostTypeLabels.php b/tests/phpunit/tests/post/getPostTypeLabels.php index aff320e64195..27e82b544868 100644 --- a/tests/phpunit/tests/post/getPostTypeLabels.php +++ b/tests/phpunit/tests/post/getPostTypeLabels.php @@ -5,8 +5,7 @@ */ class Tests_Get_Post_Type_Labels extends WP_UnitTestCase { public function test_returns_an_object() { - $this->assertInternalType( - 'object', + $this->assertIsObject( get_post_type_labels( (object) array( 'name' => 'foo', diff --git a/tests/phpunit/tests/post/types.php b/tests/phpunit/tests/post/types.php index a52e9b742926..f49085170e5f 100644 --- a/tests/phpunit/tests/post/types.php +++ b/tests/phpunit/tests/post/types.php @@ -499,8 +499,8 @@ public function test_unregister_post_type_removes_post_type_from_global() { ) ); - $this->assertInternalType( 'object', $wp_post_types['foo'] ); - $this->assertInternalType( 'object', get_post_type_object( 'foo' ) ); + $this->assertIsObject( $wp_post_types['foo'] ); + $this->assertIsObject( get_post_type_object( 'foo' ) ); $this->assertTrue( unregister_post_type( 'foo' ) ); diff --git a/tests/phpunit/tests/taxonomy.php b/tests/phpunit/tests/taxonomy.php index ec39b0a7db0b..020d6ad256a2 100644 --- a/tests/phpunit/tests/taxonomy.php +++ b/tests/phpunit/tests/taxonomy.php @@ -873,8 +873,8 @@ public function test_unregister_taxonomy_removes_taxonomy_from_global() { register_taxonomy( 'foo', 'post' ); - $this->assertInternalType( 'object', $wp_taxonomies['foo'] ); - $this->assertInternalType( 'object', get_taxonomy( 'foo' ) ); + $this->assertIsObject( $wp_taxonomies['foo'] ); + $this->assertIsObject( get_taxonomy( 'foo' ) ); $this->assertTrue( unregister_taxonomy( 'foo' ) ); diff --git a/tests/phpunit/tests/taxonomy/getObjectTaxonomies.php b/tests/phpunit/tests/taxonomy/getObjectTaxonomies.php index 998b179abb5e..3f5289660e3c 100644 --- a/tests/phpunit/tests/taxonomy/getObjectTaxonomies.php +++ b/tests/phpunit/tests/taxonomy/getObjectTaxonomies.php @@ -36,7 +36,7 @@ public function test_should_respect_output_names() { $found = get_object_taxonomies( 'wptests_pt', 'objects' ); $this->assertSame( array( 'wptests_tax' ), array_keys( $found ) ); - $this->assertInternalType( 'object', $found['wptests_tax'] ); + $this->assertIsObject( $found['wptests_tax'] ); $this->assertSame( 'wptests_tax', $found['wptests_tax']->name ); } @@ -87,7 +87,7 @@ public function test_should_respect_output_objects_when_object_is_attachment() { $found = get_object_taxonomies( $attachment, 'objects' ); $this->assertSame( array( 'wptests_tax2' ), array_keys( $found ) ); - $this->assertInternalType( 'object', $found['wptests_tax2'] ); + $this->assertIsObject( $found['wptests_tax2'] ); $this->assertSame( 'wptests_tax2', $found['wptests_tax2']->name ); } } diff --git a/tests/phpunit/tests/term/getTerm.php b/tests/phpunit/tests/term/getTerm.php index 70991248734f..f56a3a4c2a44 100644 --- a/tests/phpunit/tests/term/getTerm.php +++ b/tests/phpunit/tests/term/getTerm.php @@ -97,7 +97,7 @@ public function test_cache_should_be_populated_by_successful_fetch() { public function test_output_object() { $t = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax' ) ); - $this->assertInternalType( 'object', get_term( $t, 'wptests_tax', OBJECT ) ); + $this->assertIsObject( get_term( $t, 'wptests_tax', OBJECT ) ); } public function test_output_array_a() { @@ -119,7 +119,7 @@ public function test_output_array_n() { public function test_output_should_fall_back_to_object_for_invalid_input() { $t = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax' ) ); - $this->assertInternalType( 'object', get_term( $t, 'wptests_tax', 'foo' ) ); + $this->assertIsObject( get_term( $t, 'wptests_tax', 'foo' ) ); } /** diff --git a/tests/phpunit/tests/term/wpGetObjectTerms.php b/tests/phpunit/tests/term/wpGetObjectTerms.php index 075c6a6b4110..e7238526395a 100644 --- a/tests/phpunit/tests/term/wpGetObjectTerms.php +++ b/tests/phpunit/tests/term/wpGetObjectTerms.php @@ -93,7 +93,7 @@ public function test_references_should_be_reset_after_wp_get_object_terms_filter $terms = wp_get_object_terms( $post_id, $this->taxonomy ); remove_filter( 'wp_get_object_terms', array( $this, 'filter_get_object_terms' ) ); foreach ( $terms as $term ) { - $this->assertInternalType( 'object', $term ); + $this->assertIsObject( $term ); } } diff --git a/tests/phpunit/tests/term/wpInsertTerm.php b/tests/phpunit/tests/term/wpInsertTerm.php index 9e3d4c6f6f6a..eb46280a34be 100644 --- a/tests/phpunit/tests/term/wpInsertTerm.php +++ b/tests/phpunit/tests/term/wpInsertTerm.php @@ -900,7 +900,7 @@ public function test_wp_insert_term_with_null_description() { /** Helpers */ public function deleted_term_cb( $term, $tt_id, $taxonomy, $deleted_term, $object_ids ) { - $this->assertInternalType( 'object', $deleted_term ); + $this->assertIsObject( $deleted_term ); $this->assertIsInt( $term ); $this->assertIsArray( $object_ids ); // Pesky string $this->assertIsInt( $tt_id );