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/term/wpInsertTerm.php

    r49947 r51331  
    2828
    2929        $t = wp_insert_term( $term, $taxonomy );
    30         $this->assertInternalType( 'array', $t );
     30        $this->assertIsArray( $t );
    3131        $this->assertNotWPError( $t );
    3232        $this->assertTrue( $t['term_id'] > 0 );
     
    777777        _unregister_taxonomy( 'wptests_tax' );
    778778
    779         $this->assertInternalType( 'array', $found );
     779        $this->assertIsArray( $found );
    780780        $this->assertNotEmpty( $found['term_id'] );
    781781        $this->assertNotEmpty( $found['term_taxonomy_id'] );
     
    845845        );
    846846
    847         $this->assertInternalType( 'int', $t1 );
    848         $this->assertInternalType( 'int', $t2 );
     847        $this->assertIsInt( $t1 );
     848        $this->assertIsInt( $t2 );
    849849        $this->assertNotEquals( $t1, $t2 );
    850850
     
    901901
    902902    public function deleted_term_cb( $term, $tt_id, $taxonomy, $deleted_term, $object_ids ) {
    903         $this->assertInternalType( 'object', $deleted_term );
    904         $this->assertInternalType( 'int', $term );
    905         $this->assertInternalType( 'array', $object_ids );
    906         // Pesky string $this->assertInternalType( 'int', $tt_id );
     903        $this->assertIsObject( $deleted_term );
     904        $this->assertIsInt( $term );
     905        $this->assertIsArray( $object_ids );
     906        // Pesky string $this->assertIsInt( $tt_id );
    907907        $this->assertSame( $term, $deleted_term->term_id );
    908908        $this->assertSame( $taxonomy, $deleted_term->taxonomy );
Note: See TracChangeset for help on using the changeset viewer.