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/option/transient.php

    r47122 r48937  
    2121        $this->assertFalse( get_transient( 'doesnotexist' ) );
    2222        $this->assertTrue( set_transient( $key, $value ) );
    23         $this->assertEquals( $value, get_transient( $key ) );
     23        $this->assertSame( $value, get_transient( $key ) );
    2424        $this->assertFalse( set_transient( $key, $value ) );
    2525        $this->assertTrue( set_transient( $key, $value2 ) );
    26         $this->assertEquals( $value2, get_transient( $key ) );
     26        $this->assertSame( $value2, get_transient( $key ) );
    2727        $this->assertTrue( delete_transient( $key ) );
    2828        $this->assertFalse( get_transient( $key ) );
     
    3838
    3939        $this->assertTrue( set_transient( $key, $value ) );
    40         $this->assertEquals( $value, get_transient( $key ) );
     40        $this->assertSame( $value, get_transient( $key ) );
    4141
    4242        $value = (object) $value;
     
    7575        $value2 = rand_str();
    7676        $this->assertTrue( set_transient( $key, $value ) );
    77         $this->assertEquals( $value, get_transient( $key ) );
     77        $this->assertSame( $value, get_transient( $key ) );
    7878
    7979        $this->assertFalse( get_option( '_transient_timeout_' . $key ) );
     
    9797        $key = 'test_transient';
    9898        set_transient( $key, 'test', 60 * 10 );
    99         $this->assertEquals( 'test', get_transient( $key ) );
     99        $this->assertSame( 'test', get_transient( $key ) );
    100100
    101101        // Useful variables for tracking.
     
    115115
    116116        // Make sure 'delete_option' was not called for both the transient and the timeout.
    117         $this->assertEquals( 0, $a->get_call_count() );
     117        $this->assertSame( 0, $a->get_call_count() );
    118118    }
    119119
     
    125125        $key = 'test_transient';
    126126        set_transient( $key, 'test', 60 * 10 );
    127         $this->assertEquals( 'test', get_transient( $key ) );
     127        $this->assertSame( 'test', get_transient( $key ) );
    128128
    129129        // Make sure the timeout option returns false.
     
    142142
    143143        // Make sure 'delete_option' was called for both the transient and the timeout.
    144         $this->assertEquals( 2, $a->get_call_count() );
     144        $this->assertSame( 2, $a->get_call_count() );
    145145
    146146        $expected = array(
     
    156156            ),
    157157        );
    158         $this->assertEquals( $expected, $a->get_events() );
     158        $this->assertSame( $expected, $a->get_events() );
    159159    }
    160160}
Note: See TracChangeset for help on using the changeset viewer.