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

    r50935 r51331  
    9898    public function test_output_object() {
    9999        $t = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax' ) );
    100         $this->assertInternalType( 'object', get_term( $t, 'wptests_tax', OBJECT ) );
     100        $this->assertIsObject( get_term( $t, 'wptests_tax', OBJECT ) );
    101101    }
    102102
     
    104104        $t    = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax' ) );
    105105        $term = get_term( $t, 'wptests_tax', ARRAY_A );
    106         $this->assertInternalType( 'array', $term );
     106        $this->assertIsArray( $term );
    107107        $this->assertTrue( isset( $term['term_id'] ) );
    108108    }
     
    111111        $t    = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax' ) );
    112112        $term = get_term( $t, 'wptests_tax', ARRAY_N );
    113         $this->assertInternalType( 'array', $term );
     113        $this->assertIsArray( $term );
    114114        $this->assertFalse( isset( $term['term_id'] ) );
    115115        foreach ( $term as $k => $v ) {
    116             $this->assertInternalType( 'integer', $k );
     116            $this->assertIsInt( $k );
    117117        }
    118118    }
     
    120120    public function test_output_should_fall_back_to_object_for_invalid_input() {
    121121        $t = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax' ) );
    122         $this->assertInternalType( 'object', get_term( $t, 'wptests_tax', 'foo' ) );
     122        $this->assertIsObject( get_term( $t, 'wptests_tax', 'foo' ) );
    123123    }
    124124
     
    141141
    142142            $this->assertInstanceOf( 'WP_Term', $found );
    143             $this->assertInternalType( 'int', $found->term_id );
    144             $this->assertInternalType( 'int', $found->term_taxonomy_id );
    145             $this->assertInternalType( 'int', $found->parent );
    146             $this->assertInternalType( 'int', $found->count );
    147             $this->assertInternalType( 'int', $found->term_group );
     143            $this->assertIsInt( $found->term_id );
     144            $this->assertIsInt( $found->term_taxonomy_id );
     145            $this->assertIsInt( $found->parent );
     146            $this->assertIsInt( $found->count );
     147            $this->assertIsInt( $found->term_group );
    148148        }
    149149    }
Note: See TracChangeset for help on using the changeset viewer.