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-menu-setting.php

    r48939 r51331  
    7171        $this->assertNull( $setting->update_status );
    7272        $this->assertNull( $setting->update_error );
    73         $this->assertInternalType( 'array', $setting->default );
     73        $this->assertIsArray( $setting->default );
    7474        foreach ( array( 'name', 'description', 'parent' ) as $key ) {
    7575            $this->assertArrayHasKey( $key, $setting->default );
     
    150150
    151151        $value = $setting->value();
    152         $this->assertInternalType( 'array', $value );
     152        $this->assertIsArray( $value );
    153153        foreach ( array( 'name', 'description', 'parent' ) as $key ) {
    154154            $this->assertArrayHasKey( $key, $value );
     
    226226        $menus_ids = wp_list_pluck( $menus, 'term_id' );
    227227        $i         = array_search( $menu_id, $menus_ids, true );
    228         $this->assertInternalType( 'int', $i, 'Update-previewed menu does not appear in wp_get_nav_menus()' );
     228        $this->assertIsInt( $i, 'Update-previewed menu does not appear in wp_get_nav_menus()' );
    229229        $filtered_menu = $menus[ $i ];
    230230        $this->assertSame( 'Name 2 \\o/', $filtered_menu->name );
     
    271271        $menus_ids = wp_list_pluck( $menus, 'term_id' );
    272272        $i         = array_search( $menu_id, $menus_ids, true );
    273         $this->assertInternalType( 'int', $i, 'Insert-previewed menu was not injected into wp_get_nav_menus()' );
     273        $this->assertIsInt( $i, 'Insert-previewed menu was not injected into wp_get_nav_menus()' );
    274274        $filtered_menu = $menus[ $i ];
    275275        $this->assertSame( 'New Menu Name 1 \\o/', $filtered_menu->name );
     
    305305        $this->wp_customize->set_post_value( $setting_id, false );
    306306
    307         $this->assertInternalType( 'array', $setting->value() );
    308         $this->assertInternalType( 'object', wp_get_nav_menu_object( $menu_id ) );
     307        $this->assertIsArray( $setting->value() );
     308        $this->assertIsObject( wp_get_nav_menu_object( $menu_id ) );
    309309        $setting->preview();
    310310        $this->assertFalse( $setting->value() );
Note: See TracChangeset for help on using the changeset viewer.