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/meta.php

    r49603 r51331  
    4747    function test_unique_postmeta() {
    4848        // Add a unique post meta item.
    49         $this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'unique', 'value', true ) );
     49        $this->assertIsInt( add_post_meta( self::$post_id, 'unique', 'value', true ) );
    5050
    5151        // Check unique is enforced.
     
    7070    function test_nonunique_postmeta() {
    7171        // Add two non-unique post meta items.
    72         $this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'nonunique', 'value' ) );
    73         $this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'nonunique', 'another value' ) );
     72        $this->assertIsInt( add_post_meta( self::$post_id, 'nonunique', 'value' ) );
     73        $this->assertIsInt( add_post_meta( self::$post_id, 'nonunique', 'another value' ) );
    7474
    7575        // Check they exist.
     
    8888
    8989        // Add a third one.
    90         $this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'nonunique', 'someother value' ) );
     90        $this->assertIsInt( add_post_meta( self::$post_id, 'nonunique', 'someother value' ) );
    9191
    9292        // Check they exist.
     
    107107    function test_update_post_meta() {
    108108        // Add a unique post meta item.
    109         $this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'unique_update', 'value', true ) );
     109        $this->assertIsInt( add_post_meta( self::$post_id, 'unique_update', 'value', true ) );
    110110
    111111        // Add two non-unique post meta items.
    112         $this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'nonunique_update', 'value' ) );
    113         $this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'nonunique_update', 'another value' ) );
     112        $this->assertIsInt( add_post_meta( self::$post_id, 'nonunique_update', 'value' ) );
     113        $this->assertIsInt( add_post_meta( self::$post_id, 'nonunique_update', 'another value' ) );
    114114
    115115        // Check they exist.
     
    134134    function test_delete_post_meta() {
    135135        // Add two unique post meta items.
    136         $this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'unique_delete', 'value', true ) );
    137         $this->assertInternalType( 'integer', add_post_meta( self::$post_id_2, 'unique_delete', 'value', true ) );
     136        $this->assertIsInt( add_post_meta( self::$post_id, 'unique_delete', 'value', true ) );
     137        $this->assertIsInt( add_post_meta( self::$post_id_2, 'unique_delete', 'value', true ) );
    138138
    139139        // Check they exist.
     
    151151    function test_delete_post_meta_by_key() {
    152152        // Add two unique post meta items.
    153         $this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'unique_delete_by_key', 'value', true ) );
    154         $this->assertInternalType( 'integer', add_post_meta( self::$post_id_2, 'unique_delete_by_key', 'value', true ) );
     153        $this->assertIsInt( add_post_meta( self::$post_id, 'unique_delete_by_key', 'value', true ) );
     154        $this->assertIsInt( add_post_meta( self::$post_id_2, 'unique_delete_by_key', 'value', true ) );
    155155
    156156        // Check they exist.
     
    168168    function test_get_post_meta_by_id() {
    169169        $mid = add_post_meta( self::$post_id, 'get_post_meta_by_key', 'get_post_meta_by_key_value', true );
    170         $this->assertInternalType( 'integer', $mid );
     170        $this->assertIsInt( $mid );
    171171
    172172        $mobj             = new stdClass;
     
    179179
    180180        $mid = add_post_meta( self::$post_id, 'get_post_meta_by_key', array( 'foo', 'bar' ), true );
    181         $this->assertInternalType( 'integer', $mid );
     181        $this->assertIsInt( $mid );
    182182        $mobj->meta_id    = $mid;
    183183        $mobj->meta_value = array( 'foo', 'bar' );
     
    188188    function test_delete_meta() {
    189189        $mid = add_post_meta( self::$post_id, 'delete_meta', 'delete_meta_value', true );
    190         $this->assertInternalType( 'integer', $mid );
     190        $this->assertIsInt( $mid );
    191191
    192192        $this->assertTrue( delete_meta( $mid ) );
     
    198198    function test_update_meta() {
    199199        // Add a unique post meta item.
    200         $this->assertInternalType( 'integer', $mid1 = add_post_meta( self::$post_id, 'unique_update', 'value', true ) );
     200        $mid1 = add_post_meta( self::$post_id, 'unique_update', 'value', true );
     201        $this->assertIsInt( $mid1 );
    201202
    202203        // Add two non-unique post meta items.
    203         $this->assertInternalType( 'integer', $mid2 = add_post_meta( self::$post_id, 'nonunique_update', 'value' ) );
    204         $this->assertInternalType( 'integer', $mid3 = add_post_meta( self::$post_id, 'nonunique_update', 'another value' ) );
     204        $mid2 = add_post_meta( self::$post_id, 'nonunique_update', 'value' );
     205        $this->assertIsInt( $mid2 );
     206        $mid3 = add_post_meta( self::$post_id, 'nonunique_update', 'another value' );
     207        $this->assertIsInt( $mid3 );
    205208
    206209        // Check they exist.
     
    243246
    244247        // Add a post meta item.
    245         $this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'test_funky_post_meta', $funky_meta, true ) );
     248        $this->assertIsInt( add_post_meta( self::$post_id, 'test_funky_post_meta', $funky_meta, true ) );
    246249
    247250        // Check it exists.
     
    319322        wp_cache_delete( 'last_changed', 'posts' );
    320323
    321         $this->assertInternalType( 'integer', add_metadata( 'post', $post_id, 'foo', 'bar' ) );
     324        $this->assertIsInt( add_metadata( 'post', $post_id, 'foo', 'bar' ) );
    322325        $this->assertNotFalse( wp_cache_get_last_changed( 'posts' ) );
    323326    }
     
    331334        wp_cache_delete( 'last_changed', 'posts' );
    332335
    333         $this->assertInternalType( 'integer', update_metadata( 'post', $post_id, 'foo', 'bar' ) );
     336        $this->assertIsInt( update_metadata( 'post', $post_id, 'foo', 'bar' ) );
    334337        $this->assertNotFalse( wp_cache_get_last_changed( 'posts' ) );
    335338    }
Note: See TracChangeset for help on using the changeset viewer.