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

    r48113 r48937  
    166166        $this->assertSame( 0, $GLOBALS['multipage'] );
    167167        $this->assertSame( 1, $GLOBALS['numpages'] );
    168         $this->assertEquals( array( 'Page 0' ), $GLOBALS['pages'] );
     168        $this->assertSame( array( 'Page 0' ), $GLOBALS['pages'] );
    169169    }
    170170
     
    179179        $this->assertSame( 1, $GLOBALS['multipage'] );
    180180        $this->assertSame( 4, $GLOBALS['numpages'] );
    181         $this->assertEquals( array( 'Page 0', 'Page 1', 'Page 2', 'Page 3' ), $GLOBALS['pages'] );
     181        $this->assertSame( array( 'Page 0', 'Page 1', 'Page 2', 'Page 3' ), $GLOBALS['pages'] );
    182182    }
    183183
     
    195195        $this->assertSame( 1, $GLOBALS['multipage'] );
    196196        $this->assertSame( 3, $GLOBALS['numpages'] );
    197         $this->assertEquals( array( 'Page 1', 'Page 2', 'Page 3' ), $GLOBALS['pages'] );
     197        $this->assertSame( array( 'Page 1', 'Page 2', 'Page 3' ), $GLOBALS['pages'] );
    198198    }
    199199
     
    206206        setup_postdata( $post );
    207207
    208         $this->assertEquals( array( 'Page 0', "Page 1\nhas a line break", 'Page 2', "\nPage 3" ), $GLOBALS['pages'] );
     208        $this->assertSame( array( 'Page 0', "Page 1\nhas a line break", 'Page 2', "\nPage 3" ), $GLOBALS['pages'] );
    209209    }
    210210
     
    412412        setup_postdata( $a_post );
    413413        $content = get_echo( 'the_content' );
    414         $this->assertEquals( $post_id, $GLOBALS['post']->ID );
     414        $this->assertSame( $post_id, $GLOBALS['post']->ID );
    415415        $this->assertNotEquals( '<p>global post</p>', strip_ws( $content ) );
    416416        wp_reset_postdata();
     
    428428        setup_postdata( $post );
    429429
    430         $this->assertEquals( $GLOBALS['pages'], $this->pages_global );
     430        $this->assertSame( $GLOBALS['pages'], $this->pages_global );
    431431    }
    432432
Note: See TracChangeset for help on using the changeset viewer.