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

    r50935 r51331  
    217217            $user->init( $user->data );
    218218
    219             $this->assertInternalType( 'int', $user->ID );
     219            $this->assertIsInt( $user->ID );
    220220        }
    221221    }
     
    871871        );
    872872
    873         $this->assertInternalType( 'int', $u );
     873        $this->assertIsInt( $u );
    874874        $this->assertGreaterThan( 0, $u );
    875875
     
    14941494        $user    = get_user_by( 'ID', $user_id );
    14951495
    1496         $this->assertInternalType( 'int', $user_id );
     1496        $this->assertIsInt( $user_id );
    14971497        $this->assertInstanceOf( 'WP_User', $user );
    14981498        $this->assertSame( 'nickname1', $user->nickname );
     
    15051505        $user_id = edit_user( $user_id );
    15061506
    1507         $this->assertInternalType( 'int', $user_id );
     1507        $this->assertIsInt( $user_id );
    15081508        $this->assertSame( 'nickname_updated', $user->nickname );
    15091509
     
    15171517        $user    = get_user_by( 'ID', $user_id );
    15181518
    1519         $this->assertInternalType( 'int', $user_id );
     1519        $this->assertIsInt( $user_id );
    15201520        $this->assertSame( $old_pass, $user->user_pass );
    15211521
     
    15361536        remove_action( 'check_passwords', array( $this, 'action_check_passwords_blank_password' ) );
    15371537
    1538         $this->assertInternalType( 'int', $user_id );
     1538        $this->assertIsInt( $user_id );
    15391539        $this->assertSame( 'nickname_updated2', $user->nickname );
    15401540    }
Note: See TracChangeset for help on using the changeset viewer.