Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (17 months 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/wpGetObjectTerms.php

    r47122 r48937  
    2121        // Set the initial terms.
    2222        $tt_1 = wp_set_object_terms( $post_id, $terms_1, $this->taxonomy );
    23         $this->assertEquals( 3, count( $tt_1 ) );
     23        $this->assertSame( 3, count( $tt_1 ) );
    2424
    2525        // Make sure they're correct.
     
    3232            )
    3333        );
    34         $this->assertEquals( $terms_1_slugs, $terms );
     34        $this->assertSame( $terms_1_slugs, $terms );
    3535    }
    3636
     
    4848        $terms = wp_get_object_terms( array( $post_id1, $post_id2 ), 'category' );
    4949        $this->assertCount( 2, $terms );
    50         $this->assertEquals( array( $cat_id, $cat_id2 ), wp_list_pluck( $terms, 'term_id' ) );
     50        $this->assertSame( array( $cat_id, $cat_id2 ), wp_list_pluck( $terms, 'term_id' ) );
    5151
    5252        $terms2 = wp_get_object_terms(
     
    5959
    6060        $this->assertCount( 3, $terms2 );
    61         $this->assertEquals( array( $cat_id, $cat_id, $cat_id2 ), wp_list_pluck( $terms2, 'term_id' ) );
     61        $this->assertSame( array( $cat_id, $cat_id, $cat_id2 ), wp_list_pluck( $terms2, 'term_id' ) );
    6262    }
    6363
     
    150150        );
    151151
    152         $this->assertEquals( array( $t1, $t3, $t2 ), $found );
     152        $this->assertSame( array( $t1, $t3, $t2 ), $found );
    153153    }
    154154
     
    188188        );
    189189
    190         $this->assertEquals( array( $t2, $t1, $t3 ), $found );
     190        $this->assertSame( array( $t2, $t1, $t3 ), $found );
    191191    }
    192192
     
    224224        );
    225225
    226         $this->assertEquals( array( $t1, $t3, $t2 ), $found );
     226        $this->assertSame( array( $t1, $t3, $t2 ), $found );
    227227    }
    228228
     
    263263        );
    264264
    265         $this->assertEquals( array( $t1, $t3, $t2 ), $found );
     265        $this->assertSame( array( $t1, $t3, $t2 ), $found );
    266266    }
    267267
     
    327327        );
    328328
    329         $this->assertEquals( array( $t1, $t3, $t2 ), $found );
     329        $this->assertSame( array( $t1, $t3, $t2 ), $found );
    330330    }
    331331
     
    372372        );
    373373
    374         $this->assertEquals( array( $t1, $t3, $t2 ), $found );
     374        $this->assertSame( array( $t1, $t3, $t2 ), $found );
    375375    }
    376376
     
    413413        );
    414414
    415         $this->assertEquals( array( $t1, $t3, $t2 ), $found );
     415        $this->assertSame( array( $t1, $t3, $t2 ), $found );
    416416    }
    417417
     
    459459        );
    460460
    461         $this->assertEquals( array( $t1, $t3, $t2 ), $found );
     461        $this->assertSame( array( $t1, $t3, $t2 ), $found );
    462462    }
    463463
     
    496496        );
    497497
    498         $this->assertEquals( array( $t2, $t3, $t1 ), $found );
     498        $this->assertSame( array( $t2, $t3, $t1 ), $found );
    499499    }
    500500
     
    547547        );
    548548
    549         $this->assertEquals( array( $t3 ), $found );
     549        $this->assertSame( array( $t3 ), $found );
    550550    }
    551551
     
    928928        $found = wp_get_object_terms( $p, $this->taxonomy, 'orderby=name&fields=ids' );
    929929
    930         $this->assertEquals( array( $t1, $t3, $t2 ), $found );
     930        $this->assertSame( array( $t1, $t3, $t2 ), $found );
    931931    }
    932932
     
    947947        // Test directly.
    948948        $get_object_terms = wp_get_object_terms( $post_id, $taxonomy, array( 'fields' => 'names' ) );
    949         $this->assertEquals( $terms, $get_object_terms );
     949        $this->assertSame( $terms, $get_object_terms );
    950950
    951951        // Test metabox taxonomy (admin advanced edit).
    952952        $terms_to_edit = get_terms_to_edit( $post_id, $taxonomy );
    953         $this->assertEquals( implode( ',', $terms ), $terms_to_edit );
     953        $this->assertSame( implode( ',', $terms ), $terms_to_edit );
    954954    }
    955955
Note: See TracChangeset for help on using the changeset viewer.