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

    r48328 r48937  
    3636
    3737        $this->assertNotEmpty( $posts );
    38         $this->assertEquals( array( $post_id ), wp_list_pluck( $posts, 'ID' ) );
     38        $this->assertSame( array( $post_id ), wp_list_pluck( $posts, 'ID' ) );
    3939
    4040        $posts2 = $q->query( array( 'category__and' => array( $term_id, $term_id2 ) ) );
     
    9797
    9898        // Fourth post added in filter.
    99         $this->assertEquals( 4, count( $query->posts ) );
    100         $this->assertEquals( 4, $query->post_count );
     99        $this->assertSame( 4, count( $query->posts ) );
     100        $this->assertSame( 4, $query->post_count );
    101101
    102102        foreach ( $query->posts as $post ) {
     
    106106
    107107            // Filters are raw.
    108             $this->assertEquals( 'raw', $post->filter );
     108            $this->assertSame( 'raw', $post->filter );
    109109
    110110            // Custom data added in the_posts filter is preserved.
    111             $this->assertEquals( array( $post->ID, 'custom data' ), $post->custom_data );
     111            $this->assertSame( array( $post->ID, 'custom data' ), $post->custom_data );
    112112        }
    113113
     
    614614        );
    615615
    616         $this->assertEquals( 2, $q->found_posts );
     616        $this->assertSame( 2, $q->found_posts );
    617617        $this->assertEquals( 2, $q->max_num_pages );
    618618    }
     
    637637        );
    638638
    639         $this->assertEquals( 2, $q->found_posts );
     639        $this->assertSame( 2, $q->found_posts );
    640640        $this->assertEquals( 2, $q->max_num_pages );
    641641    }
     
    663663        remove_filter( 'split_the_query', '__return_true' );
    664664
    665         $this->assertEquals( 2, $q->found_posts );
     665        $this->assertSame( 2, $q->found_posts );
    666666        $this->assertEquals( 2, $q->max_num_pages );
    667667    }
     
    690690        remove_filter( 'split_the_query', '__return_false' );
    691691
    692         $this->assertEquals( 2, $q->found_posts );
     692        $this->assertSame( 2, $q->found_posts );
    693693        $this->assertEquals( 2, $q->max_num_pages );
    694694    }
     
    723723        $methd->invoke( $q, array( 'no_found_rows' => false ), array() );
    724724
    725         $this->assertEquals( $expected, $q->found_posts );
     725        $this->assertSame( $expected, $q->found_posts );
    726726    }
    727727
Note: See TracChangeset for help on using the changeset viewer.