Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (4 years ago)
Author:
SergeyBiryukov
Message:

Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests.

This ensures that not only the return values match the expected results, but also that their type is the same.

Going forward, stricter type checking by using assertSame() should generally be preferred to assertEquals() where appropriate, to make the tests more reliable.

Props johnbillion, jrf, SergeyBiryukov.
See #38266.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/term/splitSharedTerm.php

    r46586 r48937  
    101101        );
    102102
    103         $this->assertEquals( $this->terms['t2_child']['term_taxonomy_id'], $children[0]->term_taxonomy_id );
     103        $this->assertSame( $this->terms['t2_child']['term_taxonomy_id'], $children[0]->term_taxonomy_id );
    104104    }
    105105
     
    116116        );
    117117
    118         $this->assertEquals( $this->terms['t2_child']['term_taxonomy_id'], $children[0]->term_taxonomy_id );
     118        $this->assertSame( $this->terms['t2_child']['term_taxonomy_id'], $children[0]->term_taxonomy_id );
    119119    }
    120120
     
    157157
    158158        $t2_children = get_term_children( $t2['term_id'], 'wptests_tax_4' );
    159         $this->assertEquals( array( $new_term_id ), $t2_children );
     159        $this->assertSame( array( $new_term_id ), $t2_children );
    160160    }
    161161
     
    181181        );
    182182
    183         $this->assertEquals( $t1['term_id'], get_option( 'default_category', -1 ) );
     183        $this->assertSame( $t1['term_id'], get_option( 'default_category', -1 ) );
    184184
    185185        $new_term_id = _split_shared_term( $t1['term_id'], $t1['term_taxonomy_id'] );
    186186
    187187        $this->assertNotEquals( $new_term_id, $t1['term_id'] );
    188         $this->assertEquals( $new_term_id, get_option( 'default_category', -1 ) );
     188        $this->assertSame( $new_term_id, get_option( 'default_category', -1 ) );
    189189    }
    190190
     
    253253
    254254        $locations = get_nav_menu_locations();
    255         $this->assertEquals( $new_term_id, $locations['foo'] );
     255        $this->assertSame( $new_term_id, $locations['foo'] );
    256256    }
    257257
     
    302302
    303303        $menu_items = wp_get_nav_menu_items( $new_nav_menu_id );
    304         $this->assertEquals( array( $cat_menu_item ), wp_list_pluck( $menu_items, 'ID' ) );
     304        $this->assertSame( array( $cat_menu_item ), wp_list_pluck( $menu_items, 'ID' ) );
    305305    }
    306306
     
    318318    public function test_wp_get_split_term() {
    319319        $found = wp_get_split_term( $this->terms['t1']['term_id'], 'wptests_tax_3' );
    320         $this->assertEquals( $this->terms['t3']['term_id'], $found );
     320        $this->assertSame( $this->terms['t3']['term_id'], $found );
    321321    }
    322322}
Note: See TracChangeset for help on using the changeset viewer.