Make WordPress Core


Ignore:
Timestamp:
07/05/2021 05:21:53 PM (4 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/rest-api/rest-post-meta-fields.php

    r50610 r51331  
    291291        $meta = (array) $data['meta'];
    292292        $this->assertArrayHasKey( 'test_multi', $meta );
    293         $this->assertInternalType( 'array', $meta['test_multi'] );
     293        $this->assertIsArray( $meta['test_multi'] );
    294294        $this->assertContains( 'value1', $meta['test_multi'] );
    295295
     
    396396
    397397        $this->assertArrayHasKey( 'test_string', $meta );
    398         $this->assertInternalType( 'string', $meta['test_string'] );
     398        $this->assertIsString( $meta['test_string'] );
    399399        $this->assertSame( '42', $meta['test_string'] );
    400400
    401401        $this->assertArrayHasKey( 'test_number', $meta );
    402         $this->assertInternalType( 'float', $meta['test_number'] );
     402        $this->assertIsFloat( $meta['test_number'] );
    403403        $this->assertSame( 42.0, $meta['test_number'] );
    404404
    405405        $this->assertArrayHasKey( 'test_bool', $meta );
    406         $this->assertInternalType( 'boolean', $meta['test_bool'] );
     406        $this->assertIsBool( $meta['test_bool'] );
    407407        $this->assertTrue( $meta['test_bool'] );
    408408    }
     
    12731273
    12741274        $this->assertArrayHasKey( 'meta', $data );
    1275         $this->assertInternalType( 'array', $data['meta'] );
     1275        $this->assertIsArray( $data['meta'] );
    12761276
    12771277        if ( $in_post_type ) {
     
    13391339        $data = $response->get_data();
    13401340        $this->assertArrayHasKey( 'meta', $data );
    1341         $this->assertInternalType( 'array', $data['meta'] );
     1341        $this->assertIsArray( $data['meta'] );
    13421342
    13431343        if ( $in_post_type ) {
Note: See TracChangeset for help on using the changeset viewer.