Make WordPress Core


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

    r46586 r48937  
    3333        $after  = $wpdb->num_queries;
    3434
    35         $this->assertEquals( $before, $after );
    36         $this->assertEquals( $value, 'value' );
     35        $this->assertSame( $before, $after );
     36        $this->assertSame( $value, 'value' );
    3737    }
    3838
     
    5353        $after  = $wpdb->num_queries;
    5454
    55         $this->assertEquals( $before, $after );
    56         $this->assertEquals( $value, 'value' );
     55        $this->assertSame( $before, $after );
     56        $this->assertSame( $value, 'value' );
    5757    }
    5858
     
    7474
    7575        // Database has been hit.
    76         $this->assertEquals( $before + 1, $after );
    77         $this->assertEquals( $value, 'value' );
     76        $this->assertSame( $before + 1, $after );
     77        $this->assertSame( $value, 'value' );
    7878    }
    7979
     
    9595
    9696        // Database has been hit.
    97         $this->assertEquals( $before + 1, $after );
    98         $this->assertEquals( $value, 'value' );
     97        $this->assertSame( $before + 1, $after );
     98        $this->assertSame( $value, 'value' );
    9999    }
    100100
     
    116116        $value  = get_option( 'foo' );
    117117
    118         $this->assertEquals( $before, $wpdb->num_queries );
    119         $this->assertEquals( $value, 'bar2' );
     118        $this->assertSame( $before, $wpdb->num_queries );
     119        $this->assertSame( $value, 'bar2' );
    120120    }
    121121
     
    138138
    139139        // 'foo' should still be autoload=yes, so we should see no additional querios.
    140         $this->assertEquals( $before, $wpdb->num_queries );
    141         $this->assertEquals( $value, 'bar' );
     140        $this->assertSame( $before, $wpdb->num_queries );
     141        $this->assertSame( $value, 'bar' );
    142142    }
    143143
     
    162162
    163163        // 'foo' should still be autoload=yes, so we should see no additional querios.
    164         $this->assertEquals( $before, $wpdb->num_queries );
    165         $this->assertEquals( $value, 'bar2' );
     164        $this->assertSame( $before, $wpdb->num_queries );
     165        $this->assertSame( $value, 'bar2' );
    166166    }
    167167
     
    188188
    189189        // Check that no new database queries were performed.
    190         $this->assertEquals( $num_queries_pre_update, get_num_queries() );
     190        $this->assertSame( $num_queries_pre_update, get_num_queries() );
    191191    }
    192192
Note: See TracChangeset for help on using the changeset viewer.