Make WordPress Core


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

    r47780 r48937  
    3232        function test_wp_get_archives_default() {
    3333                $expected['default'] = "<li><a href='" . $this->month_url . "'>" . gmdate( 'F Y' ) . '</a></li>';
    34                 $this->assertEquals( $expected['default'], trim( wp_get_archives( array( 'echo' => false ) ) ) );
     34                $this->assertSame( $expected['default'], trim( wp_get_archives( array( 'echo' => false ) ) ) );
    3535        }
    3636
    3737        function test_wp_get_archives_type() {
    3838                $expected['type'] = "<li><a href='" . $this->year_url . "'>" . gmdate( 'Y' ) . '</a></li>';
    39                 $this->assertEquals(
     39                $this->assertSame(
    4040                        $expected['type'],
    4141                        trim(
     
    7272        <li><a href='$link5'>$title5</a></li>
    7373EOF;
    74                 $this->assertEqualsIgnoreEOL(
     74                $this->assertSameIgnoreEOL(
    7575                        $expected['limit'],
    7676                        trim(
     
    8888        function test_wp_get_archives_format() {
    8989                $expected['format'] = "<option value='" . $this->month_url . "'> " . gmdate( 'F Y' ) . ' </option>';
    90                 $this->assertEquals(
     90                $this->assertSame(
    9191                        $expected['format'],
    9292                        trim(
     
    103103        function test_wp_get_archives_before_and_after() {
    104104                $expected['before_and_after'] = "<div><a href='" . $this->month_url . "'>" . gmdate( 'F Y' ) . '</a></div>';
    105                 $this->assertEquals(
     105                $this->assertSame(
    106106                        $expected['before_and_after'],
    107107                        trim(
     
    120120        function test_wp_get_archives_show_post_count() {
    121121                $expected['show_post_count'] = "<li><a href='" . $this->month_url . "'>" . gmdate( 'F Y' ) . '</a>&nbsp;(8)</li>';
    122                 $this->assertEquals(
     122                $this->assertSame(
    123123                        $expected['show_post_count'],
    124124                        trim(
     
    154154        <li><a href='{$this->month_url}'>$date_full</a></li>
    155155EOF;
    156                 $this->assertEqualsIgnoreEOL(
     156                $this->assertSameIgnoreEOL(
    157157                        $expected['order_asc'],
    158158                        trim(
     
    170170        <li><a href='{$oct_url}'>October 2012</a></li>
    171171EOF;
    172                 $this->assertEqualsIgnoreEOL(
     172                $this->assertSameIgnoreEOL(
    173173                        $expected['order_desc'],
    174174                        trim(
     
    205205                        )
    206206                );
    207                 $this->assertEquals( $expected, trim( $archives ) );
     207                $this->assertSame( $expected, trim( $archives ) );
    208208        }
    209209}
Note: See TracChangeset for help on using the changeset viewer.