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

    r47122 r48937  
    114114            $tt = wp_set_object_terms( $id, array_values( $term_id ), $this->taxonomy );
    115115            // Should return three term taxonomy IDs.
    116             $this->assertEquals( 3, count( $tt ) );
     116            $this->assertSame( 3, count( $tt ) );
    117117        }
    118118
     
    120120        foreach ( $term_id as $term => $id ) {
    121121            $actual = get_objects_in_term( $id, $this->taxonomy );
    122             $this->assertEquals( $ids, array_map( 'intval', $actual ) );
     122            $this->assertSame( $ids, array_map( 'intval', $actual ) );
    123123        }
    124124
     
    126126        foreach ( array_keys( $term_id ) as $term ) {
    127127            $t = get_term_by( 'name', $term, $this->taxonomy );
    128             $this->assertEquals( 5, $t->count );
     128            $this->assertSame( 5, $t->count );
    129129        }
    130130    }
     
    142142            $tt = wp_set_object_terms( $id, $terms, $this->taxonomy );
    143143            // Should return three term taxonomy IDs.
    144             $this->assertEquals( 3, count( $tt ) );
     144            $this->assertSame( 3, count( $tt ) );
    145145            // Remember which term has which term_id.
    146146            for ( $i = 0; $i < 3; $i++ ) {
     
    153153        foreach ( $term_id as $term => $id ) {
    154154            $actual = get_objects_in_term( $id, $this->taxonomy );
    155             $this->assertEquals( $ids, array_map( 'intval', $actual ) );
     155            $this->assertSame( $ids, array_map( 'intval', $actual ) );
    156156        }
    157157
     
    159159        foreach ( $terms as $term ) {
    160160            $t = get_term_by( 'name', $term, $this->taxonomy );
    161             $this->assertEquals( 5, $t->count );
     161            $this->assertSame( 5, $t->count );
    162162        }
    163163    }
     
    269269        // Set the initial terms.
    270270        $tt_1 = wp_set_object_terms( $post_id, $terms_1, $this->taxonomy );
    271         $this->assertEquals( 3, count( $tt_1 ) );
     271        $this->assertSame( 3, count( $tt_1 ) );
    272272
    273273        // Make sure they're correct.
     
    280280            )
    281281        );
    282         $this->assertEquals( $terms_1, $terms );
     282        $this->assertSame( $terms_1, $terms );
    283283
    284284        // Change the terms.
    285285        $tt_2 = wp_set_object_terms( $post_id, $terms_2, $this->taxonomy );
    286         $this->assertEquals( 2, count( $tt_2 ) );
     286        $this->assertSame( 2, count( $tt_2 ) );
    287287
    288288        // Make sure they're correct.
     
    295295            )
    296296        );
    297         $this->assertEquals( $terms_2, $terms );
     297        $this->assertSame( $terms_2, $terms );
    298298
    299299        // Make sure the term taxonomy ID for 'bar' matches.
    300         $this->assertEquals( $tt_1[1], $tt_2[0] );
     300        $this->assertSame( $tt_1[1], $tt_2[0] );
    301301
    302302    }
     
    313313        // Set the initial terms.
    314314        $tt_1 = wp_set_object_terms( $post_id, $terms_1, $this->taxonomy );
    315         $this->assertEquals( 3, count( $tt_1 ) );
     315        $this->assertSame( 3, count( $tt_1 ) );
    316316
    317317        // Make sure they're correct.
     
    324324            )
    325325        );
    326         $this->assertEquals( $terms_1, $terms );
     326        $this->assertSame( $terms_1, $terms );
    327327
    328328        // Change the terms.
    329329        $tt_2 = wp_set_object_terms( $post_id, $terms_2, $this->taxonomy );
    330         $this->assertEquals( 2, count( $tt_2 ) );
     330        $this->assertSame( 2, count( $tt_2 ) );
    331331
    332332        // Make sure they're correct.
     
    339339            )
    340340        );
    341         $this->assertEquals( $terms_2, $terms );
     341        $this->assertSame( $terms_2, $terms );
    342342
    343343        // Make sure the term taxonomy ID for 'bar' matches.
Note: See TracChangeset for help on using the changeset viewer.