Make WordPress Core


Ignore:
Timestamp:
07/05/2021 05:21:53 PM (3 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/widgets.php

    r51140 r51331  
    625625        $this->assertArrayHasKey( 2, $option_value );
    626626        $instance = $option_value[2];
    627         $this->assertInternalType( 'array', $instance );
     627        $this->assertIsArray( $instance );
    628628        $this->assertArrayHasKey( 'content', $instance );
    629629        unset( $option_value['_multiwidget'] );
     
    876876        $result = retrieve_widgets( true );
    877877
    878         $this->assertInternalType( 'array', $result );
     878        $this->assertIsArray( $result );
    879879        $this->assertSame( $result, $sidebars_widgets );
    880880
    881881        foreach ( $sidebars_widgets as $widgets ) {
    882             $this->assertInternalType( 'array', $widgets );
     882            $this->assertIsArray( $widgets );
    883883        }
    884884
     
    925925
    926926        // $sidebars_widgets matches registered sidebars.
    927         $this->assertInternalType( 'array', $result );
     927        $this->assertIsArray( $result );
    928928        $this->assertSame( $result, $sidebars_widgets );
    929929
    930930        foreach ( $sidebars_widgets as $widgets ) {
    931             $this->assertInternalType( 'array', $widgets );
     931            $this->assertIsArray( $widgets );
    932932        }
    933933
     
    964964
    965965        $_wp_sidebars_widgets = array();
    966         $this->assertInternalType( 'array', $result );
     966        $this->assertIsArray( $result );
    967967        $this->assertSame( $result, $sidebars_widgets );
    968968
    969969        foreach ( $sidebars_widgets as $widgets ) {
    970             $this->assertInternalType( 'array', $widgets );
     970            $this->assertIsArray( $widgets );
    971971        }
    972972
     
    10061006
    10071007        $_wp_sidebars_widgets = array();
    1008         $this->assertInternalType( 'array', $result );
     1008        $this->assertIsArray( $result );
    10091009        $this->assertSame( $result, $sidebars_widgets );
    10101010
    10111011        foreach ( $sidebars_widgets as $widgets ) {
    1012             $this->assertInternalType( 'array', $widgets );
     1012            $this->assertIsArray( $widgets );
    10131013        }
    10141014
     
    10571057
    10581058        $_wp_sidebars_widgets = array();
    1059         $this->assertInternalType( 'array', $result );
     1059        $this->assertIsArray( $result );
    10601060        $this->assertSame( $result, $sidebars_widgets );
    10611061
    10621062        foreach ( $sidebars_widgets as $widgets ) {
    1063             $this->assertInternalType( 'array', $widgets );
     1063            $this->assertIsArray( $widgets );
    10641064        }
    10651065
     
    11251125        retrieve_widgets();
    11261126
    1127         $this->assertInternalType( 'array', $sidebars_widgets );
     1127        $this->assertIsArray( $sidebars_widgets );
    11281128
    11291129        foreach ( $sidebars_widgets as $widgets ) {
    1130             $this->assertInternalType( 'array', $widgets );
     1130            $this->assertIsArray( $widgets );
    11311131        }
    11321132
     
    11581158        $filtered_widgets = _wp_remove_unregistered_widgets( $widgets, $allowed_widgets );
    11591159
    1160         $this->assertInternalType( 'array', $filtered_widgets );
     1160        $this->assertIsArray( $filtered_widgets );
    11611161        $this->assertArrayHasKey( 'fantasy', $filtered_widgets );
    11621162        $this->assertEmpty( $filtered_widgets['fantasy'] );
    11631163        $this->assertArrayHasKey( 'array_version', $filtered_widgets );
    11641164        $this->assertSame( 3, $filtered_widgets['array_version'] );
    1165         $this->assertInternalType( 'integer', $filtered_widgets['array_version'] );
     1165        $this->assertIsInt( $filtered_widgets['array_version'] );
    11661166    }
    11671167
Note: See TracChangeset for help on using the changeset viewer.