Make WordPress Core


Ignore:
Timestamp:
07/05/2021 05:21:53 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Build/Test Tools: Replace assertInternalType() usage in unit tests.

The assertInternalType() and assertNotInternalType() methods are deprecated in PHPUnit 8 and removed in PHPUnit 9.

While WordPress test suite currently only supports PHPUnit up to 7.5.x, this allows us to switch to newer assertions ahead of adding full support for PHPUnit 8+.

These methods introduced in PHPUnit 7.5 should be used as an alternative:

  • assertIsArray()
  • assertIsBool()
  • assertIsFloat()
  • assertIsInt()
  • assertIsNumeric()
  • assertIsObject()
  • assertIsResource()
  • assertIsString()
  • assertIsScalar()
  • assertIsCallable()
  • assertIsIterable()
  • assertIsNotArray()
  • assertIsNotBool()
  • assertIsNotFloat()
  • assertIsNotInt()
  • assertIsNotNumeric()
  • assertIsNotObject()
  • assertIsNotResource()
  • assertIsNotString()
  • assertIsNotScalar()
  • assertIsNotCallable()
  • assertIsNotIterable()

As WordPress currently uses PHPUnit 5.7.x to run tests on PHP 5.6, polyfills for these methods are now added to the WP_UnitTestCase class for PHPUnit < 7.5.

Props pbearne, jrf, dd32, SergeyBiryukov.
Fixes #53491. See #46149.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/customize/manager.php

    r51088 r51331  
    678678
    679679        foreach ( array( 'widget_text[2]', 'widget_meta[2]' ) as $setting_id ) {
    680             $this->assertInternalType( 'array', $changeset_values[ $setting_id ] );
     680            $this->assertIsArray( $changeset_values[ $setting_id ] );
    681681            $instance_data = $wp_customize->widgets->sanitize_widget_instance( $changeset_values[ $setting_id ] );
    682             $this->assertInternalType( 'array', $instance_data );
     682            $this->assertIsArray( $instance_data );
    683683            $this->assertArrayHasKey( 'title', $instance_data );
    684684        }
     
    732732        $this->assertSame( 1000, has_action( 'customize_register', array( $wp_customize, '_save_starter_content_changeset' ) ) );
    733733        do_action( 'customize_register', $wp_customize ); // This will trigger the changeset save.
    734         $this->assertInternalType( 'int', $wp_customize->changeset_post_id() );
     734        $this->assertIsInt( $wp_customize->changeset_post_id() );
    735735        $this->assertNotEmpty( $wp_customize->changeset_data() );
    736736        foreach ( $wp_customize->changeset_data() as $setting_id => $setting_params ) {
     
    788788        $this->assertNotEquals( $changeset_data['blogname']['value'], get_option( 'blogname' ) );
    789789        $r = $wp_customize->save_changeset_post( array( 'status' => 'publish' ) );
    790         $this->assertInternalType( 'array', $r );
     790        $this->assertIsArray( $r );
    791791        $this->assertSame( 'publish', get_post( $posts_by_name['about'] )->post_status );
    792792        $this->assertSame( 'inherit', get_post( $posts_by_name['waffles'] )->post_status );
     
    10421042            )
    10431043        );
    1044         $this->assertInternalType( 'array', $r );
     1044        $this->assertIsArray( $r );
    10451045
    10461046        $this->assertSame( $did_action['customize_save_validation_before'] + 1, did_action( 'customize_save_validation_before' ) );
     
    10991099        $this->assertInstanceOf( 'WP_Error', $r );
    11001100        $this->assertSame( 'transaction_fail', $r->get_error_code() );
    1101         $this->assertInternalType( 'array', $r->get_error_data() );
     1101        $this->assertIsArray( $r->get_error_data() );
    11021102        $this->assertArrayHasKey( 'setting_validities', $r->get_error_data() );
    11031103        $error_data = $r->get_error_data();
     
    11381138            )
    11391139        );
    1140         $this->assertInternalType( 'array', $r );
     1140        $this->assertIsArray( $r );
    11411141        $this->assertArrayHasKey( 'setting_validities', $r );
    11421142        $this->assertTrue( $r['setting_validities']['blogname'] );
     
    12061206            )
    12071207        );
    1208         $this->assertInternalType( 'array', $r );
     1208        $this->assertIsArray( $r );
    12091209        $this->assertSame( 'Do it live \o/', get_option( 'blogname' ) );
    12101210        $this->assertSame( 'trash', get_post_status( $post_id ) ); // Auto-trashed.
     
    14231423    function filter_customize_changeset_save_data( $data, $context ) {
    14241424        $this->customize_changeset_save_data_call_count += 1;
    1425         $this->assertInternalType( 'array', $data );
    1426         $this->assertInternalType( 'array', $context );
     1425        $this->assertIsArray( $data );
     1426        $this->assertIsArray( $context );
    14271427        $this->assertArrayHasKey( 'uuid', $context );
    14281428        $this->assertArrayHasKey( 'title', $context );
     
    15141514            )
    15151515        );
    1516         $this->assertInternalType( 'array', $r );
     1516        $this->assertIsArray( $r );
    15171517        $this->assertSame(
    15181518            array_fill_keys( array( 'blogname', 'scratchpad', 'background_color' ), true ),
     
    15411541            )
    15421542        );
    1543         $this->assertInternalType( 'array', $r );
     1543        $this->assertIsArray( $r );
    15441544        $this->assertSame(
    15451545            array_fill_keys( array( 'blogname', 'background_color' ), true ),
     
    15701570            )
    15711571        );
    1572         $this->assertInternalType( 'array', $r );
     1572        $this->assertIsArray( $r );
    15731573        $this->assertSame(
    15741574            array_fill_keys( array( 'blogname', 'scratchpad' ), true ),
     
    18891889            )
    18901890        );
    1891         $this->assertInternalType( 'array', $r );
     1891        $this->assertIsArray( $r );
    18921892
    18931893        // Verify that autosave happened.
     
    27162716        $error->add( 'bad_number', 'Bad number', array( 'number' => 123 ) );
    27172717        $validity = $this->manager->prepare_setting_validity_for_js( $error );
    2718         $this->assertInternalType( 'array', $validity );
     2718        $this->assertIsArray( $validity );
    27192719        foreach ( $error->errors as $code => $messages ) {
    27202720            $this->assertArrayHasKey( $code, $validity );
    2721             $this->assertInternalType( 'array', $validity[ $code ] );
     2721            $this->assertIsArray( $validity[ $code ] );
    27222722            $this->assertSame( implode( ' ', $messages ), $validity[ $code ]['message'] );
    27232723            $this->assertArrayHasKey( 'data', $validity[ $code ] );
     
    29112911     */
    29122912    function filter_customize_dynamic_setting_args_for_test_dynamic_settings( $setting_args, $setting_id ) {
    2913         $this->assertInternalType( 'string', $setting_id );
     2913        $this->assertIsString( $setting_id );
    29142914        if ( in_array( $setting_id, array( 'foo', 'bar' ), true ) ) {
    29152915            $setting_args = array( 'default' => "dynamic_{$setting_id}_default" );
     
    29282928    function filter_customize_dynamic_setting_class_for_test_dynamic_settings( $setting_class, $setting_id, $setting_args ) {
    29292929        $this->assertSame( 'WP_Customize_Setting', $setting_class );
    2930         $this->assertInternalType( 'string', $setting_id );
    2931         $this->assertInternalType( 'array', $setting_args );
     2930        $this->assertIsString( $setting_id );
     2931        $this->assertIsArray( $setting_args );
    29322932        return $setting_class;
    29332933    }
     
    30403040    function test_nonces() {
    30413041        $nonces = $this->manager->get_nonces();
    3042         $this->assertInternalType( 'array', $nonces );
     3042        $this->assertIsArray( $nonces );
    30433043        $this->assertArrayHasKey( 'save', $nonces );
    30443044        $this->assertArrayHasKey( 'preview', $nonces );
     
    32043204     */
    32053205    function return_array_containing_widgets( $components, $customize_manager ) {
    3206         $this->assertInternalType( 'array', $components );
     3206        $this->assertIsArray( $components );
    32073207        $this->assertContains( 'widgets', $components );
    32083208        $this->assertContains( 'nav_menus', $components );
    3209         $this->assertInternalType( 'array', $components );
     3209        $this->assertIsArray( $components );
    32103210        $this->assertInstanceOf( 'WP_Customize_Manager', $customize_manager );
    32113211        return array( 'widgets' );
     
    32213221     */
    32223222    function return_array_containing_nav_menus( $components, $customize_manager ) {
    3223         $this->assertInternalType( 'array', $components );
     3223        $this->assertIsArray( $components );
    32243224        $this->assertContains( 'widgets', $components );
    32253225        $this->assertContains( 'nav_menus', $components );
    3226         $this->assertInternalType( 'array', $components );
     3226        $this->assertIsArray( $components );
    32273227        $this->assertInstanceOf( 'WP_Customize_Manager', $customize_manager );
    32283228        return array( 'nav_menus' );
Note: See TracChangeset for help on using the changeset viewer.