Make WordPress Core


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

    r47122 r48937  
    2727        $output = $this->walker->walk( $items, 0 );
    2828
    29         $this->assertEquals( 1, $this->walker->get_number_of_root_elements( $items ) );
    30         $this->assertEquals( '<li>1</li>', $output );
     29        $this->assertSame( 1, $this->walker->get_number_of_root_elements( $items ) );
     30        $this->assertSame( '<li>1</li>', $output );
    3131
    3232    }
     
    4242        $output = $this->walker->walk( $items, -1 );
    4343
    44         $this->assertEquals( 1, $this->walker->get_number_of_root_elements( $items ) );
    45         $this->assertEquals( '<li>1</li>', $output );
     44        $this->assertSame( 1, $this->walker->get_number_of_root_elements( $items ) );
     45        $this->assertSame( '<li>1</li>', $output );
    4646
    4747    }
     
    5757        $output = $this->walker->walk( $items, 1 );
    5858
    59         $this->assertEquals( 1, $this->walker->get_number_of_root_elements( $items ) );
    60         $this->assertEquals( '<li>1</li>', $output );
     59        $this->assertSame( 1, $this->walker->get_number_of_root_elements( $items ) );
     60        $this->assertSame( '<li>1</li>', $output );
    6161
    6262    }
     
    7777        $output = $this->walker->walk( $items, 0 );
    7878
    79         $this->assertEquals( 2, $this->walker->get_number_of_root_elements( $items ) );
    80         $this->assertEquals( '<li>1</li><li>2</li>', $output );
     79        $this->assertSame( 2, $this->walker->get_number_of_root_elements( $items ) );
     80        $this->assertSame( '<li>1</li><li>2</li>', $output );
    8181
    8282    }
     
    9797        $output = $this->walker->walk( $items, 0 );
    9898
    99         $this->assertEquals( 1, $this->walker->get_number_of_root_elements( $items ) );
    100         $this->assertEquals( '<li>1<ul><li>2</li></ul></li>', $output );
     99        $this->assertSame( 1, $this->walker->get_number_of_root_elements( $items ) );
     100        $this->assertSame( '<li>1<ul><li>2</li></ul></li>', $output );
    101101
    102102    }
     
    117117        $output = $this->walker->walk( $items, -1 );
    118118
    119         $this->assertEquals( 1, $this->walker->get_number_of_root_elements( $items ) );
    120         $this->assertEquals( '<li>1</li><li>2</li>', $output );
     119        $this->assertSame( 1, $this->walker->get_number_of_root_elements( $items ) );
     120        $this->assertSame( '<li>1</li><li>2</li>', $output );
    121121
    122122    }
     
    137137        $output = $this->walker->walk( $items, 1 );
    138138
    139         $this->assertEquals( 1, $this->walker->get_number_of_root_elements( $items ) );
    140         $this->assertEquals( '<li>1</li>', $output );
     139        $this->assertSame( 1, $this->walker->get_number_of_root_elements( $items ) );
     140        $this->assertSame( '<li>1</li>', $output );
    141141
    142142    }
     
    161161        $output = $this->walker->walk( $items, 2 );
    162162
    163         $this->assertEquals( 1, $this->walker->get_number_of_root_elements( $items ) );
    164         $this->assertEquals( '<li>1<ul><li>2</li></ul></li>', $output );
     163        $this->assertSame( 1, $this->walker->get_number_of_root_elements( $items ) );
     164        $this->assertSame( '<li>1<ul><li>2</li></ul></li>', $output );
    165165
    166166    }
     
    181181        $output = $this->walker->walk( $items, 0 );
    182182
    183         $this->assertEquals( 0, $this->walker->get_number_of_root_elements( $items ) );
    184         $this->assertEquals( '<li>1<ul><li>2</li></ul></li>', $output );
     183        $this->assertSame( 0, $this->walker->get_number_of_root_elements( $items ) );
     184        $this->assertSame( '<li>1<ul><li>2</li></ul></li>', $output );
    185185
    186186    }
     
    197197        $output = $this->walker->walk( $items, 0 );
    198198
    199         $this->assertEquals( 0, $this->walker->get_number_of_root_elements( $items ) );
    200         $this->assertEquals( '<li>1</li>', $output );
     199        $this->assertSame( 0, $this->walker->get_number_of_root_elements( $items ) );
     200        $this->assertSame( '<li>1</li>', $output );
    201201
    202202    }
     
    213213        $output = $this->walker->walk( $items, 1 );
    214214
    215         $this->assertEquals( 0, $this->walker->get_number_of_root_elements( $items ) );
     215        $this->assertSame( 0, $this->walker->get_number_of_root_elements( $items ) );
    216216
    217217        // It's not clear what the output of this "should" be.
    218218
    219219        // Currently the item is simply returned.
    220         $this->assertEquals( '<li>1</li>', $output );
     220        $this->assertSame( '<li>1</li>', $output );
    221221
    222222        // But as we've only asked for the first depth maybe nothing should be returned?
    223         // $this->assertEquals( '', $output );
     223        // $this->assertSame( '', $output );
    224224
    225225    }
     
    244244        $output = $this->walker->walk( $items, 0 );
    245245
    246         $this->assertEquals( 0, $this->walker->get_number_of_root_elements( $items ) );
    247         $this->assertEquals( '<li>4</li><li>5</li><li>6</li>', $output );
     246        $this->assertSame( 0, $this->walker->get_number_of_root_elements( $items ) );
     247        $this->assertSame( '<li>4</li><li>5</li><li>6</li>', $output );
    248248
    249249    }
     
    268268        $output = $this->walker->walk( $items, 1 );
    269269
    270         $this->assertEquals( 0, $this->walker->get_number_of_root_elements( $items ) );
     270        $this->assertSame( 0, $this->walker->get_number_of_root_elements( $items ) );
    271271
    272272        // It's not clear what the output of this "should" be.
    273273
    274274        // Currently the first item is simply returned.
    275         $this->assertEquals( '<li>4</li>', $output );
     275        $this->assertSame( '<li>4</li>', $output );
    276276
    277277        // But as we've only asked for the first depth maybe nothing should be returned?
    278         // $this->assertEquals( '', $output );
     278        // $this->assertSame( '', $output );
    279279
    280280        // Or maybe all items which are missing parents should simply be treat top level?
    281         // $this->assertEquals( '<li>4</li><li>5</li><li>6</li>', $output );
     281        // $this->assertSame( '<li>4</li><li>5</li><li>6</li>', $output );
    282282
    283283    }
Note: See TracChangeset for help on using the changeset viewer.