WordPress.org

Make WordPress Core


Ignore:
Timestamp:
07/05/2021 05:21:53 PM (5 months 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/oembed/controller.php

    r50463 r51331  
    170170            $this->fail( 'Unexpected type for $data.' );
    171171        }
    172         $this->assertInternalType( 'string', $url );
    173         $this->assertInternalType( 'array', $args );
     172        $this->assertIsString( $url );
     173        $this->assertIsArray( $args );
    174174        $this->oembed_result_filter_count++;
    175175        return $data;
     
    300300        $data     = $response->get_data();
    301301
    302         $this->assertInternalType( 'array', $data );
     302        $this->assertIsArray( $data );
    303303        $this->assertNotEmpty( $data );
    304304    }
     
    324324        $data     = $response->get_data();
    325325
    326         $this->assertInternalType( 'array', $data );
     326        $this->assertIsArray( $data );
    327327        $this->assertNotEmpty( $data );
    328328
     
    367367        $data     = $response->get_data();
    368368
    369         $this->assertInternalType( 'array', $data );
     369        $this->assertIsArray( $data );
    370370        $this->assertNotEmpty( $data );
    371371
     
    412412        $data     = $response->get_data();
    413413
    414         $this->assertInternalType( 'array', $data );
     414        $this->assertIsArray( $data );
    415415        $this->assertNotEmpty( $data );
    416416
     
    455455        $data     = $response->get_data();
    456456
    457         $this->assertInternalType( 'array', $data );
     457        $this->assertIsArray( $data );
    458458        $this->assertNotEmpty( $data );
    459459
     
    604604
    605605        $this->assertNotEmpty( $data );
    606         $this->assertInternalType( 'object', $data );
     606        $this->assertIsObject( $data );
    607607        $this->assertSame( 'YouTube', $data->provider_name );
    608608        $this->assertSame( 'https://i.ytimg.com/vi/' . self::YOUTUBE_VIDEO_ID . '/hqdefault.jpg', $data->thumbnail_url );
     
    631631
    632632        $this->assertNotEmpty( $data );
    633         $this->assertInternalType( 'object', $data );
    634         $this->assertInternalType( 'string', $data->html );
    635         $this->assertInternalType( 'array', $data->scripts );
     633        $this->assertIsObject( $data );
     634        $this->assertIsString( $data->html );
     635        $this->assertIsArray( $data->scripts );
    636636    }
    637637
     
    744744        $data     = $response->get_data();
    745745
    746         $this->assertInternalType( 'object', $data );
     746        $this->assertIsObject( $data );
    747747
    748748        $data = (array) $data;
     
    787787
    788788        $this->assertSame( 1, $this->oembed_result_filter_count );
    789         $this->assertInternalType( 'object', $data );
     789        $this->assertIsObject( $data );
    790790        $this->assertSame( 'Untrusted', $data->provider_name );
    791791        $this->assertSame( self::UNTRUSTED_PROVIDER_URL, $data->provider_url );
     
    810810
    811811        $this->assertSame( 1, $this->oembed_result_filter_count );
    812         $this->assertInternalType( 'object', $data );
     812        $this->assertIsObject( $data );
    813813
    814814        $this->assertStringStartsWith( '<b>Unfiltered</b>', $data->html );
Note: See TracChangeset for help on using the changeset viewer.