Make WordPress Core


Ignore:
Timestamp:
07/05/2021 05:21:53 PM (3 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/customize/nav-menus.php

    r49108 r51331  
    382382        );
    383383        $this->assertSame( $count + 1, $this->filter_count_customize_nav_menu_searched_items );
    384         $this->assertInternalType( 'array', $results );
     384        $this->assertIsArray( $results );
    385385        $this->assertCount( 3, $results );
    386386        remove_filter( 'customize_nav_menu_searched_items', array( $this, 'filter_search' ), 10 );
     
    466466     */
    467467    function filter_search( $items, $args ) {
    468         $this->assertInternalType( 'array', $items );
    469         $this->assertInternalType( 'array', $args );
     468        $this->assertIsArray( $items );
     469        $this->assertIsArray( $args );
    470470        $this->assertArrayHasKey( 's', $args );
    471471        $this->assertArrayHasKey( 'pagenum', $args );
     
    805805
    806806        $args = apply_filters( 'customize_dynamic_partial_args', false, 'nav_menu_instance[68b329da9893e34099c7d8ad5cb9c940]' );
    807         $this->assertInternalType( 'array', $args );
     807        $this->assertIsArray( $args );
    808808        $this->assertSame( 'nav_menu_instance', $args['type'] );
    809809        $this->assertSame( array( $this->wp_customize->nav_menus, 'render_nav_menu_partial' ), $args['render_callback'] );
     
    811811
    812812        $args = apply_filters( 'customize_dynamic_partial_args', array( 'fallback_refresh' => false ), 'nav_menu_instance[4099c7d8ad5cb9c94068b329da9893e3]' );
    813         $this->assertInternalType( 'array', $args );
     813        $this->assertIsArray( $args );
    814814        $this->assertSame( 'nav_menu_instance', $args['type'] );
    815815        $this->assertSame( array( $this->wp_customize->nav_menus, 'render_nav_menu_partial' ), $args['render_callback'] );
Note: See TracChangeset for help on using the changeset viewer.