Make WordPress Core


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

    r50449 r51331  
    1313        $result = set_post_format( $post_id, 'aside' );
    1414        $this->assertNotWPError( $result );
    15         $this->assertInternalType( 'array', $result );
     15        $this->assertIsArray( $result );
    1616        $this->assertSame( 1, count( $result ) );
    1717
     
    2121        $result = set_post_format( $post_id, 'standard' );
    2222        $this->assertNotWPError( $result );
    23         $this->assertInternalType( 'array', $result );
     23        $this->assertIsArray( $result );
    2424        $this->assertSame( 0, count( $result ) );
    2525
    2626        $result = set_post_format( $post_id, '' );
    2727        $this->assertNotWPError( $result );
    28         $this->assertInternalType( 'array', $result );
     28        $this->assertIsArray( $result );
    2929        $this->assertSame( 0, count( $result ) );
    3030    }
     
    4141        $result = set_post_format( $post_id, 'aside' );
    4242        $this->assertNotWPError( $result );
    43         $this->assertInternalType( 'array', $result );
     43        $this->assertIsArray( $result );
    4444        $this->assertSame( 1, count( $result ) );
    4545        // The format can be set but not retrieved until it is registered.
     
    5454        $result = set_post_format( $post_id, 'standard' );
    5555        $this->assertNotWPError( $result );
    56         $this->assertInternalType( 'array', $result );
     56        $this->assertIsArray( $result );
    5757        $this->assertSame( 0, count( $result ) );
    5858
    5959        $result = set_post_format( $post_id, '' );
    6060        $this->assertNotWPError( $result );
    61         $this->assertInternalType( 'array', $result );
     61        $this->assertIsArray( $result );
    6262        $this->assertSame( 0, count( $result ) );
    6363
     
    7373        $result = set_post_format( $post_id, 'aside' );
    7474        $this->assertNotWPError( $result );
    75         $this->assertInternalType( 'array', $result );
     75        $this->assertIsArray( $result );
    7676        $this->assertSame( 1, count( $result ) );
    7777        $this->assertTrue( has_post_format( 'aside', $post_id ) );
     
    7979        $result = set_post_format( $post_id, 'standard' );
    8080        $this->assertNotWPError( $result );
    81         $this->assertInternalType( 'array', $result );
     81        $this->assertIsArray( $result );
    8282        $this->assertSame( 0, count( $result ) );
    8383        // Standard is a special case. It shows as false when set.
Note: See TracChangeset for help on using the changeset viewer.