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/customize/selective-refresh.php

    r48939 r51331  
    7272     */
    7373    function test_partials() {
    74         $this->assertInternalType( 'array', $this->selective_refresh->partials() );
     74        $this->assertIsArray( $this->selective_refresh->partials() );
    7575    }
    7676
     
    164164        $this->assertTrue( (bool) preg_match( '/_customizePartialRefreshExports = ({.+})/s', $html, $matches ) );
    165165        $exported_data = json_decode( $matches[1], true );
    166         $this->assertInternalType( 'array', $exported_data );
     166        $this->assertIsArray( $exported_data );
    167167        $this->assertArrayHasKey( 'partials', $exported_data );
    168         $this->assertInternalType( 'array', $exported_data['partials'] );
     168        $this->assertIsArray( $exported_data['partials'] );
    169169        $this->assertArrayHasKey( 'blogname', $exported_data['partials'] );
    170170        $this->assertArrayNotHasKey( 'top_secret_message', $exported_data['partials'] );
     
    209209    function filter_customize_dynamic_partial_args( $partial_args, $partial_id ) {
    210210        $this->assertTrue( false === $partial_args || is_array( $partial_args ) );
    211         $this->assertInternalType( 'string', $partial_id );
     211        $this->assertIsString( $partial_id );
    212212
    213213        if ( preg_match( '/^recognized/', $partial_id ) ) {
     
    231231     */
    232232    function filter_customize_dynamic_partial_class( $partial_class, $partial_id, $partial_args ) {
    233         $this->assertInternalType( 'array', $partial_args );
    234         $this->assertInternalType( 'string', $partial_id );
    235         $this->assertInternalType( 'string', $partial_class );
     233        $this->assertIsArray( $partial_args );
     234        $this->assertIsString( $partial_id );
     235        $this->assertIsString( $partial_class );
    236236
    237237        if ( 'recognized-class' === $partial_id ) {
Note: See TracChangeset for help on using the changeset viewer.