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/cron.php

    r47122 r48937  
    4444        $scheduled = wp_schedule_single_event( $timestamp, $hook );
    4545        $this->assertTrue( $scheduled );
    46         $this->assertEquals( $timestamp, wp_next_scheduled( $hook ) );
     46        $this->assertSame( $timestamp, wp_next_scheduled( $hook ) );
    4747
    4848        // It's a non-recurring event.
    49         $this->assertEquals( '', wp_get_schedule( $hook ) );
     49        $this->assertFalse( wp_get_schedule( $hook ) );
    5050
    5151    }
     
    6060        $this->assertTrue( $scheduled );
    6161        // This returns the timestamp only if we provide matching args.
    62         $this->assertEquals( $timestamp, wp_next_scheduled( $hook, $args ) );
     62        $this->assertSame( $timestamp, wp_next_scheduled( $hook, $args ) );
    6363        // These don't match so return nothing.
    64         $this->assertEquals( false, wp_next_scheduled( $hook ) );
    65         $this->assertEquals( false, wp_next_scheduled( $hook, array( 'bar' ) ) );
     64        $this->assertFalse( wp_next_scheduled( $hook ) );
     65        $this->assertFalse( wp_next_scheduled( $hook, array( 'bar' ) ) );
    6666
    6767        // It's a non-recurring event.
    68         $this->assertEquals( '', wp_get_schedule( $hook, $args ) );
     68        $this->assertFalse( wp_get_schedule( $hook, $args ) );
    6969    }
    7070
     
    7878        $this->assertTrue( $scheduled );
    7979        // It's scheduled for the right time.
    80         $this->assertEquals( $timestamp, wp_next_scheduled( $hook ) );
     80        $this->assertSame( $timestamp, wp_next_scheduled( $hook ) );
    8181        // It's a recurring event.
    82         $this->assertEquals( $recur, wp_get_schedule( $hook ) );
     82        $this->assertSame( $recur, wp_get_schedule( $hook ) );
    8383    }
    8484
     
    9393        $this->assertTrue( $scheduled );
    9494        // This returns the timestamp only if we provide matching args.
    95         $this->assertEquals( $timestamp, wp_next_scheduled( $hook, $args ) );
     95        $this->assertSame( $timestamp, wp_next_scheduled( $hook, $args ) );
    9696        // These don't match so return nothing.
    97         $this->assertEquals( false, wp_next_scheduled( $hook ) );
    98         $this->assertEquals( false, wp_next_scheduled( $hook, array( 'bar' ) ) );
    99 
    100         $this->assertEquals( $recur, wp_get_schedule( $hook, $args ) );
     97        $this->assertFalse( wp_next_scheduled( $hook ) );
     98        $this->assertFalse( wp_next_scheduled( $hook, array( 'bar' ) ) );
     99
     100        $this->assertSame( $recur, wp_get_schedule( $hook, $args ) );
    101101
    102102    }
     
    108108
    109109        wp_schedule_single_event( $timestamp, $hook );
    110         $this->assertEquals( $timestamp, wp_next_scheduled( $hook ) );
     110        $this->assertSame( $timestamp, wp_next_scheduled( $hook ) );
    111111
    112112        // Now unschedule it and make sure it's gone.
    113113        $unscheduled = wp_unschedule_event( $timestamp, $hook );
    114114        $this->assertTrue( $unscheduled );
    115         $this->assertEquals( false, wp_next_scheduled( $hook ) );
     115        $this->assertFalse( wp_next_scheduled( $hook ) );
    116116    }
    117117
     
    276276
    277277        // The next event should be at +5 minutes, not +3.
    278         $this->assertEquals( $ts1, wp_next_scheduled( $hook, $args ) );
     278        $this->assertSame( $ts1, wp_next_scheduled( $hook, $args ) );
    279279    }
    280280
     
    295295
    296296        // The next event should be at +3 minutes, even though that one was scheduled second.
    297         $this->assertEquals( $ts2, wp_next_scheduled( $hook, $args ) );
     297        $this->assertSame( $ts2, wp_next_scheduled( $hook, $args ) );
    298298        wp_unschedule_event( $ts2, $hook, $args );
    299299        // Following event at +30 minutes should be there too.
    300         $this->assertEquals( $ts1, wp_next_scheduled( $hook, $args ) );
     300        $this->assertSame( $ts1, wp_next_scheduled( $hook, $args ) );
    301301    }
    302302
     
    314314
    315315        // The next event should be at +3 minutes.
    316         $this->assertEquals( $ts1, wp_next_scheduled( $hook, $args ) );
     316        $this->assertSame( $ts1, wp_next_scheduled( $hook, $args ) );
    317317        wp_unschedule_event( $ts1, $hook, $args );
    318318        // Following event should be there too.
    319         $this->assertEquals( $ts2, wp_next_scheduled( $hook, $args ) );
     319        $this->assertSame( $ts2, wp_next_scheduled( $hook, $args ) );
    320320    }
    321321
     
    471471
    472472        $this->assertEquals( $expected, $actual );
    473         $this->assertEquals( $expected->timestamp, $actual2 );
     473        $this->assertSame( $expected->timestamp, $actual2 );
    474474    }
    475475
Note: See TracChangeset for help on using the changeset viewer.