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/meta/registerMeta.php

    r48502 r48937  
    4646
    4747        // The filter should have been added with a priority of 10.
    48         $this->assertEquals( 10, $has_filter );
     48        $this->assertSame( 10, $has_filter );
    4949    }
    5050
     
    5454        remove_filter( 'sanitize_post_meta_flight_number', array( $this, '_old_sanitize_meta_cb' ) );
    5555
    56         $this->assertEquals( 10, $has_filter );
     56        $this->assertSame( 10, $has_filter );
    5757    }
    5858
     
    6565        remove_filter( 'sanitize_post_meta_flight_number', array( $this, '_old_sanitize_meta_cb' ) );
    6666
    67         $this->assertEquals(
     67        $this->assertSame(
    6868            array(
    6969                'auth'     => 10,
     
    103103        );
    104104
    105         $this->assertEquals( $expected, $actual );
     105        $this->assertSame( $expected, $actual );
    106106    }
    107107
     
    127127        );
    128128
    129         $this->assertEquals( $expected, $actual );
     129        $this->assertSame( $expected, $actual );
    130130    }
    131131
     
    138138        remove_filter( 'auth_post_meta_flight_number', '__return_true' );
    139139
    140         $this->assertEquals( array(), $actual );
     140        $this->assertSame( array(), $actual );
    141141    }
    142142
     
    157157        remove_filter( 'auth_post_meta_flight_number', '__return_true' );
    158158
    159         $this->assertEquals( 'old_sanitized_key old sanitized', $meta );
     159        $this->assertSame( 'old_sanitized_key old sanitized', $meta );
    160160    }
    161161
     
    180180            ),
    181181        );
    182         $this->assertEquals( $actual, $expected );
     182        $this->assertSame( $actual, $expected );
    183183    }
    184184
     
    196196        unregister_meta_key( 'post', 'new_sanitized_key' );
    197197
    198         $this->assertEquals( 'new_sanitized_key new sanitized', $meta );
     198        $this->assertSame( 'new_sanitized_key new sanitized', $meta );
    199199    }
    200200
     
    222222        unregister_meta_key( 'post', 'registered_key' );
    223223
    224         $this->assertEquals( array(), $wp_meta_keys );
     224        $this->assertSame( array(), $wp_meta_keys );
    225225    }
    226226
     
    261261        unregister_meta_key( 'post', 'registered_key1' );
    262262
    263         $this->assertEquals( 'I\'m just a field, take a good look at me', $meta_keys['registered_key1']['description'] );
     263        $this->assertSame( 'I\'m just a field, take a good look at me', $meta_keys['registered_key1']['description'] );
    264264    }
    265265
     
    282282        unregister_meta_key( 'post', 'flight_number' );
    283283
    284         $this->assertEquals( 'Oceanic 815', $meta['flight_number'][0] );
     284        $this->assertSame( 'Oceanic 815', $meta['flight_number'][0] );
    285285    }
    286286
     
    293293        unregister_meta_key( 'post', 'flight_number' );
    294294
    295         $this->assertEquals( 'Oceanic 815', $meta[0] );
     295        $this->assertSame( 'Oceanic 815', $meta[0] );
    296296    }
    297297
     
    304304        unregister_meta_key( 'post', 'flight_number' );
    305305
    306         $this->assertEquals( 'Oceanic 815', $meta );
     306        $this->assertSame( 'Oceanic 815', $meta );
    307307    }
    308308
     
    353353        $wp_meta_keys = array();
    354354
    355         $this->assertEquals( $expected, $actual );
     355        $this->assertSame( $expected, $actual );
    356356    }
    357357
     
    406406        $wp_meta_keys = array();
    407407
    408         $this->assertEquals( $expected, $actual );
     408        $this->assertSame( $expected, $actual );
    409409    }
    410410
Note: See TracChangeset for help on using the changeset viewer.