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/post/objects.php

    r50935 r51331  
    3131        // Excercise the output argument.
    3232        $post = get_post( $id, ARRAY_A );
    33         $this->assertInternalType( 'array', $post );
     33        $this->assertIsArray( $post );
    3434        $this->assertSame( 'post', $post['post_type'] );
    3535
    3636        $post = get_post( $id, ARRAY_N );
    37         $this->assertInternalType( 'array', $post );
     37        $this->assertIsArray( $post );
    3838        $this->assertFalse( isset( $post['post_type'] ) );
    3939        $this->assertTrue( in_array( 'post', $post, true ) );
     
    4141        $post = get_post( $id );
    4242        $post = get_post( $post, ARRAY_A );
    43         $this->assertInternalType( 'array', $post );
     43        $this->assertIsArray( $post );
    4444        $this->assertSame( 'post', $post['post_type'] );
    4545        $this->assertSame( $id, $post['ID'] );
     
    5252        // Make sure stdClass in $GLOBALS['post'] is handled.
    5353        $post_std = $post->to_array();
    54         $this->assertInternalType( 'array', $post_std );
     54        $this->assertIsArray( $post_std );
    5555        $post_std        = (object) $post_std;
    5656        $GLOBALS['post'] = $post_std;
     
    104104    function test_get_post_ancestors_with_falsey_values() {
    105105        foreach ( array( null, 0, false, '0', '' ) as $post_id ) {
    106             $this->assertInternalType( 'array', get_post_ancestors( $post_id ) );
     106            $this->assertIsArray( get_post_ancestors( $post_id ) );
    107107            $this->assertSame( array(), get_post_ancestors( $post_id ) );
    108108        }
     
    113113        $post    = get_post( $post_id );
    114114
    115         $this->assertInternalType( 'array', $post->post_category );
     115        $this->assertIsArray( $post->post_category );
    116116        $this->assertSame( 1, count( $post->post_category ) );
    117117        $this->assertEquals( get_option( 'default_category' ), $post->post_category[0] );
     
    132132        $post    = get_post( $post_id );
    133133
    134         $this->assertInternalType( 'array', $post->tags_input );
     134        $this->assertIsArray( $post->tags_input );
    135135        $this->assertEmpty( $post->tags_input );
    136136        wp_set_post_tags( $post_id, 'Foo, Bar, Baz' );
    137         $this->assertInternalType( 'array', $post->tags_input );
     137        $this->assertIsArray( $post->tags_input );
    138138        $this->assertSame( 3, count( $post->tags_input ) );
    139139        $this->assertSame( array( 'Bar', 'Baz', 'Foo' ), $post->tags_input );
    140140
    141141        $post = get_post( $post_id, ARRAY_A );
    142         $this->assertInternalType( 'array', $post['tags_input'] );
     142        $this->assertIsArray( $post['tags_input'] );
    143143        $this->assertSame( 3, count( $post['tags_input'] ) );
    144144        $this->assertSame( array( 'Bar', 'Baz', 'Foo' ), $post['tags_input'] );
     
    149149        $post    = get_post( $post_id );
    150150
    151         $this->assertInternalType( 'string', $post->page_template );
     151        $this->assertIsString( $post->page_template );
    152152        $template = get_post_meta( $post->ID, '_wp_page_template', true );
    153153        $this->assertSame( $template, $post->page_template );
     
    168168
    169169        $this->assertSame( 'raw', $post->filter );
    170         $this->assertInternalType( 'int', $post->post_parent );
     170        $this->assertIsInt( $post->post_parent );
    171171
    172172        $display_post = get_post( $post, OBJECT, 'js' );
     
    195195            $post = get_post( $post_id, OBJECT, $context );
    196196
    197             $this->assertInternalType( 'int', $post->ID );
    198             $this->assertInternalType( 'int', $post->post_parent );
    199             $this->assertInternalType( 'int', $post->menu_order );
     197            $this->assertIsInt( $post->ID );
     198            $this->assertIsInt( $post->post_parent );
     199            $this->assertIsInt( $post->menu_order );
    200200        }
    201201    }
     
    216216
    217217        $this->assertSame( $id, $post['ID'] );
    218         $this->assertInternalType( 'array', $post['ancestors'] );
     218        $this->assertIsArray( $post['ancestors'] );
    219219        $this->assertSame( 'raw', $post['filter'] );
    220220    }
Note: See TracChangeset for help on using the changeset viewer.