WordPress.org

Make WordPress Core


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

    r47366 r48937  
    88        $post_id = self::factory()->post->create();
    99
    10         $this->assertEquals( 0, get_comments_number( 0 ) );
    11         $this->assertEquals( 0, get_comments_number( $post_id ) );
    12         $this->assertEquals( 0, get_comments_number( get_post( $post_id ) ) );
     10        $this->assertSame( 0, get_comments_number( 0 ) );
     11        $this->assertSame( '0', get_comments_number( $post_id ) );
     12        $this->assertSame( '0', get_comments_number( get_post( $post_id ) ) );
    1313
    1414        self::factory()->comment->create_post_comments( $post_id, 12 );
    1515
    16         $this->assertEquals( 12, get_comments_number( $post_id ) );
    17         $this->assertEquals( 12, get_comments_number( get_post( $post_id ) ) );
     16        $this->assertSame( '12', get_comments_number( $post_id ) );
     17        $this->assertSame( '12', get_comments_number( get_post( $post_id ) ) );
    1818    }
    1919
     
    2323        $this->go_to( $permalink );
    2424
    25         $this->assertEquals( 0, get_comments_number() );
     25        $this->assertSame( '0', get_comments_number() );
    2626
    2727        self::factory()->comment->create_post_comments( $post_id, 12 );
    2828        $this->go_to( $permalink );
    2929
    30         $this->assertEquals( 12, get_comments_number() );
     30        $this->assertSame( '12', get_comments_number() );
    3131    }
    3232
     
    4040        $comments_number_text = get_comments_number_text( false, false, false, $post_id );
    4141
    42         $this->assertEquals( sprintf( _n( '%s Comment', '%s Comments', 6 ), '6' ), $comments_number_text );
     42        $this->assertSame( sprintf( _n( '%s Comment', '%s Comments', 6 ), '6' ), $comments_number_text );
    4343
    4444        ob_start();
     
    4646        $comments_number_text = ob_get_clean();
    4747
    48         $this->assertEquals( sprintf( _n( '%s Comment', '%s Comments', 6 ), '6' ), $comments_number_text );
     48        $this->assertSame( sprintf( _n( '%s Comment', '%s Comments', 6 ), '6' ), $comments_number_text );
    4949
    5050    }
     
    5858        $this->go_to( $permalink );
    5959
    60         $this->assertEquals( __( 'No Comments' ), get_comments_number_text() );
     60        $this->assertSame( __( 'No Comments' ), get_comments_number_text() );
    6161
    6262        $this->factory->comment->create_post_comments( $post_id, 1 );
    6363        $this->go_to( $permalink );
    6464
    65         $this->assertEquals( __( '1 Comment' ), get_comments_number_text() );
     65        $this->assertSame( __( '1 Comment' ), get_comments_number_text() );
    6666
    6767        $this->factory->comment->create_post_comments( $post_id, 1 );
    6868        $this->go_to( $permalink );
    6969
    70         $this->assertEquals( sprintf( _n( '%s Comment', '%s Comments', 2 ), '2' ), get_comments_number_text() );
     70        $this->assertSame( sprintf( _n( '%s Comment', '%s Comments', 2 ), '2' ), get_comments_number_text() );
    7171
    7272    }
     
    8585        add_filter( 'gettext_with_context', array( $this, '_enable_comment_number_declension' ), 10, 4 );
    8686
    87         $this->assertEquals( $output, get_comments_number_text( false, false, $input ) );
     87        $this->assertSame( $output, get_comments_number_text( false, false, $input ) );
    8888
    8989        remove_filter( 'gettext_with_context', array( $this, '_enable_comment_number_declension' ), 10, 4 );
Note: See TracChangeset for help on using the changeset viewer.