Tests: Use more appropriate assertions in various tests.

This replaces instances of `assertTrue( is_numeric( ... ) )` with `assertIsNumeric()` to use native PHPUnit functionality.

Follow-up to [51335], [51337], [51367], [51397], [51403], [51404], [51436].

See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51438 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2021-07-15 14:44:22 +00:00
parent cc5e3f7811
commit 56a90eb273
9 changed files with 14 additions and 14 deletions

View File

@ -205,7 +205,7 @@ class Tests_Ajax_DeleteComment extends WP_Ajax_UnitTestCase {
$this->fail( 'Expected exception: WPAjaxDieStopException' );
} catch ( WPAjaxDieStopException $e ) {
$this->assertSame( 10, strlen( $e->getMessage() ) );
$this->assertTrue( is_numeric( $e->getMessage() ) );
$this->assertIsNumeric( $e->getMessage() );
} catch ( Exception $e ) {
$this->fail( 'Unexpected exception type: ' . get_class( $e ) );
}
@ -255,7 +255,7 @@ class Tests_Ajax_DeleteComment extends WP_Ajax_UnitTestCase {
$this->fail( 'Expected exception: WPAjaxDieStopException' );
} catch ( WPAjaxDieStopException $e ) {
$this->assertSame( 10, strlen( $e->getMessage() ) );
$this->assertTrue( is_numeric( $e->getMessage() ) );
$this->assertIsNumeric( $e->getMessage() );
} catch ( Exception $e ) {
$this->fail( 'Unexpected exception type: ' . get_class( $e ) );
}

View File

@ -1214,7 +1214,7 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase {
$this->assertSame( $manager->changeset_uuid(), get_post( $post_id )->post_name, 'Expected that the "__trashed" suffix to not be added.' );
wp_set_current_user( self::$admin_user_id );
$this->assertSame( 'publish', get_post_meta( $post_id, '_wp_trash_meta_status', true ) );
$this->assertTrue( is_numeric( get_post_meta( $post_id, '_wp_trash_meta_time', true ) ) );
$this->assertIsNumeric( get_post_meta( $post_id, '_wp_trash_meta_time', true ) );
foreach ( array_keys( $expected_actions ) as $action_name ) {
$this->assertSame( $expected_actions[ $action_name ] + $action_counts[ $action_name ], did_action( $action_name ), "Action: $action_name" );

View File

@ -1198,7 +1198,7 @@ class Tests_Functions extends WP_UnitTestCase {
for ( $i = 0; $i < 20; $i += 1 ) {
$id = wp_unique_id();
$this->assertIsString( $id );
$this->assertTrue( is_numeric( $id ) );
$this->assertIsNumeric( $id );
$ids[] = $id;
}
$this->assertSame( $ids, array_unique( $ids ) );

View File

@ -79,7 +79,7 @@ class Tests_Post extends WP_UnitTestCase {
// Insert a post and make sure the ID is OK.
$id = wp_insert_post( $post );
$this->assertTrue( is_numeric( $id ) );
$this->assertIsNumeric( $id );
$this->assertTrue( $id > 0 );
// Fetch the post and make sure it matches.
@ -135,7 +135,7 @@ class Tests_Post extends WP_UnitTestCase {
$id = wp_insert_post( $post );
$this->post_ids[] = $id;
// dmp( _get_cron_array() );
$this->assertTrue( is_numeric( $id ) );
$this->assertIsNumeric( $id );
$this->assertTrue( $id > 0 );
// Fetch the post and make sure it matches.
@ -258,7 +258,7 @@ class Tests_Post extends WP_UnitTestCase {
$id = wp_insert_post( $post );
$this->post_ids[] = $id;
// dmp( _get_cron_array() );
$this->assertTrue( is_numeric( $id ) );
$this->assertIsNumeric( $id );
$this->assertTrue( $id > 0 );
// Fetch the post and make sure it matches.
@ -379,7 +379,7 @@ class Tests_Post extends WP_UnitTestCase {
$id = wp_insert_post( $post );
$this->post_ids[] = $id;
// dmp( _get_cron_array() );
$this->assertTrue( is_numeric( $id ) );
$this->assertIsNumeric( $id );
$this->assertTrue( $id > 0 );
// Fetch the post and make sure it matches.

View File

@ -420,7 +420,7 @@ class Tests_Taxonomy extends WP_UnitTestCase {
'taxonomy' => 'category',
'cat_name' => 'test1',
);
$this->assertTrue( is_numeric( wp_insert_category( $cat, true ) ) );
$this->assertIsNumeric( wp_insert_category( $cat, true ) );
}
function test_insert_category_update() {

View File

@ -153,7 +153,7 @@ class Tests_Term extends WP_UnitTestCase {
$initial_count = wp_count_terms( array( 'taxonomy' => 'category' ) );
$t = wp_insert_category( array( 'cat_name' => $term ) );
$this->assertTrue( is_numeric( $t ) );
$this->assertIsNumeric( $t );
$this->assertNotWPError( $t );
$this->assertTrue( $t > 0 );
$this->assertEquals( $initial_count + 1, wp_count_terms( array( 'taxonomy' => 'category' ) ) );

View File

@ -159,7 +159,7 @@ class Tests_Theme_GetThemeStarterContent extends WP_UnitTestCase {
foreach ( $hydrated_starter_content['posts'] as $key => $post ) {
$this->assertIsString( $key );
$this->assertFalse( is_numeric( $key ) );
$this->assertIsNotNumeric( $key );
$this->assertIsArray( $post );
$this->assertArrayHasKey( 'post_type', $post );
$this->assertArrayHasKey( 'post_title', $post );

View File

@ -482,7 +482,7 @@ class Tests_User extends WP_UnitTestCase {
// Insert a post and make sure the ID is OK.
$post_id = wp_insert_post( $post );
$this->assertTrue( is_numeric( $post_id ) );
$this->assertIsNumeric( $post_id );
setup_postdata( get_post( $post_id ) );

View File

@ -67,7 +67,7 @@ class Tests_User_WpDeleteUser extends WP_UnitTestCase {
// Insert a post and make sure the ID is OK.
$post_id = wp_insert_post( $post );
$this->assertTrue( is_numeric( $post_id ) );
$this->assertIsNumeric( $post_id );
$this->assertTrue( $post_id > 0 );
$post = get_post( $post_id );
@ -83,7 +83,7 @@ class Tests_User_WpDeleteUser extends WP_UnitTestCase {
// Insert a post and make sure the ID is OK.
$nav_id = wp_insert_post( $post );
$this->assertTrue( is_numeric( $nav_id ) );
$this->assertIsNumeric( $nav_id );
$this->assertTrue( $nav_id > 0 );
$post = get_post( $nav_id );