WordPress.org

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/functions/wpListFilter.php

    r47780 r48937  
    5050            'AND'
    5151        );
    52         $this->assertEquals( 2, count( $list ) );
     52        $this->assertSame( 2, count( $list ) );
    5353        $this->assertArrayHasKey( 'foo', $list );
    5454        $this->assertArrayHasKey( 'bar', $list );
     
    6464            'OR'
    6565        );
    66         $this->assertEquals( 3, count( $list ) );
     66        $this->assertSame( 3, count( $list ) );
    6767        $this->assertArrayHasKey( 'foo', $list );
    6868        $this->assertArrayHasKey( 'bar', $list );
     
    7979            'NOT'
    8080        );
    81         $this->assertEquals( 1, count( $list ) );
     81        $this->assertSame( 1, count( $list ) );
    8282        $this->assertArrayHasKey( 'baz', $list );
    8383    }
     
    9393            'name'
    9494        );
    95         $this->assertEquals(
     95        $this->assertSame(
    9696            array(
    9797                'foo' => 'foo',
     
    112112            'name'
    113113        );
    114         $this->assertEquals(
     114        $this->assertSame(
    115115            array(
    116116                'foo' => 'foo',
     
    131131            'name'
    132132        );
    133         $this->assertEquals( array( 'baz' => 'baz' ), $list );
     133        $this->assertSame( array( 'baz' => 'baz' ), $list );
    134134    }
    135135
    136136    function test_wp_list_pluck() {
    137137        $list = wp_list_pluck( $this->object_list, 'name' );
    138         $this->assertEquals(
     138        $this->assertSame(
    139139            array(
    140140                'foo' => 'foo',
     
    146146
    147147        $list = wp_list_pluck( $this->array_list, 'name' );
    148         $this->assertEquals(
     148        $this->assertSame(
    149149            array(
    150150                'foo' => 'foo',
     
    161161    function test_wp_list_pluck_index_key() {
    162162        $list = wp_list_pluck( $this->array_list, 'name', 'id' );
    163         $this->assertEquals(
     163        $this->assertSame(
    164164            array(
    165165                'f' => 'foo',
     
    176176    function test_wp_list_pluck_object_index_key() {
    177177        $list = wp_list_pluck( $this->object_list, 'name', 'id' );
    178         $this->assertEquals(
     178        $this->assertSame(
    179179            array(
    180180                'f' => 'foo',
     
    191191    function test_wp_list_pluck_missing_index_key() {
    192192        $list = wp_list_pluck( $this->array_list, 'name', 'nonexistent' );
    193         $this->assertEquals(
     193        $this->assertSame(
    194194            array(
    195195                0 => 'foo',
     
    208208        unset( $array_list['bar']['id'] );
    209209        $list = wp_list_pluck( $array_list, 'name', 'id' );
    210         $this->assertEquals(
     210        $this->assertSame(
    211211            array(
    212212                'f' => 'foo',
     
    225225        $mixed_list['bar'] = (object) $mixed_list['bar'];
    226226        $list              = wp_list_pluck( $mixed_list, 'name', 'id' );
    227         $this->assertEquals(
     227        $this->assertSame(
    228228            array(
    229229                'f' => 'foo',
     
    248248
    249249        $list = wp_list_pluck( $ref_list, 'name' );
    250         $this->assertEquals(
     250        $this->assertSame(
    251251            array(
    252252                'foo',
     
    273273
    274274        $list = wp_list_pluck( $ref_list, 'name', 'id' );
    275         $this->assertEquals(
     275        $this->assertSame(
    276276            array(
    277277                'f' => 'foo',
     
    287287    function test_filter_object_list_nested_array_and() {
    288288        $list = wp_filter_object_list( $this->object_list, array( 'field4' => array( 'blue' ) ), 'AND' );
    289         $this->assertEquals( 1, count( $list ) );
     289        $this->assertSame( 1, count( $list ) );
    290290        $this->assertArrayHasKey( 'baz', $list );
    291291    }
     
    293293    function test_filter_object_list_nested_array_not() {
    294294        $list = wp_filter_object_list( $this->object_list, array( 'field4' => array( 'red' ) ), 'NOT' );
    295         $this->assertEquals( 2, count( $list ) );
     295        $this->assertSame( 2, count( $list ) );
    296296        $this->assertArrayHasKey( 'bar', $list );
    297297        $this->assertArrayHasKey( 'baz', $list );
     
    307307            'OR'
    308308        );
    309         $this->assertEquals( 2, count( $list ) );
     309        $this->assertSame( 2, count( $list ) );
    310310        $this->assertArrayHasKey( 'foo', $list );
    311311        $this->assertArrayHasKey( 'baz', $list );
     
    314314    function test_filter_object_list_nested_array_or_singular() {
    315315        $list = wp_filter_object_list( $this->object_list, array( 'field4' => array( 'blue' ) ), 'OR' );
    316         $this->assertEquals( 1, count( $list ) );
     316        $this->assertSame( 1, count( $list ) );
    317317        $this->assertArrayHasKey( 'baz', $list );
    318318    }
     
    321321    function test_filter_object_list_nested_array_and_field() {
    322322        $list = wp_filter_object_list( $this->object_list, array( 'field4' => array( 'blue' ) ), 'AND', 'name' );
    323         $this->assertEquals( array( 'baz' => 'baz' ), $list );
     323        $this->assertSame( array( 'baz' => 'baz' ), $list );
    324324    }
    325325
    326326    function test_filter_object_list_nested_array_not_field() {
    327327        $list = wp_filter_object_list( $this->object_list, array( 'field4' => array( 'green' ) ), 'NOT', 'name' );
    328         $this->assertEquals(
     328        $this->assertSame(
    329329            array(
    330330                'foo' => 'foo',
     
    345345            'name'
    346346        );
    347         $this->assertEquals(
     347        $this->assertSame(
    348348            array(
    349349                'foo' => 'foo',
Note: See TracChangeset for help on using the changeset viewer.