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

    r49451 r51331  
    819819        register_taxonomy( 'foo', 'post', array( 'query_var' => 'bar' ) );
    820820
    821         $this->assertInternalType( 'int', array_search( 'bar', $wp->public_query_vars, true ) );
     821        $this->assertIsInt( array_search( 'bar', $wp->public_query_vars, true ) );
    822822        $this->assertTrue( unregister_taxonomy( 'foo' ) );
    823823        $this->assertFalse( array_search( 'bar', $wp->public_query_vars, true ) );
     
    841841        );
    842842
    843         $this->assertInternalType( 'array', $wp_rewrite->extra_permastructs['foo'] );
     843        $this->assertIsArray( $wp_rewrite->extra_permastructs['foo'] );
    844844        $this->assertTrue( unregister_taxonomy( 'foo' ) );
    845845        $this->assertFalse( isset( $wp_rewrite->extra_permastructs['foo'] ) );
     
    874874        register_taxonomy( 'foo', 'post' );
    875875
    876         $this->assertInternalType( 'object', $wp_taxonomies['foo'] );
    877         $this->assertInternalType( 'object', get_taxonomy( 'foo' ) );
     876        $this->assertIsObject( $wp_taxonomies['foo'] );
     877        $this->assertIsObject( get_taxonomy( 'foo' ) );
    878878
    879879        $this->assertTrue( unregister_taxonomy( 'foo' ) );
Note: See TracChangeset for help on using the changeset viewer.