WordPress.org

Make WordPress Core


Ignore:
Timestamp:
02/10/2021 01:24:24 PM (10 months ago)
Author:
SergeyBiryukov
Message:

Tests: Use assertSame() in some newly introduced 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.

Follow-up to [49904], [49925], [49992], [50012], [50013], [50065], [50075], [50131], [50150], [50157].

See #38266, #52482.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/https-detection.php

    r50075 r50284  
    6666        add_filter( 'pre_http_request', array( $this, 'mock_success_with_sslverify' ), 10, 2 );
    6767        wp_update_https_detection_errors();
    68         $this->assertEquals( array(), get_option( 'https_detection_errors' ) );
     68        $this->assertSame( array(), get_option( 'https_detection_errors' ) );
    6969
    7070        // If initial request fails and request without SSL verification succeeds,
     
    7373        add_filter( 'pre_http_request', array( $this, 'mock_success_without_sslverify' ), 10, 2 );
    7474        wp_update_https_detection_errors();
    75         $this->assertEquals(
     75        $this->assertSame(
    7676            array( 'ssl_verification_failed' => array( 'Bad SSL certificate.' ) ),
    7777            get_option( 'https_detection_errors' )
     
    8383        add_filter( 'pre_http_request', array( $this, 'mock_error_without_sslverify' ), 10, 2 );
    8484        wp_update_https_detection_errors();
    85         $this->assertEquals(
     85        $this->assertSame(
    8686            array( 'bad_ssl_certificate' => array( 'Bad SSL certificate.' ) ),
    8787            get_option( 'https_detection_errors' )
     
    9292        add_filter( 'pre_http_request', array( $this, 'mock_not_found' ), 10, 2 );
    9393        wp_update_https_detection_errors();
    94         $this->assertEquals(
     94        $this->assertSame(
    9595            array( 'bad_response_code' => array( 'Not Found' ) ),
    9696            get_option( 'https_detection_errors' )
     
    101101        add_filter( 'pre_http_request', array( $this, 'mock_bad_source' ), 10, 2 );
    102102        wp_update_https_detection_errors();
    103         $this->assertEquals(
     103        $this->assertSame(
    104104            array( 'bad_response_source' => array( 'It looks like the response did not come from this site.' ) ),
    105105            get_option( 'https_detection_errors' )
     
    107107
    108108        // Check that the requests are made to the correct URL.
    109         $this->assertEquals( 'https://example.com/', $this->last_request_url );
     109        $this->assertSame( 'https://example.com/', $this->last_request_url );
    110110    }
    111111
     
    122122        );
    123123        wp_update_https_detection_errors();
    124         $this->assertEquals( array(), get_option( 'https_detection_errors' ) );
     124        $this->assertSame( array(), get_option( 'https_detection_errors' ) );
    125125
    126126        // Override to enforce an error being detected.
     
    135135        );
    136136        wp_update_https_detection_errors();
    137         $this->assertEquals(
     137        $this->assertSame(
    138138            array( 'ssl_verification_failed' => array( 'Bad SSL certificate.' ) ),
    139139            get_option( 'https_detection_errors' )
     
    146146    public function test_wp_schedule_https_detection() {
    147147        wp_schedule_https_detection();
    148         $this->assertEquals( 'twicedaily', wp_get_schedule( 'wp_https_detection' ) );
     148        $this->assertSame( 'twicedaily', wp_get_schedule( 'wp_https_detection' ) );
    149149    }
    150150
     
    158158            'args' => array( 'sslverify' => true ),
    159159        );
    160         $this->assertEquals( $request, wp_cron_conditionally_prevent_sslverify( $request ) );
     160        $this->assertSame( $request, wp_cron_conditionally_prevent_sslverify( $request ) );
    161161
    162162        // If URL is using HTTPS, set 'sslverify' to false.
     
    167167        $expected                      = $request;
    168168        $expected['args']['sslverify'] = false;
    169         $this->assertEquals( $expected, wp_cron_conditionally_prevent_sslverify( $request ) );
     169        $this->assertSame( $expected, wp_cron_conditionally_prevent_sslverify( $request ) );
    170170    }
    171171
Note: See TracChangeset for help on using the changeset viewer.