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

    r49108 r51331  
    117117        _unregister_taxonomy( 'foo' );
    118118
    119         $this->assertInternalType( 'array', $found );
     119        $this->assertIsArray( $found );
    120120        $this->assertEquals( $t, $found['term_id'] );
    121121    }
     
    181181        _unregister_taxonomy( 'foo' );
    182182
    183         $this->assertInternalType( 'array', $found );
     183        $this->assertIsArray( $found );
    184184        $this->assertEquals( $t, $found['term_id'] );
    185185    }
     
    199199        _unregister_taxonomy( 'foo' );
    200200
    201         $this->assertInternalType( 'array', $found );
     201        $this->assertIsArray( $found );
    202202        $this->assertEquals( $t, $found['term_id'] );
    203203    }
     
    217217        _unregister_taxonomy( 'foo' );
    218218
    219         $this->assertInternalType( 'array', $found );
     219        $this->assertIsArray( $found );
    220220        $this->assertEquals( $t, $found['term_id'] );
    221221    }
     
    235235        _unregister_taxonomy( 'foo' );
    236236
    237         $this->assertInternalType( 'string', $found );
     237        $this->assertIsString( $found );
    238238        $this->assertEquals( $t, $found );
    239239    }
     
    253253        _unregister_taxonomy( 'foo' );
    254254
    255         $this->assertInternalType( 'string', $found );
     255        $this->assertIsString( $found );
    256256        $this->assertEquals( $t, $found );
    257257    }
     
    263263        $term = rand_str();
    264264        $t    = wp_insert_term( $term, 'wptests_tax' );
    265         $this->assertInternalType( 'array', $t );
     265        $this->assertIsArray( $t );
    266266        $this->assertEquals( $t['term_id'], term_exists( $t['term_id'] ) );
    267267        $this->assertEquals( $t['term_id'], term_exists( $term ) );
Note: See TracChangeset for help on using the changeset viewer.