mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-04 20:54:29 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@51331 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -80,8 +80,8 @@ class Tests_Functions extends WP_UnitTestCase {
|
||||
*/
|
||||
function test_wp_parse_args_boolean_strings() {
|
||||
$args = wp_parse_args( 'foo=false&bar=true' );
|
||||
$this->assertInternalType( 'string', $args['foo'] );
|
||||
$this->assertInternalType( 'string', $args['bar'] );
|
||||
$this->assertIsString( $args['foo'] );
|
||||
$this->assertIsString( $args['bar'] );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -581,17 +581,17 @@ class Tests_Functions extends WP_UnitTestCase {
|
||||
function test_get_allowed_mime_types() {
|
||||
$mimes = get_allowed_mime_types();
|
||||
|
||||
$this->assertInternalType( 'array', $mimes );
|
||||
$this->assertIsArray( $mimes );
|
||||
$this->assertNotEmpty( $mimes );
|
||||
|
||||
add_filter( 'upload_mimes', '__return_empty_array' );
|
||||
$mimes = get_allowed_mime_types();
|
||||
$this->assertInternalType( 'array', $mimes );
|
||||
$this->assertIsArray( $mimes );
|
||||
$this->assertEmpty( $mimes );
|
||||
|
||||
remove_filter( 'upload_mimes', '__return_empty_array' );
|
||||
$mimes = get_allowed_mime_types();
|
||||
$this->assertInternalType( 'array', $mimes );
|
||||
$this->assertIsArray( $mimes );
|
||||
$this->assertNotEmpty( $mimes );
|
||||
}
|
||||
|
||||
@@ -601,28 +601,28 @@ class Tests_Functions extends WP_UnitTestCase {
|
||||
function test_wp_get_mime_types() {
|
||||
$mimes = wp_get_mime_types();
|
||||
|
||||
$this->assertInternalType( 'array', $mimes );
|
||||
$this->assertIsArray( $mimes );
|
||||
$this->assertNotEmpty( $mimes );
|
||||
|
||||
add_filter( 'mime_types', '__return_empty_array' );
|
||||
$mimes = wp_get_mime_types();
|
||||
$this->assertInternalType( 'array', $mimes );
|
||||
$this->assertIsArray( $mimes );
|
||||
$this->assertEmpty( $mimes );
|
||||
|
||||
remove_filter( 'mime_types', '__return_empty_array' );
|
||||
$mimes = wp_get_mime_types();
|
||||
$this->assertInternalType( 'array', $mimes );
|
||||
$this->assertIsArray( $mimes );
|
||||
$this->assertNotEmpty( $mimes );
|
||||
|
||||
// 'upload_mimes' should not affect wp_get_mime_types().
|
||||
add_filter( 'upload_mimes', '__return_empty_array' );
|
||||
$mimes = wp_get_mime_types();
|
||||
$this->assertInternalType( 'array', $mimes );
|
||||
$this->assertIsArray( $mimes );
|
||||
$this->assertNotEmpty( $mimes );
|
||||
|
||||
remove_filter( 'upload_mimes', '__return_empty_array' );
|
||||
$mimes2 = wp_get_mime_types();
|
||||
$this->assertInternalType( 'array', $mimes2 );
|
||||
$this->assertIsArray( $mimes2 );
|
||||
$this->assertNotEmpty( $mimes2 );
|
||||
$this->assertSame( $mimes2, $mimes );
|
||||
}
|
||||
@@ -910,7 +910,7 @@ class Tests_Functions extends WP_UnitTestCase {
|
||||
|
||||
$urls = wp_extract_urls( $blob );
|
||||
$this->assertNotEmpty( $urls );
|
||||
$this->assertInternalType( 'array', $urls );
|
||||
$this->assertIsArray( $urls );
|
||||
$this->assertCount( count( $original_urls ), $urls );
|
||||
$this->assertSame( $original_urls, $urls );
|
||||
|
||||
@@ -931,7 +931,7 @@ class Tests_Functions extends WP_UnitTestCase {
|
||||
|
||||
$urls = wp_extract_urls( $blob );
|
||||
$this->assertNotEmpty( $urls );
|
||||
$this->assertInternalType( 'array', $urls );
|
||||
$this->assertIsArray( $urls );
|
||||
$this->assertCount( 8, $urls );
|
||||
$this->assertSame( array_slice( $original_urls, 0, 8 ), $urls );
|
||||
|
||||
@@ -945,7 +945,7 @@ class Tests_Functions extends WP_UnitTestCase {
|
||||
|
||||
$urls = wp_extract_urls( $blob );
|
||||
$this->assertNotEmpty( $urls );
|
||||
$this->assertInternalType( 'array', $urls );
|
||||
$this->assertIsArray( $urls );
|
||||
$this->assertCount( 8, $urls );
|
||||
$this->assertSame( array_slice( $original_urls, 0, 8 ), $urls );
|
||||
}
|
||||
@@ -1066,7 +1066,7 @@ class Tests_Functions extends WP_UnitTestCase {
|
||||
public function test_wp_get_ext_types() {
|
||||
$extensions = wp_get_ext_types();
|
||||
|
||||
$this->assertInternalType( 'array', $extensions );
|
||||
$this->assertIsArray( $extensions );
|
||||
$this->assertNotEmpty( $extensions );
|
||||
|
||||
add_filter( 'ext2type', '__return_empty_array' );
|
||||
@@ -1075,7 +1075,7 @@ class Tests_Functions extends WP_UnitTestCase {
|
||||
|
||||
remove_filter( 'ext2type', '__return_empty_array' );
|
||||
$extensions = wp_get_ext_types();
|
||||
$this->assertInternalType( 'array', $extensions );
|
||||
$this->assertIsArray( $extensions );
|
||||
$this->assertNotEmpty( $extensions );
|
||||
}
|
||||
|
||||
@@ -1197,7 +1197,7 @@ class Tests_Functions extends WP_UnitTestCase {
|
||||
$ids = array();
|
||||
for ( $i = 0; $i < 20; $i += 1 ) {
|
||||
$id = wp_unique_id();
|
||||
$this->assertInternalType( 'string', $id );
|
||||
$this->assertIsString( $id );
|
||||
$this->assertTrue( is_numeric( $id ) );
|
||||
$ids[] = $id;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user