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/xmlrpc/wp/getPostType.php

    r50463 r51331  
    6060
    6161        // Check data types.
    62         $this->assertInternalType( 'string', $result['name'] );
    63         $this->assertInternalType( 'string', $result['label'] );
    64         $this->assertInternalType( 'bool', $result['hierarchical'] );
    65         $this->assertInternalType( 'bool', $result['public'] );
    66         $this->assertInternalType( 'bool', $result['_builtin'] );
    67         $this->assertInternalType( 'bool', $result['map_meta_cap'] );
    68         $this->assertInternalType( 'bool', $result['has_archive'] );
    69         $this->assertInternalType( 'bool', $result['show_ui'] );
    70         $this->assertInternalType( 'int', $result['menu_position'] );
    71         $this->assertInternalType( 'string', $result['menu_icon'] );
    72         $this->assertInternalType( 'array', $result['labels'] );
    73         $this->assertInternalType( 'array', $result['cap'] );
    74         $this->assertInternalType( 'array', $result['taxonomies'] );
    75         $this->assertInternalType( 'array', $result['supports'] );
     62        $this->assertIsString( $result['name'] );
     63        $this->assertIsString( $result['label'] );
     64        $this->assertIsBool( $result['hierarchical'] );
     65        $this->assertIsBool( $result['public'] );
     66        $this->assertIsBool( $result['_builtin'] );
     67        $this->assertIsBool( $result['map_meta_cap'] );
     68        $this->assertIsBool( $result['has_archive'] );
     69        $this->assertIsBool( $result['show_ui'] );
     70        $this->assertIsInt( $result['menu_position'] );
     71        $this->assertIsString( $result['menu_icon'] );
     72        $this->assertIsArray( $result['labels'] );
     73        $this->assertIsArray( $result['cap'] );
     74        $this->assertIsArray( $result['taxonomies'] );
     75        $this->assertIsArray( $result['supports'] );
    7676
    7777        // Check label data types.
    78         $this->assertInternalType( 'string', $result['labels']['name'] );
    79         $this->assertInternalType( 'string', $result['labels']['singular_name'] );
    80         $this->assertInternalType( 'string', $result['labels']['add_new'] );
    81         $this->assertInternalType( 'string', $result['labels']['add_new_item'] );
    82         $this->assertInternalType( 'string', $result['labels']['edit_item'] );
    83         $this->assertInternalType( 'string', $result['labels']['new_item'] );
    84         $this->assertInternalType( 'string', $result['labels']['view_item'] );
    85         $this->assertInternalType( 'string', $result['labels']['search_items'] );
    86         $this->assertInternalType( 'string', $result['labels']['not_found'] );
    87         $this->assertInternalType( 'string', $result['labels']['not_found_in_trash'] );
    88         $this->assertInternalType( 'string', $result['labels']['parent_item_colon'] );
    89         $this->assertInternalType( 'string', $result['labels']['all_items'] );
    90         $this->assertInternalType( 'string', $result['labels']['menu_name'] );
    91         $this->assertInternalType( 'string', $result['labels']['name_admin_bar'] );
     78        $this->assertIsString( $result['labels']['name'] );
     79        $this->assertIsString( $result['labels']['singular_name'] );
     80        $this->assertIsString( $result['labels']['add_new'] );
     81        $this->assertIsString( $result['labels']['add_new_item'] );
     82        $this->assertIsString( $result['labels']['edit_item'] );
     83        $this->assertIsString( $result['labels']['new_item'] );
     84        $this->assertIsString( $result['labels']['view_item'] );
     85        $this->assertIsString( $result['labels']['search_items'] );
     86        $this->assertIsString( $result['labels']['not_found'] );
     87        $this->assertIsString( $result['labels']['not_found_in_trash'] );
     88        $this->assertIsString( $result['labels']['parent_item_colon'] );
     89        $this->assertIsString( $result['labels']['all_items'] );
     90        $this->assertIsString( $result['labels']['menu_name'] );
     91        $this->assertIsString( $result['labels']['name_admin_bar'] );
    9292
    9393        // Check cap data types.
    94         $this->assertInternalType( 'string', $result['cap']['edit_post'] );
    95         $this->assertInternalType( 'string', $result['cap']['read_post'] );
    96         $this->assertInternalType( 'string', $result['cap']['delete_post'] );
    97         $this->assertInternalType( 'string', $result['cap']['edit_posts'] );
    98         $this->assertInternalType( 'string', $result['cap']['edit_others_posts'] );
    99         $this->assertInternalType( 'string', $result['cap']['publish_posts'] );
    100         $this->assertInternalType( 'string', $result['cap']['read_private_posts'] );
    101         $this->assertInternalType( 'string', $result['cap']['read'] );
    102         $this->assertInternalType( 'string', $result['cap']['delete_posts'] );
    103         $this->assertInternalType( 'string', $result['cap']['delete_private_posts'] );
    104         $this->assertInternalType( 'string', $result['cap']['delete_published_posts'] );
    105         $this->assertInternalType( 'string', $result['cap']['delete_others_posts'] );
    106         $this->assertInternalType( 'string', $result['cap']['edit_private_posts'] );
    107         $this->assertInternalType( 'string', $result['cap']['edit_published_posts'] );
     94        $this->assertIsString( $result['cap']['edit_post'] );
     95        $this->assertIsString( $result['cap']['read_post'] );
     96        $this->assertIsString( $result['cap']['delete_post'] );
     97        $this->assertIsString( $result['cap']['edit_posts'] );
     98        $this->assertIsString( $result['cap']['edit_others_posts'] );
     99        $this->assertIsString( $result['cap']['publish_posts'] );
     100        $this->assertIsString( $result['cap']['read_private_posts'] );
     101        $this->assertIsString( $result['cap']['read'] );
     102        $this->assertIsString( $result['cap']['delete_posts'] );
     103        $this->assertIsString( $result['cap']['delete_private_posts'] );
     104        $this->assertIsString( $result['cap']['delete_published_posts'] );
     105        $this->assertIsString( $result['cap']['delete_others_posts'] );
     106        $this->assertIsString( $result['cap']['edit_private_posts'] );
     107        $this->assertIsString( $result['cap']['edit_published_posts'] );
    108108
    109109        // Check taxonomy data types.
    110110        foreach ( $result['taxonomies'] as $taxonomy ) {
    111             $this->assertInternalType( 'string', $taxonomy );
     111            $this->assertIsString( $taxonomy );
    112112        }
    113113
    114114        // Check support data types.
    115115        foreach ( $result['supports'] as $key => $value ) {
    116             $this->assertInternalType( 'string', $key );
    117             $this->assertInternalType( 'bool', $value );
     116            $this->assertIsString( $key );
     117            $this->assertIsBool( $value );
    118118        }
    119119
Note: See TracChangeset for help on using the changeset viewer.