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/functions.php

    r50814 r51331  
    8181    function test_wp_parse_args_boolean_strings() {
    8282        $args = wp_parse_args( 'foo=false&bar=true' );
    83         $this->assertInternalType( 'string', $args['foo'] );
    84         $this->assertInternalType( 'string', $args['bar'] );
     83        $this->assertIsString( $args['foo'] );
     84        $this->assertIsString( $args['bar'] );
    8585    }
    8686
     
    582582        $mimes = get_allowed_mime_types();
    583583
    584         $this->assertInternalType( 'array', $mimes );
     584        $this->assertIsArray( $mimes );
    585585        $this->assertNotEmpty( $mimes );
    586586
    587587        add_filter( 'upload_mimes', '__return_empty_array' );
    588588        $mimes = get_allowed_mime_types();
    589         $this->assertInternalType( 'array', $mimes );
     589        $this->assertIsArray( $mimes );
    590590        $this->assertEmpty( $mimes );
    591591
    592592        remove_filter( 'upload_mimes', '__return_empty_array' );
    593593        $mimes = get_allowed_mime_types();
    594         $this->assertInternalType( 'array', $mimes );
     594        $this->assertIsArray( $mimes );
    595595        $this->assertNotEmpty( $mimes );
    596596    }
     
    602602        $mimes = wp_get_mime_types();
    603603
    604         $this->assertInternalType( 'array', $mimes );
     604        $this->assertIsArray( $mimes );
    605605        $this->assertNotEmpty( $mimes );
    606606
    607607        add_filter( 'mime_types', '__return_empty_array' );
    608608        $mimes = wp_get_mime_types();
    609         $this->assertInternalType( 'array', $mimes );
     609        $this->assertIsArray( $mimes );
    610610        $this->assertEmpty( $mimes );
    611611
    612612        remove_filter( 'mime_types', '__return_empty_array' );
    613613        $mimes = wp_get_mime_types();
    614         $this->assertInternalType( 'array', $mimes );
     614        $this->assertIsArray( $mimes );
    615615        $this->assertNotEmpty( $mimes );
    616616
     
    618618        add_filter( 'upload_mimes', '__return_empty_array' );
    619619        $mimes = wp_get_mime_types();
    620         $this->assertInternalType( 'array', $mimes );
     620        $this->assertIsArray( $mimes );
    621621        $this->assertNotEmpty( $mimes );
    622622
    623623        remove_filter( 'upload_mimes', '__return_empty_array' );
    624624        $mimes2 = wp_get_mime_types();
    625         $this->assertInternalType( 'array', $mimes2 );
     625        $this->assertIsArray( $mimes2 );
    626626        $this->assertNotEmpty( $mimes2 );
    627627        $this->assertSame( $mimes2, $mimes );
     
    911911        $urls = wp_extract_urls( $blob );
    912912        $this->assertNotEmpty( $urls );
    913         $this->assertInternalType( 'array', $urls );
     913        $this->assertIsArray( $urls );
    914914        $this->assertCount( count( $original_urls ), $urls );
    915915        $this->assertSame( $original_urls, $urls );
     
    932932        $urls = wp_extract_urls( $blob );
    933933        $this->assertNotEmpty( $urls );
    934         $this->assertInternalType( 'array', $urls );
     934        $this->assertIsArray( $urls );
    935935        $this->assertCount( 8, $urls );
    936936        $this->assertSame( array_slice( $original_urls, 0, 8 ), $urls );
     
    946946        $urls = wp_extract_urls( $blob );
    947947        $this->assertNotEmpty( $urls );
    948         $this->assertInternalType( 'array', $urls );
     948        $this->assertIsArray( $urls );
    949949        $this->assertCount( 8, $urls );
    950950        $this->assertSame( array_slice( $original_urls, 0, 8 ), $urls );
     
    10671067        $extensions = wp_get_ext_types();
    10681068
    1069         $this->assertInternalType( 'array', $extensions );
     1069        $this->assertIsArray( $extensions );
    10701070        $this->assertNotEmpty( $extensions );
    10711071
     
    10761076        remove_filter( 'ext2type', '__return_empty_array' );
    10771077        $extensions = wp_get_ext_types();
    1078         $this->assertInternalType( 'array', $extensions );
     1078        $this->assertIsArray( $extensions );
    10791079        $this->assertNotEmpty( $extensions );
    10801080    }
     
    11981198        for ( $i = 0; $i < 20; $i += 1 ) {
    11991199            $id = wp_unique_id();
    1200             $this->assertInternalType( 'string', $id );
     1200            $this->assertIsString( $id );
    12011201            $this->assertTrue( is_numeric( $id ) );
    12021202            $ids[] = $id;
Note: See TracChangeset for help on using the changeset viewer.