Skip to content

Commit

Permalink
Tests: replace assert[Not]InternalType( 'array', $var ) with `asser…
Browse files Browse the repository at this point in the history
…tIs[Not]Array()`

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 548ef78 commit ca343ca
Show file tree
Hide file tree
Showing 62 changed files with 197 additions and 197 deletions.
4 changes: 2 additions & 2 deletions tests/phpunit/tests/ajax/CustomizeManager.php
Expand Up @@ -286,7 +286,7 @@ function test_save_success_publish_create() {
);
$this->make_ajax_call( 'customize_save' );
$this->assertTrue( $this->_last_response_parsed['success'] );
$this->assertInternalType( 'array', $this->_last_response_parsed['data'] );
$this->assertIsArray( $this->_last_response_parsed['data'] );

$this->assertEquals( 'publish', $this->_last_response_parsed['data']['changeset_status'] );
$this->assertArrayHasKey( 'next_changeset_uuid', $this->_last_response_parsed['data'] );
Expand Down Expand Up @@ -325,7 +325,7 @@ function test_save_success_publish_edit() {
$_POST['customize_changeset_title'] = 'Published';
$this->make_ajax_call( 'customize_save' );
$this->assertTrue( $this->_last_response_parsed['success'] );
$this->assertInternalType( 'array', $this->_last_response_parsed['data'] );
$this->assertIsArray( $this->_last_response_parsed['data'] );

$this->assertEquals( 'publish', $this->_last_response_parsed['data']['changeset_status'] );
$this->assertArrayHasKey( 'next_changeset_uuid', $this->_last_response_parsed['data'] );
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/tests/comment/query.php
Expand Up @@ -3332,9 +3332,9 @@ public function test_comment_query_object() {
$this->assertNull( $query1->query_vars );
$this->assertEmpty( $query1->comments );
$comments = $query1->query( array( 'status' => 'all' ) );
$this->assertInternalType( 'array', $query1->query_vars );
$this->assertIsArray( $query1->query_vars );
$this->assertNotEmpty( $query1->comments );
$this->assertInternalType( 'array', $query1->comments );
$this->assertIsArray( $query1->comments );

$query2 = new WP_Comment_Query( array( 'status' => 'all' ) );
$this->assertNotEmpty( $query2->query_vars );
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/tests/customize/custom-css-setting.php
Expand Up @@ -344,10 +344,10 @@ function test_update_filter() {
* @return array Data.
*/
function filter_update_custom_css_data( $data, $args ) {
$this->assertInternalType( 'array', $data );
$this->assertIsArray( $data );
$this->assertEqualSets( array( 'css', 'preprocessed' ), array_keys( $data ) );
$this->assertEquals( '', $data['preprocessed'] );
$this->assertInternalType( 'array', $args );
$this->assertIsArray( $args );
$this->assertEqualSets( array( 'css', 'preprocessed', 'stylesheet' ), array_keys( $args ) );
$this->assertEquals( $args['css'], $data['css'] );
$this->assertEquals( $args['preprocessed'], $data['preprocessed'] );
Expand Down
42 changes: 21 additions & 21 deletions tests/phpunit/tests/customize/manager.php
Expand Up @@ -677,9 +677,9 @@ function test_import_theme_starter_content() {
$this->assertEqualSets( $expected_setting_ids, array_keys( $changeset_values ) );

foreach ( array( 'widget_text[2]', 'widget_meta[3]' ) as $setting_id ) {
$this->assertInternalType( 'array', $changeset_values[ $setting_id ] );
$this->assertIsArray( $changeset_values[ $setting_id ] );
$instance_data = $wp_customize->widgets->sanitize_widget_instance( $changeset_values[ $setting_id ] );
$this->assertInternalType( 'array', $instance_data );
$this->assertIsArray( $instance_data );
$this->assertArrayHasKey( 'title', $instance_data );
}

Expand Down Expand Up @@ -787,7 +787,7 @@ function test_import_theme_starter_content() {
$this->assertEquals( 'auto-draft', get_post( $posts_by_name['waffles'] )->post_status );
$this->assertNotEquals( $changeset_data['blogname']['value'], get_option( 'blogname' ) );
$r = $wp_customize->save_changeset_post( array( 'status' => 'publish' ) );
$this->assertInternalType( 'array', $r );
$this->assertIsArray( $r );
$this->assertEquals( 'publish', get_post( $posts_by_name['about'] )->post_status );
$this->assertEquals( 'inherit', get_post( $posts_by_name['waffles'] )->post_status );
$this->assertEquals( $changeset_data['blogname']['value'], get_option( 'blogname' ) );
Expand Down Expand Up @@ -1041,7 +1041,7 @@ function test_save_changeset_post_without_theme_activation() {
'data' => $pre_saved_data,
)
);
$this->assertInternalType( 'array', $r );
$this->assertIsArray( $r );

$this->assertEquals( $did_action['customize_save_validation_before'] + 1, did_action( 'customize_save_validation_before' ) );

Expand Down Expand Up @@ -1098,7 +1098,7 @@ function test_save_changeset_post_without_theme_activation() {
);
$this->assertInstanceOf( 'WP_Error', $r );
$this->assertEquals( 'transaction_fail', $r->get_error_code() );
$this->assertInternalType( 'array', $r->get_error_data() );
$this->assertIsArray( $r->get_error_data() );
$this->assertArrayHasKey( 'setting_validities', $r->get_error_data() );
$error_data = $r->get_error_data();
$this->assertArrayHasKey( 'blogname', $error_data['setting_validities'] );
Expand Down Expand Up @@ -1137,7 +1137,7 @@ function test_save_changeset_post_without_theme_activation() {
),
)
);
$this->assertInternalType( 'array', $r );
$this->assertIsArray( $r );
$this->assertArrayHasKey( 'setting_validities', $r );
$this->assertTrue( $r['setting_validities']['blogname'] );
$this->assertInstanceOf( 'WP_Error', $r['setting_validities']['bar_unknown'] );
Expand Down Expand Up @@ -1204,7 +1204,7 @@ function test_save_changeset_post_without_theme_activation() {
),
)
);
$this->assertInternalType( 'array', $r );
$this->assertIsArray( $r );
$this->assertEquals( 'Do it live \o/', get_option( 'blogname' ) );
$this->assertEquals( 'trash', get_post_status( $post_id ) ); // Auto-trashed.
$this->assertEquals( $original_capabilities, wp_list_pluck( $manager->settings(), 'capability' ) );
Expand Down Expand Up @@ -1421,8 +1421,8 @@ public function filter_map_meta_cap_to_disallow_unfiltered_html( $caps, $cap ) {
*/
function filter_customize_changeset_save_data( $data, $context ) {
$this->customize_changeset_save_data_call_count += 1;
$this->assertInternalType( 'array', $data );
$this->assertInternalType( 'array', $context );
$this->assertIsArray( $data );
$this->assertIsArray( $context );
$this->assertArrayHasKey( 'uuid', $context );
$this->assertArrayHasKey( 'title', $context );
$this->assertArrayHasKey( 'status', $context );
Expand Down Expand Up @@ -1512,7 +1512,7 @@ function test_save_changeset_post_with_varying_users() {
),
)
);
$this->assertInternalType( 'array', $r );
$this->assertIsArray( $r );
$this->assertEquals(
array_fill_keys( array( 'blogname', 'scratchpad', 'background_color' ), true ),
$r['setting_validities']
Expand All @@ -1539,7 +1539,7 @@ function test_save_changeset_post_with_varying_users() {
),
)
);
$this->assertInternalType( 'array', $r );
$this->assertIsArray( $r );
$this->assertEquals(
array_fill_keys( array( 'blogname', 'background_color' ), true ),
$r['setting_validities']
Expand Down Expand Up @@ -1568,7 +1568,7 @@ function test_save_changeset_post_with_varying_users() {
'user_id' => self::$subscriber_user_id,
)
);
$this->assertInternalType( 'array', $r );
$this->assertIsArray( $r );
$this->assertEquals(
array_fill_keys( array( 'scratchpad', 'blogname' ), true ),
$r['setting_validities']
Expand Down Expand Up @@ -1887,7 +1887,7 @@ public function test_save_changeset_post_with_autosave() {
'autosave' => true,
)
);
$this->assertInternalType( 'array', $r );
$this->assertIsArray( $r );

// Verify that autosave happened.
$autosave_revision = wp_get_post_autosave( $changeset_post_id, get_current_user_id() );
Expand Down Expand Up @@ -2714,10 +2714,10 @@ function test_prepare_setting_validity_for_js() {
$error->add( 'bad_letter', 'Bad letra', 123 );
$error->add( 'bad_number', 'Bad number', array( 'number' => 123 ) );
$validity = $this->manager->prepare_setting_validity_for_js( $error );
$this->assertInternalType( 'array', $validity );
$this->assertIsArray( $validity );
foreach ( $error->errors as $code => $messages ) {
$this->assertArrayHasKey( $code, $validity );
$this->assertInternalType( 'array', $validity[ $code ] );
$this->assertIsArray( $validity[ $code ] );
$this->assertEquals( join( ' ', $messages ), $validity[ $code ]['message'] );
$this->assertArrayHasKey( 'data', $validity[ $code ] );
$this->assertEquals( $validity[ $code ]['data'], $error->get_error_data( $code ) );
Expand Down Expand Up @@ -2927,7 +2927,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->assertInternalType( 'array', $setting_args );
$this->assertIsArray( $setting_args );
return $setting_class;
}

Expand Down Expand Up @@ -3038,7 +3038,7 @@ function test_autofocus() {
*/
function test_nonces() {
$nonces = $this->manager->get_nonces();
$this->assertInternalType( 'array', $nonces );
$this->assertIsArray( $nonces );
$this->assertArrayHasKey( 'save', $nonces );
$this->assertArrayHasKey( 'preview', $nonces );

Expand Down Expand Up @@ -3202,10 +3202,10 @@ function test_customize_loaded_components_filter() {
* @return array Components.
*/
function return_array_containing_widgets( $components, $customize_manager ) {
$this->assertInternalType( 'array', $components );
$this->assertIsArray( $components );
$this->assertContains( 'widgets', $components );
$this->assertContains( 'nav_menus', $components );
$this->assertInternalType( 'array', $components );
$this->assertIsArray( $components );
$this->assertInstanceOf( 'WP_Customize_Manager', $customize_manager );
return array( 'widgets' );
}
Expand All @@ -3219,10 +3219,10 @@ function return_array_containing_widgets( $components, $customize_manager ) {
* @return array Components.
*/
function return_array_containing_nav_menus( $components, $customize_manager ) {
$this->assertInternalType( 'array', $components );
$this->assertIsArray( $components );
$this->assertContains( 'widgets', $components );
$this->assertContains( 'nav_menus', $components );
$this->assertInternalType( 'array', $components );
$this->assertIsArray( $components );
$this->assertInstanceOf( 'WP_Customize_Manager', $customize_manager );
return array( 'nav_menus' );
}
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/tests/customize/nav-menu-item-setting.php
Expand Up @@ -73,7 +73,7 @@ function test_construct() {
$this->assertNull( $setting->previous_post_id );
$this->assertNull( $setting->update_status );
$this->assertNull( $setting->update_error );
$this->assertInternalType( 'array', $setting->default );
$this->assertIsArray( $setting->default );

$default = array(
'object_id' => 0,
Expand Down Expand Up @@ -531,7 +531,7 @@ function test_sanitize() {
);
foreach ( $valid_urls as $valid_url ) {
$url_setting = $setting->sanitize( array( 'url' => $valid_url ) );
$this->assertInternalType( 'array', $url_setting );
$this->assertIsArray( $url_setting );
$this->assertEquals( $valid_url, $url_setting['url'] );
}

Expand Down
6 changes: 3 additions & 3 deletions tests/phpunit/tests/customize/nav-menu-setting.php
Expand Up @@ -70,7 +70,7 @@ function test_construct() {
$this->assertNull( $setting->previous_term_id );
$this->assertNull( $setting->update_status );
$this->assertNull( $setting->update_error );
$this->assertInternalType( 'array', $setting->default );
$this->assertIsArray( $setting->default );
foreach ( array( 'name', 'description', 'parent' ) as $key ) {
$this->assertArrayHasKey( $key, $setting->default );
}
Expand Down Expand Up @@ -149,7 +149,7 @@ function test_value() {
$setting = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, $setting_id );

$value = $setting->value();
$this->assertInternalType( 'array', $value );
$this->assertIsArray( $value );
foreach ( array( 'name', 'description', 'parent' ) as $key ) {
$this->assertArrayHasKey( $key, $value );
}
Expand Down Expand Up @@ -304,7 +304,7 @@ function test_preview_deleted() {

$this->wp_customize->set_post_value( $setting_id, false );

$this->assertInternalType( 'array', $setting->value() );
$this->assertIsArray( $setting->value() );
$this->assertInternalType( 'object', wp_get_nav_menu_object( $menu_id ) );
$setting->preview();
$this->assertFalse( $setting->value() );
Expand Down
10 changes: 5 additions & 5 deletions tests/phpunit/tests/customize/nav-menus.php
Expand Up @@ -381,7 +381,7 @@ function test_search_available_items_query() {
)
);
$this->assertEquals( $count + 1, $this->filter_count_customize_nav_menu_searched_items );
$this->assertInternalType( 'array', $results );
$this->assertIsArray( $results );
$this->assertCount( 3, $results );
remove_filter( 'customize_nav_menu_searched_items', array( $this, 'filter_search' ), 10 );

Expand Down Expand Up @@ -465,8 +465,8 @@ public function test_search_available_items_query_should_return_unassigned_term_
* @return array Items.
*/
function filter_search( $items, $args ) {
$this->assertInternalType( 'array', $items );
$this->assertInternalType( 'array', $args );
$this->assertIsArray( $items );
$this->assertIsArray( $args );
$this->assertArrayHasKey( 's', $args );
$this->assertArrayHasKey( 'pagenum', $args );
$this->filter_count_customize_nav_menu_searched_items += 1;
Expand Down Expand Up @@ -804,13 +804,13 @@ function test_customize_dynamic_partial_args() {
do_action( 'customize_register', $this->wp_customize );

$args = apply_filters( 'customize_dynamic_partial_args', false, 'nav_menu_instance[68b329da9893e34099c7d8ad5cb9c940]' );
$this->assertInternalType( 'array', $args );
$this->assertIsArray( $args );
$this->assertEquals( 'nav_menu_instance', $args['type'] );
$this->assertEquals( array( $this->wp_customize->nav_menus, 'render_nav_menu_partial' ), $args['render_callback'] );
$this->assertTrue( $args['container_inclusive'] );

$args = apply_filters( 'customize_dynamic_partial_args', array( 'fallback_refresh' => false ), 'nav_menu_instance[4099c7d8ad5cb9c94068b329da9893e3]' );
$this->assertInternalType( 'array', $args );
$this->assertIsArray( $args );
$this->assertEquals( 'nav_menu_instance', $args['type'] );
$this->assertEquals( array( $this->wp_customize->nav_menus, 'render_nav_menu_partial' ), $args['render_callback'] );
$this->assertTrue( $args['container_inclusive'] );
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/tests/customize/partial.php
Expand Up @@ -166,7 +166,7 @@ function test_id_data() {
function filter_customize_partial_render( $rendered, $partial, $container_context ) {
$this->assertTrue( false === $rendered || is_string( $rendered ) );
$this->assertInstanceOf( 'WP_Customize_Partial', $partial );
$this->assertInternalType( 'array', $container_context );
$this->assertIsArray( $container_context );
$this->count_filter_customize_partial_render += 1;
return $rendered;
}
Expand All @@ -183,7 +183,7 @@ function filter_customize_partial_render_with_id( $rendered, $partial, $containe
$this->assertEquals( sprintf( 'customize_partial_render_%s', $partial->id ), current_filter() );
$this->assertTrue( false === $rendered || is_string( $rendered ) );
$this->assertInstanceOf( 'WP_Customize_Partial', $partial );
$this->assertInternalType( 'array', $container_context );
$this->assertIsArray( $container_context );
$this->count_filter_customize_partial_render_with_id += 1;
return $rendered;
}
Expand Down
8 changes: 4 additions & 4 deletions tests/phpunit/tests/customize/selective-refresh-ajax.php
Expand Up @@ -160,7 +160,7 @@ function test_handle_render_partials_request_for_unrecognized_partial() {
}
$output = json_decode( ob_get_clean(), true );
$this->assertTrue( $output['success'] );
$this->assertInternalType( 'array', $output['data'] );
$this->assertIsArray( $output['data'] );
$this->assertArrayHasKey( 'contents', $output['data'] );
$this->assertArrayHasKey( 'errors', $output['data'] );
$this->assertArrayHasKey( 'foo', $output['data']['contents'] );
Expand Down Expand Up @@ -280,7 +280,7 @@ function test_handle_rendering_partial_with_missing_settings() {
* @return string
*/
function render_callback_blogname( $partial, $context ) {
$this->assertInternalType( 'array', $context );
$this->assertIsArray( $context );
$this->assertInstanceOf( 'WP_Customize_Partial', $partial );
return get_bloginfo( 'name', 'display' );
}
Expand All @@ -293,7 +293,7 @@ function render_callback_blogname( $partial, $context ) {
* @return string
*/
function render_callback_blogdescription( $partial, $context ) {
$this->assertInternalType( 'array', $context );
$this->assertIsArray( $context );
$this->assertInstanceOf( 'WP_Customize_Partial', $partial );
$x = get_bloginfo( 'description', 'display' );
return $x;
Expand Down Expand Up @@ -374,7 +374,7 @@ function filter_customize_dynamic_partial_args( $partial_args, $partial_id ) {
* @return array Response.
*/
function filter_customize_render_partials_response( $response, $component, $partial_placements ) {
$this->assertInternalType( 'array', $response );
$this->assertIsArray( $response );
$this->assertInstanceOf( 'WP_Customize_Selective_Refresh', $component );
if ( isset( $this->expected_partial_ids ) ) {
$this->assertEqualSets( $this->expected_partial_ids, array_keys( $partial_placements ) );
Expand Down
8 changes: 4 additions & 4 deletions tests/phpunit/tests/customize/selective-refresh.php
Expand Up @@ -71,7 +71,7 @@ function test_register_scripts() {
* @see WP_Customize_Selective_Refresh::partials()
*/
function test_partials() {
$this->assertInternalType( 'array', $this->selective_refresh->partials() );
$this->assertIsArray( $this->selective_refresh->partials() );
}

/**
Expand Down Expand Up @@ -163,9 +163,9 @@ function test_export_preview_data() {
$html = ob_get_clean();
$this->assertTrue( (bool) preg_match( '/_customizePartialRefreshExports = ({.+})/s', $html, $matches ) );
$exported_data = json_decode( $matches[1], true );
$this->assertInternalType( 'array', $exported_data );
$this->assertIsArray( $exported_data );
$this->assertArrayHasKey( 'partials', $exported_data );
$this->assertInternalType( 'array', $exported_data['partials'] );
$this->assertIsArray( $exported_data['partials'] );
$this->assertArrayHasKey( 'blogname', $exported_data['partials'] );
$this->assertArrayNotHasKey( 'top_secret_message', $exported_data['partials'] );
$this->assertEquals( '#site-title', $exported_data['partials']['blogname']['selector'] );
Expand Down Expand Up @@ -230,7 +230,7 @@ function filter_customize_dynamic_partial_args( $partial_args, $partial_id ) {
* @return string
*/
function filter_customize_dynamic_partial_class( $partial_class, $partial_id, $partial_args ) {
$this->assertInternalType( 'array', $partial_args );
$this->assertIsArray( $partial_args );
$this->assertInternalType( 'string', $partial_id );
$this->assertInternalType( 'string', $partial_class );

Expand Down

0 comments on commit ca343ca

Please sign in to comment.