Make WordPress Core


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

    r47122 r48937  
    420420
    421421        $expected = array( $p1 );
    422         $this->assertEquals( $expected, $query->posts );
     422        $this->assertSame( $expected, $query->posts );
    423423    }
    424424
     
    673673
    674674        $expected = array( $post_id4 );
    675         $this->assertEquals( $expected, $query->posts );
     675        $this->assertSame( $expected, $query->posts );
    676676
    677677        $query = new WP_Query(
     
    697697        );
    698698
    699         $this->assertEquals( 0, count( $query->posts ) );
     699        $this->assertSame( 0, count( $query->posts ) );
    700700    }
    701701
     
    13741374        );
    13751375
    1376         $this->assertEquals( array( $posts[2], $posts[0], $posts[1] ), $query->posts );
     1376        $this->assertSame( array( $posts[2], $posts[0], $posts[1] ), $query->posts );
    13771377    }
    13781378
     
    14191419        );
    14201420
    1421         $this->assertEquals( array( $posts[2], $posts[0], $posts[1] ), $query->posts );
     1421        $this->assertSame( array( $posts[2], $posts[0], $posts[1] ), $query->posts );
    14221422    }
    14231423
     
    15351535
    15361536        $query = new WP_Query( $args );
    1537         $this->assertEquals( 2, count( $query->posts ) );
     1537        $this->assertSame( 2, count( $query->posts ) );
    15381538        foreach ( $query->posts as $post ) {
    15391539            $this->assertInstanceOf( 'WP_Post', $post );
    1540             $this->assertEquals( 'raw', $post->filter );
     1540            $this->assertSame( 'raw', $post->filter );
    15411541        }
    15421542        $posts = wp_list_pluck( $query->posts, 'ID' );
     
    15511551
    15521552        $query = new WP_Query( $args );
    1553         $this->assertEquals( 3, count( $query->posts ) );
     1553        $this->assertSame( 3, count( $query->posts ) );
    15541554        foreach ( $query->posts as $post ) {
    15551555            $this->assertInstanceOf( 'WP_Post', $post );
    1556             $this->assertEquals( 'raw', $post->filter );
     1556            $this->assertSame( 'raw', $post->filter );
    15571557        }
    15581558        $posts = wp_list_pluck( $query->posts, 'ID' );
     
    15831583        );
    15841584
    1585         $this->assertEquals( 2, count( $posts ) );
     1585        $this->assertSame( 2, count( $posts ) );
    15861586        $posts = wp_list_pluck( $posts, 'ID' );
    15871587        $this->assertEqualSets( array( $post_id, $post_id3 ), $posts );
     
    15951595        );
    15961596
    1597         $this->assertEquals( 2, count( $posts ) );
     1597        $this->assertSame( 2, count( $posts ) );
    15981598        foreach ( $posts as $post ) {
    15991599            $this->assertInstanceOf( 'WP_Post', $post );
    1600             $this->assertEquals( 'raw', $post->filter );
     1600            $this->assertSame( 'raw', $post->filter );
    16011601        }
    16021602        $posts = wp_list_pluck( $posts, 'ID' );
     
    16261626
    16271627        $posts = get_posts( $args );
    1628         $this->assertEquals( 2, count( $posts ) );
     1628        $this->assertSame( 2, count( $posts ) );
    16291629        foreach ( $posts as $post ) {
    16301630            $this->assertInstanceOf( 'WP_Post', $post );
    1631             $this->assertEquals( 'raw', $post->filter );
     1631            $this->assertSame( 'raw', $post->filter );
    16321632        }
    16331633        $posts = wp_list_pluck( $posts, 'ID' );
     
    16601660            )
    16611661        );
    1662         $this->assertEquals( 1, count( $q->posts ) );
     1662        $this->assertSame( 1, count( $q->posts ) );
    16631663        foreach ( $q->posts as $post ) {
    16641664            $this->assertInstanceOf( 'WP_Post', $post );
    1665             $this->assertEquals( 'raw', $post->filter );
     1665            $this->assertSame( 'raw', $post->filter );
    16661666        }
    1667         $this->assertEquals( $post_id, $q->posts[0]->ID );
     1667        $this->assertSame( $post_id, $q->posts[0]->ID );
    16681668
    16691669        $posts = get_posts(
     
    16731673            )
    16741674        );
    1675         $this->assertEquals( 2, count( $posts ) );
     1675        $this->assertSame( 2, count( $posts ) );
    16761676        foreach ( $posts as $post ) {
    16771677            $this->assertInstanceOf( 'WP_Post', $post );
    1678             $this->assertEquals( 'raw', $post->filter );
     1678            $this->assertSame( 'raw', $post->filter );
    16791679        }
    16801680        $posts = wp_list_pluck( $posts, 'ID' );
     
    16871687            )
    16881688        );
    1689         $this->assertEquals( 2, count( $posts ) );
     1689        $this->assertSame( 2, count( $posts ) );
    16901690        foreach ( $posts as $post ) {
    16911691            $this->assertInstanceOf( 'WP_Post', $post );
    1692             $this->assertEquals( 'raw', $post->filter );
     1692            $this->assertSame( 'raw', $post->filter );
    16931693        }
    16941694        $posts = wp_list_pluck( $posts, 'ID' );
     
    16961696
    16971697        $posts = get_posts( array( 'meta_value' => 0 ) );
    1698         $this->assertEquals( 5, count( $posts ) );
     1698        $this->assertSame( 5, count( $posts ) );
    16991699        foreach ( $posts as $post ) {
    17001700            $this->assertInstanceOf( 'WP_Post', $post );
    1701             $this->assertEquals( 'raw', $post->filter );
     1701            $this->assertSame( 'raw', $post->filter );
    17021702        }
    17031703        $posts = wp_list_pluck( $posts, 'ID' );
     
    17051705
    17061706        $posts = get_posts( array( 'meta_value' => '0' ) );
    1707         $this->assertEquals( 5, count( $posts ) );
     1707        $this->assertSame( 5, count( $posts ) );
    17081708        foreach ( $posts as $post ) {
    17091709            $this->assertInstanceOf( 'WP_Post', $post );
    1710             $this->assertEquals( 'raw', $post->filter );
     1710            $this->assertSame( 'raw', $post->filter );
    17111711        }
    17121712        $posts = wp_list_pluck( $posts, 'ID' );
     
    17371737        );
    17381738
    1739         $this->assertEquals( array( $posts[1], $posts[2], $posts[0] ), $q->posts );
     1739        $this->assertSame( array( $posts[1], $posts[2], $posts[0] ), $q->posts );
    17401740    }
    17411741
     
    17801780        );
    17811781
    1782         $this->assertEquals( array( $p3, $p1, $p2 ), $q->posts );
     1782        $this->assertSame( array( $p3, $p1, $p2 ), $q->posts );
    17831783    }
    17841784
     
    18161816        );
    18171817
    1818         $this->assertEquals( array( $posts[2], $posts[0], $posts[1] ), $q->posts );
     1818        $this->assertSame( array( $posts[2], $posts[0], $posts[1] ), $q->posts );
    18191819    }
    18201820
Note: See TracChangeset for help on using the changeset viewer.