WordPress.org

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

    r47122 r48937  
    5151
    5252        $posts = $this->get_search_results( 'About' );
    53         $this->assertEquals( $post_id, reset( $posts )->ID );
     53        $this->assertSame( $post_id, reset( $posts )->ID );
    5454    }
    5555
     
    5858        $query = new WP_Query( array( 's' => 'This is a search term' ) );
    5959        $this->assertNotEquals( explode( ' ', $terms ), $query->get( 'search_terms' ) );
    60         $this->assertEquals( array( 'search', 'term' ), $query->get( 'search_terms' ) );
     60        $this->assertSame( array( 'search', 'term' ), $query->get( 'search_terms' ) );
    6161    }
    6262
     
    6868
    6969        $this->assertNotEquals( array( 'search', 'term' ), $query->get( 'search_terms' ) );
    70         $this->assertEquals( array( 'This', 'is', 'search', 'term' ), $query->get( 'search_terms' ) );
     70        $this->assertSame( array( 'This', 'is', 'search', 'term' ), $query->get( 'search_terms' ) );
    7171    }
    7272
     
    9090
    9191        // By default, we can use the hyphen prefix to exclude results.
    92         $this->assertEquals( array(), $this->get_search_results( $title ) );
     92        $this->assertSame( array(), $this->get_search_results( $title ) );
    9393
    9494        // After we disable the feature using the filter, we should get the result.
     
    9696        $result = $this->get_search_results( $title );
    9797        $post   = array_pop( $result );
    98         $this->assertEquals( $post->ID, $post_id );
     98        $this->assertSame( $post->ID, $post_id );
    9999        remove_filter( 'wp_query_search_exclusion_prefix', '__return_false' );
    100100    }
     
    117117        $result = $this->get_search_results( $title );
    118118        $post   = array_pop( $result );
    119         $this->assertEquals( $post->ID, $post_id );
     119        $this->assertSame( $post->ID, $post_id );
    120120
    121121        // After we change the prefix, the result should be excluded.
     
    123123        $found = $this->get_search_results( $title );
    124124        remove_filter( 'wp_query_search_exclusion_prefix', array( $this, 'filter_search_exclusion_prefix_octothorpe' ) );
    125         $this->assertEquals( array(), $found );
     125        $this->assertSame( array(), $found );
    126126    }
    127127
Note: See TracChangeset for help on using the changeset viewer.