WordPress.org

Make WordPress Core


Ignore:
Timestamp:
07/05/2021 05:21:53 PM (5 months 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/theme/getThemeStarterContent.php

    r50968 r51331  
    143143
    144144        foreach ( $hydrated_starter_content['widgets']['sidebar-1'] as $widget ) {
    145             $this->assertInternalType( 'array', $widget );
     145            $this->assertIsArray( $widget );
    146146            $this->assertCount( 2, $widget );
    147             $this->assertInternalType( 'string', $widget[0] );
    148             $this->assertInternalType( 'array', $widget[1] );
     147            $this->assertIsString( $widget[0] );
     148            $this->assertIsArray( $widget[1] );
    149149            $this->assertArrayHasKey( 'title', $widget[1] );
    150150        }
     
    153153
    154154        foreach ( $hydrated_starter_content['nav_menus']['top']['items'] as $nav_menu_item ) {
    155             $this->assertInternalType( 'array', $nav_menu_item );
     155            $this->assertIsArray( $nav_menu_item );
    156156            $this->assertTrue( ! empty( $nav_menu_item['object_id'] ) || ! empty( $nav_menu_item['url'] ) );
    157157        }
     
    159159
    160160        foreach ( $hydrated_starter_content['posts'] as $key => $post ) {
    161             $this->assertInternalType( 'string', $key );
     161            $this->assertIsString( $key );
    162162            $this->assertFalse( is_numeric( $key ) );
    163             $this->assertInternalType( 'array', $post );
     163            $this->assertIsArray( $post );
    164164            $this->assertArrayHasKey( 'post_type', $post );
    165165            $this->assertArrayHasKey( 'post_title', $post );
     
    201201     */
    202202    public function filter_theme_starter_content( $content, $config ) {
    203         $this->assertInternalType( 'array', $config );
     203        $this->assertIsArray( $config );
    204204        $this->assertCount( 1, $config['widgets']['sidebar-1'] );
    205205        $content['widgets']['sidebar-1'][] = array(
Note: See TracChangeset for help on using the changeset viewer.