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-term-meta-fields.php

    r50793 r51331  
    238238        $meta = (array) $data['meta'];
    239239        $this->assertArrayHasKey( 'test_multi', $meta );
    240         $this->assertInternalType( 'array', $meta['test_multi'] );
     240        $this->assertIsArray( $meta['test_multi'] );
    241241        $this->assertContains( 'value1', $meta['test_multi'] );
    242242
     
    343343
    344344        $this->assertArrayHasKey( 'test_string', $meta );
    345         $this->assertInternalType( 'string', $meta['test_string'] );
     345        $this->assertIsString( $meta['test_string'] );
    346346        $this->assertSame( '42', $meta['test_string'] );
    347347
    348348        $this->assertArrayHasKey( 'test_number', $meta );
    349         $this->assertInternalType( 'float', $meta['test_number'] );
     349        $this->assertIsFloat( $meta['test_number'] );
    350350        $this->assertSame( 42.0, $meta['test_number'] );
    351351
    352352        $this->assertArrayHasKey( 'test_bool', $meta );
    353         $this->assertInternalType( 'boolean', $meta['test_bool'] );
     353        $this->assertIsBool( $meta['test_bool'] );
    354354        $this->assertTrue( $meta['test_bool'] );
    355355    }
     
    11581158
    11591159        $this->assertArrayHasKey( 'meta', $data );
    1160         $this->assertInternalType( 'array', $data['meta'] );
     1160        $this->assertIsArray( $data['meta'] );
    11611161
    11621162        if ( $in_taxonomy ) {
     
    12221222        $data = $response->get_data();
    12231223        $this->assertArrayHasKey( 'meta', $data );
    1224         $this->assertInternalType( 'array', $data['meta'] );
     1224        $this->assertIsArray( $data['meta'] );
    12251225
    12261226        if ( $in_taxonomy ) {
Note: See TracChangeset for help on using the changeset viewer.