Skip to content

Commit

Permalink
Tests: replace assert[Not]InternalType( 'string', $var ) with `asse…
Browse files Browse the repository at this point in the history
…rtIs[Not]String()`

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 f746feb commit 46a80bf
Show file tree
Hide file tree
Showing 26 changed files with 179 additions and 179 deletions.
2 changes: 1 addition & 1 deletion tests/phpunit/tests/blocks/render.php
Expand Up @@ -324,7 +324,7 @@ public function test_dynamic_block_renders_string() {
$rendered = $block_type->render();

$this->assertSame( '10', $rendered );
$this->assertInternalType( 'string', $rendered );
$this->assertIsString( $rendered );
}

public function test_dynamic_block_gets_inner_html() {
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/tests/customize/manager.php
Expand Up @@ -2909,7 +2909,7 @@ function action_customize_register_for_dynamic_settings() {
* @return array
*/
function filter_customize_dynamic_setting_args_for_test_dynamic_settings( $setting_args, $setting_id ) {
$this->assertInternalType( 'string', $setting_id );
$this->assertIsString( $setting_id );
if ( in_array( $setting_id, array( 'foo', 'bar' ), true ) ) {
$setting_args = array( 'default' => "dynamic_{$setting_id}_default" );
}
Expand All @@ -2926,7 +2926,7 @@ function filter_customize_dynamic_setting_args_for_test_dynamic_settings( $setti
*/
function filter_customize_dynamic_setting_class_for_test_dynamic_settings( $setting_class, $setting_id, $setting_args ) {
$this->assertEquals( 'WP_Customize_Setting', $setting_class );
$this->assertInternalType( 'string', $setting_id );
$this->assertIsString( $setting_id );
$this->assertIsArray( $setting_args );
return $setting_class;
}
Expand Down
6 changes: 3 additions & 3 deletions tests/phpunit/tests/customize/selective-refresh.php
Expand Up @@ -208,7 +208,7 @@ function test_add_dynamic_partials() {
*/
function filter_customize_dynamic_partial_args( $partial_args, $partial_id ) {
$this->assertTrue( false === $partial_args || is_array( $partial_args ) );
$this->assertInternalType( 'string', $partial_id );
$this->assertIsString( $partial_id );

if ( preg_match( '/^recognized/', $partial_id ) ) {
$partial_args = array(
Expand All @@ -231,8 +231,8 @@ function filter_customize_dynamic_partial_args( $partial_args, $partial_id ) {
*/
function filter_customize_dynamic_partial_class( $partial_class, $partial_id, $partial_args ) {
$this->assertIsArray( $partial_args );
$this->assertInternalType( 'string', $partial_id );
$this->assertInternalType( 'string', $partial_class );
$this->assertIsString( $partial_id );
$this->assertIsString( $partial_class );

if ( 'recognized-class' === $partial_id ) {
$partial_class = 'Tested_Custom_Partial';
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/customize/setting.php
Expand Up @@ -730,7 +730,7 @@ public function test_validate() {
*/
public function filter_validate_for_test_validate( $validity, $value ) {
$this->assertInstanceOf( 'WP_Error', $validity );
$this->assertInternalType( 'string', $value );
$this->assertIsString( $value );
if ( sanitize_key( $value ) !== $value ) {
$validity->add( 'invalid_key', 'Invalid key' );
}
Expand Down
6 changes: 3 additions & 3 deletions tests/phpunit/tests/functions.php
Expand Up @@ -80,8 +80,8 @@ function test_wp_parse_args_other() {
*/
function test_wp_parse_args_boolean_strings() {
$args = wp_parse_args( 'foo=false&bar=true' );
$this->assertInternalType( 'string', $args['foo'] );
$this->assertInternalType( 'string', $args['bar'] );
$this->assertIsString( $args['foo'] );
$this->assertIsString( $args['bar'] );
}

/**
Expand Down Expand Up @@ -1179,7 +1179,7 @@ function test_wp_unique_id() {
$ids = array();
for ( $i = 0; $i < 20; $i += 1 ) {
$id = wp_unique_id();
$this->assertInternalType( 'string', $id );
$this->assertIsString( $id );
$this->assertTrue( is_numeric( $id ) );
$ids[] = $id;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/functions/wpRemoteFopen.php
Expand Up @@ -28,7 +28,7 @@ public function test_wp_remote_fopen() {
$url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
$response = wp_remote_fopen( $url );

$this->assertInternalType( 'string', $response );
$this->assertIsString( $response );
$this->assertEquals( 40148, strlen( $response ) );
}
}
24 changes: 12 additions & 12 deletions tests/phpunit/tests/general/archives.php
Expand Up @@ -29,7 +29,7 @@ function test_get_archives_cache() {
'echo' => false,
)
);
$this->assertInternalType( 'string', $result );
$this->assertIsString( $result );
$time1 = wp_cache_get( 'last_changed', 'posts' );
$this->assertNotEmpty( $time1 );
$this->assertEquals( $num_queries + 1, $wpdb->num_queries );
Expand All @@ -43,7 +43,7 @@ function test_get_archives_cache() {
'echo' => false,
)
);
$this->assertInternalType( 'string', $result );
$this->assertIsString( $result );
$this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
$this->assertEquals( $num_queries, $wpdb->num_queries );

Expand All @@ -55,7 +55,7 @@ function test_get_archives_cache() {
'order' => 'ASC',
)
);
$this->assertInternalType( 'string', $result );
$this->assertIsString( $result );
$this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
$this->assertEquals( $num_queries + 1, $wpdb->num_queries );

Expand All @@ -69,7 +69,7 @@ function test_get_archives_cache() {
'order' => 'ASC',
)
);
$this->assertInternalType( 'string', $result );
$this->assertIsString( $result );
$this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
$this->assertEquals( $num_queries, $wpdb->num_queries );

Expand All @@ -82,7 +82,7 @@ function test_get_archives_cache() {
'echo' => false,
)
);
$this->assertInternalType( 'string', $result );
$this->assertIsString( $result );
$this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
$this->assertEquals( $num_queries + 1, $wpdb->num_queries );

Expand All @@ -95,7 +95,7 @@ function test_get_archives_cache() {
'echo' => false,
)
);
$this->assertInternalType( 'string', $result );
$this->assertIsString( $result );
$this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
$this->assertEquals( $num_queries, $wpdb->num_queries );

Expand All @@ -106,7 +106,7 @@ function test_get_archives_cache() {
'echo' => false,
)
);
$this->assertInternalType( 'string', $result );
$this->assertIsString( $result );
$this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
$this->assertEquals( $num_queries + 1, $wpdb->num_queries );

Expand All @@ -119,7 +119,7 @@ function test_get_archives_cache() {
'echo' => false,
)
);
$this->assertInternalType( 'string', $result );
$this->assertIsString( $result );
$this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
$this->assertEquals( $num_queries, $wpdb->num_queries );

Expand All @@ -130,7 +130,7 @@ function test_get_archives_cache() {
'echo' => false,
)
);
$this->assertInternalType( 'string', $result );
$this->assertIsString( $result );
$this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
$this->assertEquals( $num_queries + 1, $wpdb->num_queries );

Expand All @@ -143,7 +143,7 @@ function test_get_archives_cache() {
'echo' => false,
)
);
$this->assertInternalType( 'string', $result );
$this->assertIsString( $result );
$this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
$this->assertEquals( $num_queries, $wpdb->num_queries );

Expand All @@ -154,7 +154,7 @@ function test_get_archives_cache() {
'echo' => false,
)
);
$this->assertInternalType( 'string', $result );
$this->assertIsString( $result );
$this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
$this->assertEquals( $num_queries + 1, $wpdb->num_queries );

Expand All @@ -167,7 +167,7 @@ function test_get_archives_cache() {
'echo' => false,
)
);
$this->assertInternalType( 'string', $result );
$this->assertIsString( $result );
$this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
$this->assertEquals( $num_queries, $wpdb->num_queries );
}
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/general/template.php
Expand Up @@ -290,7 +290,7 @@ function test_get_custom_logo() {
$this->_set_custom_logo();
$custom_logo = get_custom_logo();
$this->assertNotEmpty( $custom_logo );
$this->assertInternalType( 'string', $custom_logo );
$this->assertIsString( $custom_logo );

$this->_remove_custom_logo();
$this->assertEmpty( get_custom_logo() );
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/tests/oembed/controller.php
Expand Up @@ -168,7 +168,7 @@ public function filter_oembed_result( $data, $url, $args ) {
if ( ! is_string( $data ) && false !== $data ) {
$this->fail( 'Unexpected type for $data.' );
}
$this->assertInternalType( 'string', $url );
$this->assertIsString( $url );
$this->assertIsArray( $args );
$this->oembed_result_filter_count++;
return $data;
Expand Down Expand Up @@ -630,7 +630,7 @@ public function test_proxy_with_classic_embed_provider() {

$this->assertNotEmpty( $data );
$this->assertIsObject( $data );
$this->assertInternalType( 'string', $data->html );
$this->assertIsString( $data->html );
$this->assertIsArray( $data->scripts );
}

Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/post/objects.php
Expand Up @@ -148,7 +148,7 @@ function test_get_page_template_property() {
$post_id = self::factory()->post->create();
$post = get_post( $post_id );

$this->assertInternalType( 'string', $post->page_template );
$this->assertIsString( $post->page_template );
$template = get_post_meta( $post->ID, '_wp_page_template', true );
$this->assertEquals( $template, $post->page_template );
update_post_meta( $post_id, '_wp_page_template', 'foo.php' );
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/rest-api/rest-post-meta-fields.php
Expand Up @@ -395,7 +395,7 @@ public function test_get_value_types() {
$meta = (array) $data['meta'];

$this->assertArrayHasKey( 'test_string', $meta );
$this->assertInternalType( 'string', $meta['test_string'] );
$this->assertIsString( $meta['test_string'] );
$this->assertSame( '42', $meta['test_string'] );

$this->assertArrayHasKey( 'test_number', $meta );
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/rest-api/rest-term-meta-fields.php
Expand Up @@ -342,7 +342,7 @@ public function test_get_value_types() {
$meta = (array) $data['meta'];

$this->assertArrayHasKey( 'test_string', $meta );
$this->assertInternalType( 'string', $meta['test_string'] );
$this->assertIsString( $meta['test_string'] );
$this->assertSame( '42', $meta['test_string'] );

$this->assertArrayHasKey( 'test_number', $meta );
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/tests/rest-api/rest-users-controller.php
Expand Up @@ -1219,7 +1219,7 @@ public function test_create_item_invalid_username() {
} else {
$this->assertIsArray( $data['data']['params'] );
$errors = $data['data']['params'];
$this->assertInternalType( 'string', $errors['username'] );
$this->assertIsString( $errors['username'] );
$this->assertEquals( 'This username is invalid because it uses illegal characters. Please enter a valid username.', $errors['username'] );
}
}
Expand Down Expand Up @@ -1259,7 +1259,7 @@ public function test_create_item_illegal_username() {
$data = $response->get_data();
$this->assertIsArray( $data['data']['params'] );
$errors = $data['data']['params'];
$this->assertInternalType( 'string', $errors['username'] );
$this->assertIsString( $errors['username'] );
$this->assertEquals( 'Sorry, that username is not allowed.', $errors['username'] );
}

Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/tests/term/termExists.php
Expand Up @@ -234,7 +234,7 @@ public function test_term_exists_taxonomy_empty_parent_empty_match_slug() {

_unregister_taxonomy( 'foo' );

$this->assertInternalType( 'string', $found );
$this->assertIsString( $found );
$this->assertEquals( $t, $found );
}

Expand All @@ -252,7 +252,7 @@ public function test_term_exists_taxonomy_empty_parent_empty_match_name() {

_unregister_taxonomy( 'foo' );

$this->assertInternalType( 'string', $found );
$this->assertIsString( $found );
$this->assertEquals( $t, $found );
}

Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/tests/theme/getThemeStarterContent.php
Expand Up @@ -144,7 +144,7 @@ function test_default_content_sections() {
foreach ( $hydrated_starter_content['widgets']['sidebar-1'] as $widget ) {
$this->assertIsArray( $widget );
$this->assertCount( 2, $widget );
$this->assertInternalType( 'string', $widget[0] );
$this->assertIsString( $widget[0] );
$this->assertIsArray( $widget[1] );
$this->assertArrayHasKey( 'title', $widget[1] );
}
Expand All @@ -158,7 +158,7 @@ function test_default_content_sections() {
$this->assertEquals( 'Email Us', $hydrated_starter_content['nav_menus']['top']['items'][4]['title'], 'Core content extended' );

foreach ( $hydrated_starter_content['posts'] as $key => $post ) {
$this->assertInternalType( 'string', $key );
$this->assertIsString( $key );
$this->assertFalse( is_numeric( $key ) );
$this->assertIsArray( $post );
$this->assertArrayHasKey( 'post_type', $post );
Expand Down
30 changes: 15 additions & 15 deletions tests/phpunit/tests/xmlrpc/mw/getPost.php
Expand Up @@ -52,26 +52,26 @@ function test_valid_post() {
$this->assertNotIXRError( $result );

// Check data types.
$this->assertInternalType( 'string', $result['userid'] );
$this->assertIsString( $result['userid'] );
$this->assertIsInt( $result['postid'] );
$this->assertInternalType( 'string', $result['description'] );
$this->assertInternalType( 'string', $result['title'] );
$this->assertInternalType( 'string', $result['link'] );
$this->assertInternalType( 'string', $result['permaLink'] );
$this->assertIsString( $result['description'] );
$this->assertIsString( $result['title'] );
$this->assertIsString( $result['link'] );
$this->assertIsString( $result['permaLink'] );
$this->assertIsArray( $result['categories'] );
$this->assertInternalType( 'string', $result['mt_excerpt'] );
$this->assertInternalType( 'string', $result['mt_text_more'] );
$this->assertInternalType( 'string', $result['wp_more_text'] );
$this->assertIsString( $result['mt_excerpt'] );
$this->assertIsString( $result['mt_text_more'] );
$this->assertIsString( $result['wp_more_text'] );
$this->assertIsInt( $result['mt_allow_comments'] );
$this->assertIsInt( $result['mt_allow_pings'] );
$this->assertInternalType( 'string', $result['mt_keywords'] );
$this->assertInternalType( 'string', $result['wp_slug'] );
$this->assertInternalType( 'string', $result['wp_password'] );
$this->assertInternalType( 'string', $result['wp_author_id'] );
$this->assertInternalType( 'string', $result['wp_author_display_name'] );
$this->assertInternalType( 'string', $result['post_status'] );
$this->assertIsString( $result['mt_keywords'] );
$this->assertIsString( $result['wp_slug'] );
$this->assertIsString( $result['wp_password'] );
$this->assertIsString( $result['wp_author_id'] );
$this->assertIsString( $result['wp_author_display_name'] );
$this->assertIsString( $result['post_status'] );
$this->assertIsArray( $result['custom_fields'] );
$this->assertInternalType( 'string', $result['wp_post_format'] );
$this->assertIsString( $result['wp_post_format'] );
$this->assertIsBool( $result['sticky'] );

$post_data = get_post( self::$post_id );
Expand Down
34 changes: 17 additions & 17 deletions tests/phpunit/tests/xmlrpc/mw/getRecentPosts.php
Expand Up @@ -58,26 +58,26 @@ function test_valid_post() {
$post = get_post( $result['postid'] );

// Check data types.
$this->assertInternalType( 'string', $result['userid'] );
$this->assertInternalType( 'string', $result['postid'] );
$this->assertInternalType( 'string', $result['description'] );
$this->assertInternalType( 'string', $result['title'] );
$this->assertInternalType( 'string', $result['link'] );
$this->assertInternalType( 'string', $result['permaLink'] );
$this->assertIsString( $result['userid'] );
$this->assertIsString( $result['postid'] );
$this->assertIsString( $result['description'] );
$this->assertIsString( $result['title'] );
$this->assertIsString( $result['link'] );
$this->assertIsString( $result['permaLink'] );
$this->assertIsArray( $result['categories'] );
$this->assertInternalType( 'string', $result['mt_excerpt'] );
$this->assertInternalType( 'string', $result['mt_text_more'] );
$this->assertInternalType( 'string', $result['wp_more_text'] );
$this->assertIsString( $result['mt_excerpt'] );
$this->assertIsString( $result['mt_text_more'] );
$this->assertIsString( $result['wp_more_text'] );
$this->assertIsInt( $result['mt_allow_comments'] );
$this->assertIsInt( $result['mt_allow_pings'] );
$this->assertInternalType( 'string', $result['mt_keywords'] );
$this->assertInternalType( 'string', $result['wp_slug'] );
$this->assertInternalType( 'string', $result['wp_password'] );
$this->assertInternalType( 'string', $result['wp_author_id'] );
$this->assertInternalType( 'string', $result['wp_author_display_name'] );
$this->assertInternalType( 'string', $result['post_status'] );
$this->assertIsString( $result['mt_keywords'] );
$this->assertIsString( $result['wp_slug'] );
$this->assertIsString( $result['wp_password'] );
$this->assertIsString( $result['wp_author_id'] );
$this->assertIsString( $result['wp_author_display_name'] );
$this->assertIsString( $result['post_status'] );
$this->assertIsArray( $result['custom_fields'] );
$this->assertInternalType( 'string', $result['wp_post_format'] );
$this->assertIsString( $result['wp_post_format'] );

// Check expected values.
$this->assertStringMatchesFormat( '%d', $result['userid'] );
Expand Down Expand Up @@ -106,7 +106,7 @@ function test_post_thumbnail() {
$this->assertNotIXRError( $results );

foreach ( $results as $result ) {
$this->assertInternalType( 'string', $result['wp_post_thumbnail'] );
$this->assertIsString( $result['wp_post_thumbnail'] );
$this->assertStringMatchesFormat( '%d', $result['wp_post_thumbnail'] );

if ( ! empty( $result['wp_post_thumbnail'] ) || $result['postid'] === self::$post_id ) {
Expand Down

0 comments on commit 46a80bf

Please sign in to comment.