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-users-controller.php

    r49603 r51331  
    12121212
    12131213        if ( is_multisite() ) {
    1214             $this->assertInternalType( 'array', $data['additional_errors'] );
     1214            $this->assertIsArray( $data['additional_errors'] );
    12151215            $this->assertCount( 1, $data['additional_errors'] );
    12161216            $error = $data['additional_errors'][0];
     
    12181218            $this->assertSame( 'Usernames can only contain lowercase letters (a-z) and numbers.', $error['message'] );
    12191219        } else {
    1220             $this->assertInternalType( 'array', $data['data']['params'] );
     1220            $this->assertIsArray( $data['data']['params'] );
    12211221            $errors = $data['data']['params'];
    1222             $this->assertInternalType( 'string', $errors['username'] );
     1222            $this->assertIsString( $errors['username'] );
    12231223            $this->assertSame( 'This username is invalid because it uses illegal characters. Please enter a valid username.', $errors['username'] );
    12241224        }
     
    12581258
    12591259        $data = $response->get_data();
    1260         $this->assertInternalType( 'array', $data['data']['params'] );
     1260        $this->assertIsArray( $data['data']['params'] );
    12611261        $errors = $data['data']['params'];
    1262         $this->assertInternalType( 'string', $errors['username'] );
     1262        $this->assertIsString( $errors['username'] );
    12631263        $this->assertSame( 'Sorry, that username is not allowed.', $errors['username'] );
    12641264    }
     
    13821382        $this->assertErrorResponse( 'rest_invalid_param', $switched_response, 400 );
    13831383        $data = $switched_response->get_data();
    1384         $this->assertInternalType( 'array', $data['additional_errors'] );
     1384        $this->assertIsArray( $data['additional_errors'] );
    13851385        $this->assertCount( 2, $data['additional_errors'] );
    13861386        $errors = $data['additional_errors'];
Note: See TracChangeset for help on using the changeset viewer.