From 24479f214167145993c14817412ea832502a35e5 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 6 Jul 2021 12:25:53 +0000 Subject: [PATCH] Tests: Use more appropriate assertions in various tests. This replaces instances of `assertTrue( is_array( ... ) )` with `assertIsArray()` to use native PHPUnit functionality. Follow-up to [51331]. See #53363. git-svn-id: https://develop.svn.wordpress.org/trunk@51335 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/includes/abstract-testcase.php | 4 ++-- tests/phpunit/tests/admin/includesPlugin.php | 2 +- tests/phpunit/tests/import/parser.php | 4 ++-- tests/phpunit/tests/rest-api/rest-schema-setup.php | 2 +- tests/phpunit/tests/taxonomy.php | 4 ++-- tests/phpunit/tests/term/getTheTerms.php | 4 ++-- tests/phpunit/tests/theme.php | 8 ++++---- tests/phpunit/tests/user.php | 2 +- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php index 1c7fe55e6d..88c5363982 100644 --- a/tests/phpunit/includes/abstract-testcase.php +++ b/tests/phpunit/includes/abstract-testcase.php @@ -760,11 +760,11 @@ abstract class WP_UnitTestCase_Base extends PHPUnit\Framework\TestCase { * @param array $array Array to check. */ public function assertNonEmptyMultidimensionalArray( $array ) { - $this->assertTrue( is_array( $array ) ); + $this->assertIsArray( $array ); $this->assertNotEmpty( $array ); foreach ( $array as $sub_array ) { - $this->assertTrue( is_array( $sub_array ) ); + $this->assertIsArray( $sub_array ); $this->assertNotEmpty( $sub_array ); } } diff --git a/tests/phpunit/tests/admin/includesPlugin.php b/tests/phpunit/tests/admin/includesPlugin.php index cbbc181b46..1a989d008b 100644 --- a/tests/phpunit/tests/admin/includesPlugin.php +++ b/tests/phpunit/tests/admin/includesPlugin.php @@ -27,7 +27,7 @@ class Tests_Admin_includesPlugin extends WP_UnitTestCase { 'DomainPath' => '', ); - $this->assertTrue( is_array( $data ) ); + $this->assertIsArray( $data ); foreach ( $default_headers as $name => $value ) { $this->assertTrue( isset( $data[ $name ] ) ); diff --git a/tests/phpunit/tests/import/parser.php b/tests/phpunit/tests/import/parser.php index 21c8c33c3f..c7ceec6d9e 100644 --- a/tests/phpunit/tests/import/parser.php +++ b/tests/phpunit/tests/import/parser.php @@ -58,7 +58,7 @@ class Tests_Import_Parser extends WP_Import_UnitTestCase { $parser = new $p; $result = $parser->parse( $file ); - $this->assertTrue( is_array( $result ), $message ); + $this->assertIsArray( $result, $message ); $this->assertSame( 'http://localhost/', $result['base_url'], $message ); $this->assertEquals( array( @@ -151,7 +151,7 @@ class Tests_Import_Parser extends WP_Import_UnitTestCase { $parser = new $p; $result = $parser->parse( $file ); - $this->assertTrue( is_array( $result ), $message ); + $this->assertIsArray( $result, $message ); $this->assertSame( 'http://localhost/', $result['base_url'], $message ); $this->assertSame( $result['categories'][0]['category_nicename'], 'alpha', $message ); $this->assertSame( $result['categories'][0]['cat_name'], 'alpha', $message ); diff --git a/tests/phpunit/tests/rest-api/rest-schema-setup.php b/tests/phpunit/tests/rest-api/rest-schema-setup.php index edfce2b39d..0bbff275d2 100644 --- a/tests/phpunit/tests/rest-api/rest-schema-setup.php +++ b/tests/phpunit/tests/rest-api/rest-schema-setup.php @@ -72,7 +72,7 @@ class WP_Test_REST_Schema_Initialization extends WP_Test_REST_TestCase { public function test_expected_routes_in_schema() { $routes = rest_get_server()->get_routes(); - $this->assertTrue( is_array( $routes ), '`get_routes` should return an array.' ); + $this->assertIsArray( $routes, '`get_routes` should return an array.' ); $this->assertTrue( ! empty( $routes ), 'Routes should not be empty.' ); $routes = array_filter( array_keys( $routes ), array( $this, 'is_builtin_route' ) ); diff --git a/tests/phpunit/tests/taxonomy.php b/tests/phpunit/tests/taxonomy.php index 21224d82e2..d008840238 100644 --- a/tests/phpunit/tests/taxonomy.php +++ b/tests/phpunit/tests/taxonomy.php @@ -28,7 +28,7 @@ class Tests_Taxonomy extends WP_UnitTestCase { $tax = get_taxonomy( $taxonomy ); // Should return an object with the correct taxonomy object type. $this->assertTrue( is_object( $tax ) ); - $this->assertTrue( is_array( $tax->object_type ) ); + $this->assertIsArray( $tax->object_type ); $this->assertSame( array( 'post' ), $tax->object_type ); } } @@ -110,7 +110,7 @@ class Tests_Taxonomy extends WP_UnitTestCase { $tax = get_taxonomy( $taxonomy ); // Should return an object with the correct taxonomy object type. $this->assertTrue( is_object( $tax ) ); - $this->assertTrue( is_array( $tax->object_type ) ); + $this->assertIsArray( $tax->object_type ); $this->assertSame( array( 'link' ), $tax->object_type ); } } diff --git a/tests/phpunit/tests/term/getTheTerms.php b/tests/phpunit/tests/term/getTheTerms.php index 43990431c7..4603790787 100644 --- a/tests/phpunit/tests/term/getTheTerms.php +++ b/tests/phpunit/tests/term/getTheTerms.php @@ -248,7 +248,7 @@ class Tests_Term_GetTheTerms extends WP_UnitTestCase { // Re-activate term counting so this doesn't affect other tests. wp_defer_term_counting( false ); - $this->assertTrue( is_array( $terms ) ); + $this->assertIsArray( $terms ); $this->assertSame( array( $term_id ), wp_list_pluck( $terms, 'term_id' ) ); } @@ -283,7 +283,7 @@ class Tests_Term_GetTheTerms extends WP_UnitTestCase { // Re-activate term counting so this doesn't affect other tests. wp_defer_term_counting( false ); - $this->assertTrue( is_array( $terms ) ); + $this->assertIsArray( $terms ); $this->assertSame( array( $term_ids[1] ), wp_list_pluck( $terms, 'term_id' ) ); } } diff --git a/tests/phpunit/tests/theme.php b/tests/phpunit/tests/theme.php index c4022eefcb..a04b817306 100644 --- a/tests/phpunit/tests/theme.php +++ b/tests/phpunit/tests/theme.php @@ -145,16 +145,16 @@ class Tests_Theme extends WP_UnitTestCase { $this->assertNotEmpty( $theme['Stylesheet'] ); // Template files should all exist. - $this->assertTrue( is_array( $theme['Template Files'] ) ); - $this->assertTrue( count( $theme['Template Files'] ) > 0 ); + $this->assertIsArray( $theme['Template Files'] ); + $this->assertNotEmpty( $theme['Template Files'] ); foreach ( $theme['Template Files'] as $file ) { $this->assertTrue( is_file( $dir . $file ) ); $this->assertTrue( is_readable( $dir . $file ) ); } // CSS files should all exist. - $this->assertTrue( is_array( $theme['Stylesheet Files'] ) ); - $this->assertTrue( count( $theme['Stylesheet Files'] ) > 0 ); + $this->assertIsArray( $theme['Stylesheet Files'] ); + $this->assertNotEmpty( $theme['Stylesheet Files'] ); foreach ( $theme['Stylesheet Files'] as $file ) { $this->assertTrue( is_file( $dir . $file ) ); $this->assertTrue( is_readable( $dir . $file ) ); diff --git a/tests/phpunit/tests/user.php b/tests/phpunit/tests/user.php index 1917c3a54c..0830385e02 100644 --- a/tests/phpunit/tests/user.php +++ b/tests/phpunit/tests/user.php @@ -155,7 +155,7 @@ class Tests_User extends WP_UnitTestCase { ); // There is already some stuff in the array. - $this->assertTrue( is_array( get_user_meta( self::$author_id ) ) ); + $this->assertIsArray( get_user_meta( self::$author_id ) ); foreach ( $vals as $k => $v ) { update_user_meta( self::$author_id, $k, $v );