Skip to content

Commit

Permalink
Tests: replace assert[Not]InternalType( 'object', $var ) with `asse…
Browse files Browse the repository at this point in the history
…rtIs[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
* sebastianbergmann/phpunit#3368
  • Loading branch information
jrfnl committed Aug 19, 2020
1 parent 1f2d221 commit 725bd04
Show file tree
Hide file tree
Showing 14 changed files with 23 additions and 24 deletions.
2 changes: 1 addition & 1 deletion tests/phpunit/tests/adminbar.php
Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/customize/nav-menu-setting.php
Expand Up @@ -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 ) );
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/db.php
Expand Up @@ -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 );
}

Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/includes/factory.php
Expand Up @@ -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 );
}
}
4 changes: 2 additions & 2 deletions tests/phpunit/tests/media/getAttachmentTaxonomies.php
Expand Up @@ -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 );
}

Expand All @@ -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 );
}
}
10 changes: 5 additions & 5 deletions tests/phpunit/tests/oembed/controller.php
Expand Up @@ -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'] );
Expand All @@ -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 );
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 );
Expand All @@ -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( '<b>Unfiltered</b>', $data->html );
}
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/post/getPageByPath.php
Expand Up @@ -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 );
Expand Down
3 changes: 1 addition & 2 deletions tests/phpunit/tests/post/getPostTypeLabels.php
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/tests/post/types.php
Expand Up @@ -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' ) );

Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/tests/taxonomy.php
Expand Up @@ -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' ) );

Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/tests/taxonomy/getObjectTaxonomies.php
Expand Up @@ -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 );
}

Expand Down Expand Up @@ -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 );
}
}
4 changes: 2 additions & 2 deletions tests/phpunit/tests/term/getTerm.php
Expand Up @@ -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() {
Expand All @@ -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' ) );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/term/wpGetObjectTerms.php
Expand Up @@ -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 );
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/term/wpInsertTerm.php
Expand Up @@ -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 );
Expand Down

0 comments on commit 725bd04

Please sign in to comment.