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/http/functions.php

    r47122 r48937  
    2626        $this->assertInternalType( 'array', $response );
    2727
    28         $this->assertEquals( 'image/jpeg', $headers['content-type'] );
    29         $this->assertEquals( '40148', $headers['content-length'] );
    30         $this->assertEquals( '200', wp_remote_retrieve_response_code( $response ) );
     28        $this->assertSame( 'image/jpeg', $headers['content-type'] );
     29        $this->assertSame( '40148', $headers['content-length'] );
     30        $this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
    3131    }
    3232
     
    3737
    3838        $this->skipTestOnTimeout( $response );
    39         $this->assertEquals( '301', wp_remote_retrieve_response_code( $response ) );
     39        $this->assertSame( 301, wp_remote_retrieve_response_code( $response ) );
    4040    }
    4141
     
    4545
    4646        $this->skipTestOnTimeout( $response );
    47         $this->assertEquals( '404', wp_remote_retrieve_response_code( $response ) );
     47        $this->assertSame( 404, wp_remote_retrieve_response_code( $response ) );
    4848    }
    4949
     
    6060
    6161        // Should return the same headers as a HEAD request.
    62         $this->assertEquals( 'image/jpeg', $headers['content-type'] );
    63         $this->assertEquals( '40148', $headers['content-length'] );
    64         $this->assertEquals( '200', wp_remote_retrieve_response_code( $response ) );
     62        $this->assertSame( 'image/jpeg', $headers['content-type'] );
     63        $this->assertSame( '40148', $headers['content-length'] );
     64        $this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
    6565    }
    6666
     
    7676
    7777        // Should return the same headers as a HEAD request.
    78         $this->assertEquals( 'image/jpeg', $headers['content-type'] );
    79         $this->assertEquals( '40148', $headers['content-length'] );
    80         $this->assertEquals( '200', wp_remote_retrieve_response_code( $response ) );
     78        $this->assertSame( 'image/jpeg', $headers['content-type'] );
     79        $this->assertSame( '40148', $headers['content-length'] );
     80        $this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
    8181    }
    8282
     
    197197        // Check the host_only flag in the resulting WP_Http_Cookie.
    198198        $cookie = wp_remote_retrieve_cookie( $response, 'test' );
    199         $this->assertEquals( $cookie->domain, 'wordpress.org' );
     199        $this->assertSame( $cookie->domain, 'wordpress.org' );
    200200        $this->assertFalse( $cookie->host_only, 'host-only flag not set' );
    201201
Note: See TracChangeset for help on using the changeset viewer.