WordPress.org

Make WordPress Core

Changeset 51454


Ignore:
Timestamp:
07/18/2021 02:10:24 PM (5 months ago)
Author:
SergeyBiryukov
Message:

Tests: Use more appropriate assertions in various tests.

This replaces instances of assertTrue( ... > 0 ) with assertGreaterThan() to use native PHPUnit functionality.

Follow-up to [51335], [51337], [51367], [51397], [51403], [51404], [51436], [51438], [51448], [51449], [51451], [51453].

See #53363.

Location:
trunk/tests/phpunit/tests
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/bookmark/getBookmarks.php

    r51139 r51454  
    5656
    5757        $this->assertEqualSets( $bookmarks, wp_list_pluck( $found2, 'link_id' ) );
    58         $this->assertTrue( $num_queries < $wpdb->num_queries );
     58        $this->assertGreaterThan( $num_queries, $wpdb->num_queries );
    5959    }
    6060
     
    8383        // Equal sets != same order.
    8484        $this->assertEqualSets( $found1, $found2 );
    85         $this->assertTrue( $num_queries < $wpdb->num_queries );
     85        $this->assertGreaterThan( $num_queries, $wpdb->num_queries );
    8686    }
    8787
  • trunk/tests/phpunit/tests/cron.php

    r50610 r51454  
    127127
    128128        // Make sure they're returned by wp_next_scheduled().
    129         $this->assertTrue( wp_next_scheduled( $hook ) > 0 );
    130         $this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 );
     129        $this->assertGreaterThan( 0, wp_next_scheduled( $hook ) );
     130        $this->assertGreaterThan( 0, wp_next_scheduled( $hook, $args ) );
    131131
    132132        // Clear the schedule for the no args events and make sure it's gone.
     
    135135        $this->assertFalse( wp_next_scheduled( $hook ) );
    136136        // The args events should still be there.
    137         $this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 );
     137        $this->assertGreaterThan( 0, wp_next_scheduled( $hook, $args ) );
    138138
    139139        // Clear the schedule for the args events and make sure they're gone too.
     
    166166
    167167        // Make sure they're returned by wp_next_scheduled().
    168         $this->assertTrue( wp_next_scheduled( $hook ) > 0 );
    169         $this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 );
     168        $this->assertGreaterThan( 0, wp_next_scheduled( $hook ) );
     169        $this->assertGreaterThan( 0, wp_next_scheduled( $hook, $args ) );
    170170
    171171        // Clear the schedule for the no args events and make sure it's gone.
     
    173173        $this->assertFalse( wp_next_scheduled( $hook ) );
    174174        // The args events should still be there.
    175         $this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 );
     175        $this->assertGreaterThan( 0, wp_next_scheduled( $hook, $args ) );
    176176
    177177        // Clear the schedule for the args events and make sure they're gone too.
     
    199199
    200200        // Make sure they're returned by wp_next_scheduled().
    201         $this->assertTrue( wp_next_scheduled( $hook ) > 0 );
    202         $this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 );
     201        $this->assertGreaterThan( 0, wp_next_scheduled( $hook ) );
     202        $this->assertGreaterThan( 0, wp_next_scheduled( $hook, $args ) );
    203203
    204204        // Clear the schedule for the no args events and make sure it's gone.
     
    206206        $this->assertFalse( wp_next_scheduled( $hook ) );
    207207        // The args events should still be there.
    208         $this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 );
     208        $this->assertGreaterThan( 0, wp_next_scheduled( $hook, $args ) );
    209209
    210210        // Clear the schedule for the args events and make sure they're gone too.
     
    233233
    234234        // Make sure they're returned by wp_next_scheduled().
    235         $this->assertTrue( wp_next_scheduled( $hook ) > 0 );
    236         $this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 );
     235        $this->assertGreaterThan( 0, wp_next_scheduled( $hook ) );
     236        $this->assertGreaterThan( 0, wp_next_scheduled( $hook, $args ) );
    237237
    238238        // Clear the schedule and make sure it's gone.
  • trunk/tests/phpunit/tests/meta.php

    r51367 r51454  
    345345        $negative_mid = $this->meta_id * -1;
    346346
    347         $this->assertTrue( $negative_mid < 0 );
     347        $this->assertLessThan( 0, $negative_mid );
    348348        $this->assertFalse( get_metadata_by_mid( 'user', $negative_mid ) );
    349349        $this->assertFalse( update_metadata_by_mid( 'user', $negative_mid, 'meta_new_value' ) );
  • trunk/tests/phpunit/tests/multisite/network.php

    r51331 r51454  
    452452            $user_count = (int) get_user_count();
    453453
    454             $this->assertTrue( $site_count > 0 && $user_count > 0 );
     454            $this->assertGreaterThan( 0, $site_count );
     455            $this->assertGreaterThan( 0, $user_count );
    455456        }
    456457
     
    467468            $user_count = (int) get_user_count( self::$different_network_id );
    468469
    469             $this->assertTrue( $site_count > 0 && $user_count > 0 );
     470            $this->assertGreaterThan( 0, $site_count );
     471            $this->assertGreaterThan( 0, $user_count );
    470472        }
    471473
  • trunk/tests/phpunit/tests/post.php

    r51438 r51454  
    8181            $id = wp_insert_post( $post );
    8282            $this->assertIsNumeric( $id );
    83             $this->assertTrue( $id > 0 );
     83            $this->assertGreaterThan( 0, $id );
    8484
    8585            // Fetch the post and make sure it matches.
     
    137137        // dmp( _get_cron_array() );
    138138        $this->assertIsNumeric( $id );
    139         $this->assertTrue( $id > 0 );
     139        $this->assertGreaterThan( 0, $id );
    140140
    141141        // Fetch the post and make sure it matches.
     
    260260        // dmp( _get_cron_array() );
    261261        $this->assertIsNumeric( $id );
    262         $this->assertTrue( $id > 0 );
     262        $this->assertGreaterThan( 0, $id );
    263263
    264264        // Fetch the post and make sure it matches.
     
    381381        // dmp( _get_cron_array() );
    382382        $this->assertIsNumeric( $id );
    383         $this->assertTrue( $id > 0 );
     383        $this->assertGreaterThan( 0, $id );
    384384
    385385        // Fetch the post and make sure it matches.
     
    794794        );
    795795        $insert_post_id = wp_insert_post( $post_data, true, true );
    796         $this->assertTrue( ( is_int( $insert_post_id ) && $insert_post_id > 0 ) );
     796        $this->assertIsInt( $insert_post_id );
     797        $this->assertGreaterThan( 0, $insert_post_id );
    797798
    798799        $post = get_post( $insert_post_id );
  • trunk/tests/phpunit/tests/rest-api/rest-controller.php

    r51453 r51454  
    514514        $first_call_count = $listener->get_call_count( $method );
    515515
    516         $this->assertTrue( $first_call_count > 0 );
     516        $this->assertGreaterThan( 0, $first_call_count );
    517517
    518518        $request->set_param( '_fields', 'somestring' );
     
    526526        $controller->prepare_item_for_response( $item, $request );
    527527
    528         $this->assertTrue( $listener->get_call_count( $method ) > $first_call_count );
     528        $this->assertGreaterThan( $first_call_count, $listener->get_call_count( $method ) );
    529529    }
    530530
  • trunk/tests/phpunit/tests/term.php

    r51438 r51454  
    156156        $this->assertIsNumeric( $t );
    157157        $this->assertNotWPError( $t );
    158         $this->assertTrue( $t > 0 );
     158        $this->assertGreaterThan( 0, $t );
    159159        $this->assertEquals( $initial_count + 1, wp_count_terms( array( 'taxonomy' => 'category' ) ) );
    160160
    161161        // Make sure the term exists.
    162         $this->assertTrue( term_exists( $term ) > 0 );
    163         $this->assertTrue( term_exists( $t ) > 0 );
     162        $this->assertGreaterThan( 0, term_exists( $term ) );
     163        $this->assertGreaterThan( 0, term_exists( $t ) );
    164164
    165165        // Now delete it.
  • trunk/tests/phpunit/tests/term/wpInsertTerm.php

    r51404 r51454  
    3030        $this->assertIsArray( $t );
    3131        $this->assertNotWPError( $t );
    32         $this->assertTrue( $t['term_id'] > 0 );
    33         $this->assertTrue( $t['term_taxonomy_id'] > 0 );
     32        $this->assertGreaterThan( 0, $t['term_id'] );
     33        $this->assertGreaterThan( 0, $t['term_taxonomy_id'] );
    3434        $this->assertEquals( $initial_count + 1, wp_count_terms( array( 'taxonomy' => $taxonomy ) ) );
    3535
    3636        // Make sure the term exists.
    37         $this->assertTrue( term_exists( $term ) > 0 );
    38         $this->assertTrue( term_exists( $t['term_id'] ) > 0 );
     37        $this->assertGreaterThan( 0, term_exists( $term ) );
     38        $this->assertGreaterThan( 0, term_exists( $t['term_id'] ) );
    3939
    4040        // Now delete it.
  • trunk/tests/phpunit/tests/theme.php

    r51403 r51454  
    141141            $this->assertNotEmpty( $theme['Description'] );
    142142            $this->assertNotEmpty( $theme['Author'] );
    143             $this->assertTrue( version_compare( $theme['Version'], 0 ) > 0 );
     143            $this->assertGreaterThan( 0, version_compare( $theme['Version'], 0 ) );
    144144            $this->assertNotEmpty( $theme['Template'] );
    145145            $this->assertNotEmpty( $theme['Stylesheet'] );
  • trunk/tests/phpunit/tests/user/wpDeleteUser.php

    r51438 r51454  
    6969        $post_id = wp_insert_post( $post );
    7070        $this->assertIsNumeric( $post_id );
    71         $this->assertTrue( $post_id > 0 );
     71        $this->assertGreaterThan( 0, $post_id );
    7272
    7373        $post = get_post( $post_id );
     
    8585        $nav_id = wp_insert_post( $post );
    8686        $this->assertIsNumeric( $nav_id );
    87         $this->assertTrue( $nav_id > 0 );
     87        $this->assertGreaterThan( 0, $nav_id );
    8888
    8989        $post = get_post( $nav_id );
Note: See TracChangeset for help on using the changeset viewer.