Make WordPress Core


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

    r46586 r48937  
    2323            while ( $second_query->have_posts() ) {
    2424                $second_query->the_post();
    25                 $this->assertEquals( get_the_ID(), $nested_post_id );
     25                $this->assertSame( get_the_ID(), $nested_post_id );
    2626            }
    2727            $first_query->reset_postdata();
    28             $this->assertEquals( get_the_ID(), $post_id );
     28            $this->assertSame( get_the_ID(), $post_id );
    2929        }
    3030    }
     
    3535    function test_default_query_var() {
    3636        $query = new WP_Query;
    37         $this->assertEquals( '', $query->get( 'nonexistent' ) );
     37        $this->assertSame( '', $query->get( 'nonexistent' ) );
    3838        $this->assertFalse( $query->get( 'nonexistent', false ) );
    3939        $this->assertTrue( $query->get( 'nonexistent', true ) );
     
    5050        $this->go_to( get_feed_link() );
    5151
    52         $this->assertEquals( 30, get_query_var( 'posts_per_page' ) );
     52        $this->assertSame( 30, get_query_var( 'posts_per_page' ) );
    5353    }
    5454
     
    520520
    521521        $this->assertFalse( $GLOBALS['wp_query']->is_404() );
    522         $this->assertEquals( $post_id, $GLOBALS['wp_query']->post->ID );
     522        $this->assertSame( $post_id, $GLOBALS['wp_query']->post->ID );
    523523    }
    524524
     
    553553
    554554        $this->assertFalse( $GLOBALS['wp_query']->is_404() );
    555         $this->assertEquals( $post_id, $GLOBALS['wp_query']->post->ID );
     555        $this->assertSame( $post_id, $GLOBALS['wp_query']->post->ID );
    556556    }
    557557
Note: See TracChangeset for help on using the changeset viewer.