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/getTheTerms.php

    r46586 r48937  
    2323        // Cache should be empty after a set.
    2424        $tt_1 = wp_set_object_terms( $post_id, $terms_1, $this->taxonomy );
    25         $this->assertEquals( 3, count( $tt_1 ) );
     25        $this->assertSame( 3, count( $tt_1 ) );
    2626        $this->assertFalse( wp_cache_get( $post_id, $this->taxonomy . '_relationships' ) );
    2727
     
    4444        // Cache should be empty after a set.
    4545        $tt_2 = wp_set_object_terms( $post_id, $terms_2, $this->taxonomy );
    46         $this->assertEquals( 2, count( $tt_2 ) );
     46        $this->assertSame( 2, count( $tt_2 ) );
    4747        $this->assertFalse( wp_cache_get( $post_id, $this->taxonomy . '_relationships' ) );
    4848    }
     
    6363
    6464        $terms = get_the_terms( $post_id, 'post_tag' );
    65         $this->assertEquals( $tag_id, $terms[0]->term_id );
    66         $this->assertEquals( 'My Amazing Tag', $terms[0]->description );
     65        $this->assertSame( $tag_id, $terms[0]->term_id );
     66        $this->assertSame( 'My Amazing Tag', $terms[0]->description );
    6767
    6868        $_updated = wp_update_term(
     
    7575
    7676        $_new_term = get_term( $tag_id, 'post_tag' );
    77         $this->assertEquals( $tag_id, $_new_term->term_id );
    78         $this->assertEquals( 'This description is even more amazing!', $_new_term->description );
     77        $this->assertSame( $tag_id, $_new_term->term_id );
     78        $this->assertSame( 'This description is even more amazing!', $_new_term->description );
    7979
    8080        $terms = get_the_terms( $post_id, 'post_tag' );
    81         $this->assertEquals( $tag_id, $terms[0]->term_id );
    82         $this->assertEquals( 'This description is even more amazing!', $terms[0]->description );
     81        $this->assertSame( $tag_id, $terms[0]->term_id );
     82        $this->assertSame( 'This description is even more amazing!', $terms[0]->description );
    8383    }
    8484
Note: See TracChangeset for help on using the changeset viewer.