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/multisite/site.php

    r49603 r51331  
    9595            $this->assertFalse( ms_is_switched() );
    9696            $current_blog_id = get_current_blog_id();
    97             $this->assertInternalType( 'integer', $current_blog_id );
     97            $this->assertIsInt( $current_blog_id );
    9898
    9999            wp_cache_set( 'switch-test', $current_blog_id, 'switch-test' );
     
    142142            $blog_id = self::factory()->blog->create();
    143143
    144             $this->assertInternalType( 'int', $blog_id );
     144            $this->assertIsInt( $blog_id );
    145145            $prefix = $wpdb->get_blog_prefix( $blog_id );
    146146
     
    13291329            $site_id = wp_insert_site( $site_data );
    13301330
    1331             $this->assertInternalType( 'integer', $site_id );
     1331            $this->assertIsInt( $site_id );
    13321332
    13331333            $site = get_site( $site_id );
     
    14351435            remove_action( 'clean_site_cache', array( $this, 'action_database_insert_on_clean_site_cache' ) );
    14361436
    1437             $this->assertInternalType( 'integer', $site_id );
     1437            $this->assertIsInt( $site_id );
    14381438
    14391439        }
     
    18201820                )
    18211821            );
    1822             $this->assertInternalType( 'integer', $site_id );
     1822            $this->assertIsInt( $site_id );
    18231823
    18241824            $site = get_site( $site_id );
     
    18281828            $second_date = current_time( 'mysql', true );
    18291829            $site_id     = wp_update_site( $site_id, array() );
    1830             $this->assertInternalType( 'integer', $site_id );
     1830            $this->assertIsInt( $site_id );
    18311831
    18321832            $site = get_site( $site_id );
Note: See TracChangeset for help on using the changeset viewer.