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/query/conditionals.php

    r47122 r48937  
    193193            // Make sure the correct page was fetched.
    194194            global $wp_query;
    195             $this->assertEquals( $page_id, $wp_query->get_queried_object()->ID );
     195            $this->assertSame( $page_id, $wp_query->get_queried_object()->ID );
    196196        }
    197197    }
     
    232232            // Make sure the correct page was fetched.
    233233            global $wp_query;
    234             $this->assertEquals( $page_id, $wp_query->get_queried_object()->ID );
     234            $this->assertSame( $page_id, $wp_query->get_queried_object()->ID );
    235235        }
    236236    }
     
    269269            // Make sure the correct page was fetched.
    270270            global $wp_query;
    271             $this->assertEquals( $page_id, $wp_query->get_queried_object()->ID );
     271            $this->assertSame( $page_id, $wp_query->get_queried_object()->ID );
    272272        }
    273273    }
     
    309309            // Make sure the correct page was fetched.
    310310            global $wp_query;
    311             $this->assertEquals( $page_id, $wp_query->get_queried_object()->ID );
     311            $this->assertSame( $page_id, $wp_query->get_queried_object()->ID );
    312312        }
    313313    }
     
    329329        // Make sure the correct page was fetched.
    330330        global $wp_query;
    331         $this->assertEquals( $page_id, $wp_query->get_queried_object()->ID );
     331        $this->assertSame( $page_id, $wp_query->get_queried_object()->ID );
    332332    }
    333333
     
    348348        // Make sure the correct page was fetched.
    349349        global $wp_query;
    350         $this->assertEquals( $page_id, $wp_query->get_queried_object()->ID );
     350        $this->assertSame( $page_id, $wp_query->get_queried_object()->ID );
    351351    }
    352352
     
    369369        // Make sure the correct page was fetched.
    370370        global $wp_query;
    371         $this->assertEquals( $page_id, $wp_query->get_queried_object()->ID );
     371        $this->assertSame( $page_id, $wp_query->get_queried_object()->ID );
    372372
    373373        update_option( 'show_on_front', 'posts' );
     
    483483    function test_search_encoded_chars() {
    484484        $this->go_to( '/search/F%C3%BCnf%2Bbar/' );
    485         $this->assertEquals( get_query_var( 's' ), 'Fünf+bar' );
     485        $this->assertSame( get_query_var( 's' ), 'Fünf+bar' );
    486486    }
    487487
     
    824824        $this->go_to( '/ptawtq/' );
    825825        $this->assertQueryTrue( 'is_post_type_archive', 'is_archive' );
    826         $this->assertEquals( get_queried_object(), get_post_type_object( $cpt_name ) );
     826        $this->assertSame( get_queried_object(), get_post_type_object( $cpt_name ) );
    827827
    828828        add_action( 'pre_get_posts', array( $this, 'pre_get_posts_with_tax_query' ) );
     
    830830        $this->go_to( '/ptawtq/' );
    831831        $this->assertQueryTrue( 'is_post_type_archive', 'is_archive' );
    832         $this->assertEquals( get_queried_object(), get_post_type_object( $cpt_name ) );
     832        $this->assertSame( get_queried_object(), get_post_type_object( $cpt_name ) );
    833833
    834834        remove_action( 'pre_get_posts', array( $this, 'pre_get_posts_with_tax_query' ) );
     
    866866        $this->go_to( "/$cpt_name/" );
    867867        $this->assertQueryTrue( 'is_post_type_archive', 'is_archive' );
    868         $this->assertEquals( get_queried_object(), get_post_type_object( $cpt_name ) );
     868        $this->assertSame( get_queried_object(), get_post_type_object( $cpt_name ) );
    869869
    870870        add_action( 'pre_get_posts', array( $this, 'pre_get_posts_with_type_array' ) );
     
    872872        $this->go_to( "/$cpt_name/" );
    873873        $this->assertQueryTrue( 'is_post_type_archive', 'is_archive' );
    874         $this->assertEquals( get_queried_object(), get_post_type_object( 'post' ) );
     874        $this->assertSame( get_queried_object(), get_post_type_object( 'post' ) );
    875875
    876876        remove_action( 'pre_get_posts', array( $this, 'pre_get_posts_with_type_array' ) );
Note: See TracChangeset for help on using the changeset viewer.