Skip to content

Commit

Permalink
Tests: replace assert[Not]InternalType( 'int', $var ) with `assertI…
Browse files Browse the repository at this point in the history
…s[Not]Int()`

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 16, 2020
1 parent b03f1bc commit d778cee
Show file tree
Hide file tree
Showing 37 changed files with 100 additions and 100 deletions.
4 changes: 2 additions & 2 deletions tests/phpunit/tests/comment/metaCache.php
Expand Up @@ -233,7 +233,7 @@ public function test_add_metadata_sets_comments_last_changed() {

wp_cache_delete( 'last_changed', 'comment' );

$this->assertInternalType( 'integer', add_metadata( 'comment', $comment_id, 'foo', 'bar' ) );
$this->assertIsInt( add_metadata( 'comment', $comment_id, 'foo', 'bar' ) );
$this->assertNotFalse( wp_cache_get_last_changed( 'comment' ) );
}

Expand All @@ -245,7 +245,7 @@ public function test_update_metadata_sets_comments_last_changed() {

wp_cache_delete( 'last_changed', 'comment' );

$this->assertInternalType( 'integer', update_metadata( 'comment', $comment_id, 'foo', 'bar' ) );
$this->assertIsInt( update_metadata( 'comment', $comment_id, 'foo', 'bar' ) );
$this->assertNotFalse( wp_cache_get_last_changed( 'comment' ) );
}

Expand Down
6 changes: 3 additions & 3 deletions tests/phpunit/tests/comment/query.php
Expand Up @@ -1714,9 +1714,9 @@ function test_fields_ids_query() {
);

// Ensure we are dealing with integers, and not objects.
$this->assertInternalType( 'integer', $comment_1 );
$this->assertInternalType( 'integer', $comment_2 );
$this->assertInternalType( 'integer', $comment_3 );
$this->assertIsInt( $comment_1 );
$this->assertIsInt( $comment_2 );
$this->assertIsInt( $comment_3 );

$comment_ids = get_comments( array( 'fields' => 'ids' ) );
$this->assertCount( 3, $comment_ids );
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/customize/manager.php
Expand Up @@ -731,7 +731,7 @@ function test_import_theme_starter_content() {
$this->assertNull( $wp_customize->changeset_post_id() );
$this->assertEquals( 1000, has_action( 'customize_register', array( $wp_customize, '_save_starter_content_changeset' ) ) );
do_action( 'customize_register', $wp_customize ); // This will trigger the changeset save.
$this->assertInternalType( 'int', $wp_customize->changeset_post_id() );
$this->assertIsInt( $wp_customize->changeset_post_id() );
$this->assertNotEmpty( $wp_customize->changeset_data() );
foreach ( $wp_customize->changeset_data() as $setting_id => $setting_params ) {
$this->assertArrayHasKey( 'starter_content', $setting_params );
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/tests/customize/nav-menu-setting.php
Expand Up @@ -225,7 +225,7 @@ function test_preview_updated() {
$menus = wp_get_nav_menus();
$menus_ids = wp_list_pluck( $menus, 'term_id' );
$i = array_search( $menu_id, $menus_ids, true );
$this->assertInternalType( 'int', $i, 'Update-previewed menu does not appear in wp_get_nav_menus()' );
$this->assertIsInt( $i, 'Update-previewed menu does not appear in wp_get_nav_menus()' );
$filtered_menu = $menus[ $i ];
$this->assertEquals( 'Name 2 \\o/', $filtered_menu->name );
}
Expand Down Expand Up @@ -270,7 +270,7 @@ function test_preview_inserted() {
$menus = wp_get_nav_menus();
$menus_ids = wp_list_pluck( $menus, 'term_id' );
$i = array_search( $menu_id, $menus_ids, true );
$this->assertInternalType( 'int', $i, 'Insert-previewed menu was not injected into wp_get_nav_menus()' );
$this->assertIsInt( $i, 'Insert-previewed menu was not injected into wp_get_nav_menus()' );
$filtered_menu = $menus[ $i ];
$this->assertEquals( 'New Menu Name 1 \\o/', $filtered_menu->name );
}
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/tests/customize/panel.php
Expand Up @@ -31,7 +31,7 @@ function tearDown(): void {
*/
function test_construct_default_args() {
$panel = new WP_Customize_Panel( $this->manager, 'foo' );
$this->assertInternalType( 'int', $panel->instance_number );
$this->assertIsInt( $panel->instance_number );
$this->assertEquals( $this->manager, $panel->manager );
$this->assertEquals( 'foo', $panel->id );
$this->assertEquals( 160, $panel->priority );
Expand Down Expand Up @@ -125,7 +125,7 @@ function test_json() {
}
$this->assertEmpty( $data['content'] );
$this->assertTrue( $data['active'] );
$this->assertInternalType( 'int', $data['instanceNumber'] );
$this->assertIsInt( $data['instanceNumber'] );
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/tests/customize/section.php
Expand Up @@ -38,7 +38,7 @@ function tearDown(): void {
*/
function test_construct_default_args() {
$section = new WP_Customize_Section( $this->manager, 'foo' );
$this->assertInternalType( 'int', $section->instance_number );
$this->assertIsInt( $section->instance_number );
$this->assertEquals( $this->manager, $section->manager );
$this->assertEquals( 'foo', $section->id );
$this->assertEquals( 160, $section->priority );
Expand Down Expand Up @@ -139,7 +139,7 @@ function test_json() {
}
$this->assertEmpty( $data['content'] );
$this->assertTrue( $data['active'] );
$this->assertInternalType( 'int', $data['instanceNumber'] );
$this->assertIsInt( $data['instanceNumber'] );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/date/currentTime.php
Expand Up @@ -98,7 +98,7 @@ public function test_should_return_wp_timestamp() {
$this->assertEquals( $wp_timestamp, current_time( 'U' ), 'The dates should be equal', 2 );

// phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
$this->assertInternalType( 'int', current_time( 'timestamp' ) );
$this->assertIsInt( current_time( 'timestamp' ) );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/image/header.php
Expand Up @@ -147,7 +147,7 @@ function test_insert_cropped_attachment() {

$cropped_id = $this->custom_image_header->insert_attachment( $object, $cropped );

$this->assertInternalType( 'int', $cropped_id );
$this->assertIsInt( $cropped_id );
$this->assertGreaterThan( 0, $cropped_id );
}

Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/image/siteIcon.php
Expand Up @@ -120,7 +120,7 @@ function test_insert_cropped_attachment() {
$object = $this->wp_site_icon->create_attachment_object( $cropped, $attachment_id );
$cropped_id = $this->wp_site_icon->insert_attachment( $object, $cropped );

$this->assertInternalType( 'int', $cropped_id );
$this->assertIsInt( $cropped_id );
$this->assertGreaterThan( 0, $cropped_id );
}

Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/media.php
Expand Up @@ -1132,7 +1132,7 @@ function _upload_dir( $dir ) {
*/
function test_attachment_url_to_postid_with_empty_url() {
$post_id = attachment_url_to_postid( '' );
$this->assertInternalType( 'int', $post_id );
$this->assertIsInt( $post_id );
$this->assertEquals( 0, $post_id );
}

Expand Down
8 changes: 4 additions & 4 deletions tests/phpunit/tests/meta.php
Expand Up @@ -207,11 +207,11 @@ function test_metadata_slashes() {
$this->assertFalse( metadata_exists( 'user', $this->author->ID, $key ) );
$this->assertFalse( delete_metadata( 'user', $this->author->ID, $key ) );
$this->assertSame( '', get_metadata( 'user', $this->author->ID, $key, true ) );
$this->assertInternalType( 'int', add_metadata( 'user', $this->author->ID, $key, $value ) );
$this->assertIsInt( add_metadata( 'user', $this->author->ID, $key, $value ) );
$this->assertEquals( $expected, get_metadata( 'user', $this->author->ID, $key, true ) );
$this->assertTrue( delete_metadata( 'user', $this->author->ID, $key ) );
$this->assertSame( '', get_metadata( 'user', $this->author->ID, $key, true ) );
$this->assertInternalType( 'int', update_metadata( 'user', $this->author->ID, $key, $value ) );
$this->assertIsInt( update_metadata( 'user', $this->author->ID, $key, $value ) );
$this->assertEquals( $expected, get_metadata( 'user', $this->author->ID, $key, true ) );
$this->assertTrue( update_metadata( 'user', $this->author->ID, $key, 'blah' ) );
$this->assertEquals( 'blah', get_metadata( 'user', $this->author->ID, $key, true ) );
Expand All @@ -220,11 +220,11 @@ function test_metadata_slashes() {
$this->assertFalse( metadata_exists( 'user', $this->author->ID, $key ) );

// Test overslashing.
$this->assertInternalType( 'int', add_metadata( 'user', $this->author->ID, $key, $value2 ) );
$this->assertIsInt( add_metadata( 'user', $this->author->ID, $key, $value2 ) );
$this->assertEquals( $expected2, get_metadata( 'user', $this->author->ID, $key, true ) );
$this->assertTrue( delete_metadata( 'user', $this->author->ID, $key ) );
$this->assertSame( '', get_metadata( 'user', $this->author->ID, $key, true ) );
$this->assertInternalType( 'int', update_metadata( 'user', $this->author->ID, $key, $value2 ) );
$this->assertIsInt( update_metadata( 'user', $this->author->ID, $key, $value2 ) );
$this->assertEquals( $expected2, get_metadata( 'user', $this->author->ID, $key, true ) );
}

Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/tests/multisite/network.php
Expand Up @@ -352,7 +352,7 @@ function test_wp_schedule_update_network_counts() {
// We can't use wp_schedule_update_network_counts() because WP_INSTALLING is set.
wp_schedule_event( time(), 'twicedaily', 'update_network_counts' );

$this->assertInternalType( 'int', wp_next_scheduled( 'update_network_counts' ) );
$this->assertIsInt( wp_next_scheduled( 'update_network_counts' ) );
}

/**
Expand All @@ -365,7 +365,7 @@ function test_get_dashboard_blog() {

$user_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
$blog_id = self::factory()->blog->create( array( 'user_id' => $user_id ) );
$this->assertInternalType( 'int', $blog_id );
$this->assertIsInt( $blog_id );

// Set the dashboard blog to another one.
update_site_option( 'dashboard_blog', $blog_id );
Expand Down
12 changes: 6 additions & 6 deletions tests/phpunit/tests/multisite/site.php
Expand Up @@ -94,7 +94,7 @@ function test_switch_restore_blog() {
$this->assertEquals( array(), $_wp_switched_stack );
$this->assertFalse( ms_is_switched() );
$current_blog_id = get_current_blog_id();
$this->assertInternalType( 'integer', $current_blog_id );
$this->assertIsInt( $current_blog_id );

wp_cache_set( 'switch-test', $current_blog_id, 'switch-test' );
$this->assertEquals( $current_blog_id, wp_cache_get( 'switch-test', 'switch-test' ) );
Expand Down Expand Up @@ -141,7 +141,7 @@ function test_created_site_details() {

$blog_id = self::factory()->blog->create();

$this->assertInternalType( 'int', $blog_id );
$this->assertIsInt( $blog_id );
$prefix = $wpdb->get_blog_prefix( $blog_id );

// $get_all = false, only retrieve details from the blogs table.
Expand Down Expand Up @@ -1298,7 +1298,7 @@ public function test_wp_insert_site( $site_data, $expected_data ) {
remove_action( 'wp_initialize_site', 'wp_initialize_site', 10 );
$site_id = wp_insert_site( $site_data );

$this->assertInternalType( 'integer', $site_id );
$this->assertIsInt( $site_id );

$site = get_site( $site_id );
foreach ( $expected_data as $key => $value ) {
Expand Down Expand Up @@ -1404,7 +1404,7 @@ public function test_wp_insert_site_with_clean_site_cache() {

remove_action( 'clean_site_cache', array( $this, 'action_database_insert_on_clean_site_cache' ) );

$this->assertInternalType( 'integer', $site_id );
$this->assertIsInt( $site_id );

}

Expand Down Expand Up @@ -1789,15 +1789,15 @@ public function test_site_dates_are_gmt() {
'network_id' => 1,
)
);
$this->assertInternalType( 'integer', $site_id );
$this->assertIsInt( $site_id );

$site = get_site( $site_id );
$this->assertEquals( strtotime( $first_date ), strtotime( $site->registered ), 'The dates should be equal', 2 );
$this->assertEquals( strtotime( $first_date ), strtotime( $site->last_updated ), 'The dates should be equal', 2 );

$second_date = current_time( 'mysql', true );
$site_id = wp_update_site( $site_id, array() );
$this->assertInternalType( 'integer', $site_id );
$this->assertIsInt( $site_id );

$site = get_site( $site_id );
$this->assertEquals( strtotime( $first_date ), strtotime( $site->registered ), 'The dates should be equal', 2 );
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/multisite/siteMeta.php
Expand Up @@ -157,7 +157,7 @@ public function test_update_should_pass_to_add_when_no_value_exists_for_key() {
}

$actual = update_site_meta( self::$site_id, 'foo', 'bar' );
$this->assertInternalType( 'int', $actual );
$this->assertIsInt( $actual );
$this->assertNotEmpty( $actual );

$meta = get_site_meta( self::$site_id, 'foo', true );
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/tests/option/multisite.php
Expand Up @@ -99,15 +99,15 @@ function test_from_same_site_with_null_blog_id() {

function test_with_another_site() {
$user_id = self::factory()->user->create();
$this->assertInternalType( 'integer', $user_id );
$this->assertIsInt( $user_id );

$blog_id = self::factory()->blog->create(
array(
'user_id' => $user_id,
'public' => 1,
)
);
$this->assertInternalType( 'integer', $blog_id );
$this->assertIsInt( $blog_id );

$key = __FUNCTION__ . '_key1';
$key2 = __FUNCTION__ . '_key2';
Expand Down
40 changes: 20 additions & 20 deletions tests/phpunit/tests/post/meta.php
Expand Up @@ -46,7 +46,7 @@ public static function wpTearDownAfterClass() {

function test_unique_postmeta() {
// Add a unique post meta item.
$this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'unique', 'value', true ) );
$this->assertIsInt( add_post_meta( self::$post_id, 'unique', 'value', true ) );

// Check unique is enforced.
$this->assertFalse( add_post_meta( self::$post_id, 'unique', 'another value', true ) );
Expand All @@ -69,8 +69,8 @@ function test_unique_postmeta() {

function test_nonunique_postmeta() {
// Add two non-unique post meta items.
$this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'nonunique', 'value' ) );
$this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'nonunique', 'another value' ) );
$this->assertIsInt( add_post_meta( self::$post_id, 'nonunique', 'value' ) );
$this->assertIsInt( add_post_meta( self::$post_id, 'nonunique', 'another value' ) );

// Check they exist.
$this->assertEquals( 'value', get_post_meta( self::$post_id, 'nonunique', true ) );
Expand All @@ -87,7 +87,7 @@ function test_nonunique_postmeta() {
$this->assertEquals( array( 'another value' ), get_post_meta( self::$post_id, 'nonunique', false ) );

// Add a third one.
$this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'nonunique', 'someother value' ) );
$this->assertIsInt( add_post_meta( self::$post_id, 'nonunique', 'someother value' ) );

// Check they exist.
$expected = array(
Expand All @@ -106,11 +106,11 @@ function test_nonunique_postmeta() {

function test_update_post_meta() {
// Add a unique post meta item.
$this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'unique_update', 'value', true ) );
$this->assertIsInt( add_post_meta( self::$post_id, 'unique_update', 'value', true ) );

// Add two non-unique post meta items.
$this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'nonunique_update', 'value' ) );
$this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'nonunique_update', 'another value' ) );
$this->assertIsInt( add_post_meta( self::$post_id, 'nonunique_update', 'value' ) );
$this->assertIsInt( add_post_meta( self::$post_id, 'nonunique_update', 'another value' ) );

// Check they exist.
$this->assertEquals( 'value', get_post_meta( self::$post_id, 'unique_update', true ) );
Expand All @@ -133,8 +133,8 @@ function test_update_post_meta() {

function test_delete_post_meta() {
// Add two unique post meta items.
$this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'unique_delete', 'value', true ) );
$this->assertInternalType( 'integer', add_post_meta( self::$post_id_2, 'unique_delete', 'value', true ) );
$this->assertIsInt( add_post_meta( self::$post_id, 'unique_delete', 'value', true ) );
$this->assertIsInt( add_post_meta( self::$post_id_2, 'unique_delete', 'value', true ) );

// Check they exist.
$this->assertEquals( 'value', get_post_meta( self::$post_id, 'unique_delete', true ) );
Expand All @@ -150,8 +150,8 @@ function test_delete_post_meta() {

function test_delete_post_meta_by_key() {
// Add two unique post meta items.
$this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'unique_delete_by_key', 'value', true ) );
$this->assertInternalType( 'integer', add_post_meta( self::$post_id_2, 'unique_delete_by_key', 'value', true ) );
$this->assertIsInt( add_post_meta( self::$post_id, 'unique_delete_by_key', 'value', true ) );
$this->assertIsInt( add_post_meta( self::$post_id_2, 'unique_delete_by_key', 'value', true ) );

// Check they exist.
$this->assertEquals( 'value', get_post_meta( self::$post_id, 'unique_delete_by_key', true ) );
Expand All @@ -167,7 +167,7 @@ function test_delete_post_meta_by_key() {

function test_get_post_meta_by_id() {
$mid = add_post_meta( self::$post_id, 'get_post_meta_by_key', 'get_post_meta_by_key_value', true );
$this->assertInternalType( 'integer', $mid );
$this->assertIsInt( $mid );

$mobj = new stdClass;
$mobj->meta_id = $mid;
Expand All @@ -178,7 +178,7 @@ function test_get_post_meta_by_id() {
delete_metadata_by_mid( 'post', $mid );

$mid = add_post_meta( self::$post_id, 'get_post_meta_by_key', array( 'foo', 'bar' ), true );
$this->assertInternalType( 'integer', $mid );
$this->assertIsInt( $mid );
$mobj->meta_id = $mid;
$mobj->meta_value = array( 'foo', 'bar' );
$this->assertEquals( $mobj, get_post_meta_by_id( $mid ) );
Expand All @@ -187,7 +187,7 @@ function test_get_post_meta_by_id() {

function test_delete_meta() {
$mid = add_post_meta( self::$post_id, 'delete_meta', 'delete_meta_value', true );
$this->assertInternalType( 'integer', $mid );
$this->assertIsInt( $mid );

$this->assertTrue( delete_meta( $mid ) );
$this->assertFalse( get_metadata_by_mid( 'post', $mid ) );
Expand All @@ -197,11 +197,11 @@ function test_delete_meta() {

function test_update_meta() {
// Add a unique post meta item.
$this->assertInternalType( 'integer', $mid1 = add_post_meta( self::$post_id, 'unique_update', 'value', true ) );
$this->assertIsInt( $mid1 = add_post_meta( self::$post_id, 'unique_update', 'value', true ) );

// Add two non-unique post meta items.
$this->assertInternalType( 'integer', $mid2 = add_post_meta( self::$post_id, 'nonunique_update', 'value' ) );
$this->assertInternalType( 'integer', $mid3 = add_post_meta( self::$post_id, 'nonunique_update', 'another value' ) );
$this->assertIsInt( $mid2 = add_post_meta( self::$post_id, 'nonunique_update', 'value' ) );
$this->assertIsInt( $mid3 = add_post_meta( self::$post_id, 'nonunique_update', 'another value' ) );

// Check they exist.
$this->assertEquals( 'value', get_post_meta( self::$post_id, 'unique_update', true ) );
Expand Down Expand Up @@ -242,7 +242,7 @@ function test_funky_post_meta() {
$funky_meta[] = $classy;

// Add a post meta item.
$this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'test_funky_post_meta', $funky_meta, true ) );
$this->assertIsInt( add_post_meta( self::$post_id, 'test_funky_post_meta', $funky_meta, true ) );

// Check it exists.
$this->assertEquals( $funky_meta, get_post_meta( self::$post_id, 'test_funky_post_meta', true ) );
Expand Down Expand Up @@ -318,7 +318,7 @@ public function test_add_metadata_sets_posts_last_changed() {

wp_cache_delete( 'last_changed', 'posts' );

$this->assertInternalType( 'integer', add_metadata( 'post', $post_id, 'foo', 'bar' ) );
$this->assertIsInt( add_metadata( 'post', $post_id, 'foo', 'bar' ) );
$this->assertNotFalse( wp_cache_get_last_changed( 'posts' ) );
}

Expand All @@ -330,7 +330,7 @@ public function test_update_metadata_sets_posts_last_changed() {

wp_cache_delete( 'last_changed', 'posts' );

$this->assertInternalType( 'integer', update_metadata( 'post', $post_id, 'foo', 'bar' ) );
$this->assertIsInt( update_metadata( 'post', $post_id, 'foo', 'bar' ) );
$this->assertNotFalse( wp_cache_get_last_changed( 'posts' ) );
}

Expand Down

0 comments on commit d778cee

Please sign in to comment.