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/xmlrpc/wp/getUser.php

    r47122 r48937  
    2828        $result = $this->myxmlrpcserver->wp_getUser( array( 1, 'username', 'password', 1 ) );
    2929        $this->assertIXRError( $result );
    30         $this->assertEquals( 403, $result->code );
     30        $this->assertSame( 403, $result->code );
    3131    }
    3232
     
    3434        $result = $this->myxmlrpcserver->wp_getUser( array( 1, 'administrator', 'administrator', 34902348908234 ) );
    3535        $this->assertIXRError( $result );
    36         $this->assertEquals( 404, $result->code );
     36        $this->assertSame( 404, $result->code );
    3737    }
    3838
     
    4343        $result = $this->myxmlrpcserver->wp_getUser( array( 1, 'subscriber', 'subscriber', $editor_id ) );
    4444        $this->assertIXRError( $result );
    45         $this->assertEquals( 401, $result->code );
     45        $this->assertSame( 401, $result->code );
    4646    }
    4747
     
    9393        // Check expected values.
    9494        $this->assertEquals( $user_id, $result['user_id'] );
    95         $this->assertEquals( $user_data['user_login'], $result['username'] );
    96         $this->assertEquals( $user_data['first_name'], $result['first_name'] );
    97         $this->assertEquals( $user_data['last_name'], $result['last_name'] );
    98         $this->assertEquals( $registered_date, $result['registered']->getTimestamp() );
    99         $this->assertEquals( $user_data['description'], $result['bio'] );
    100         $this->assertEquals( $user_data['user_email'], $result['email'] );
    101         $this->assertEquals( $user_data['nickname'], $result['nickname'] );
    102         $this->assertEquals( $user_data['user_nicename'], $result['nicename'] );
    103         $this->assertEquals( $user_data['user_url'], $result['url'] );
    104         $this->assertEquals( $user_data['display_name'], $result['display_name'] );
    105         $this->assertEquals( $user_data['user_login'], $result['username'] );
     95        $this->assertSame( $user_data['user_login'], $result['username'] );
     96        $this->assertSame( $user_data['first_name'], $result['first_name'] );
     97        $this->assertSame( $user_data['last_name'], $result['last_name'] );
     98        $this->assertSame( $registered_date, $result['registered']->getTimestamp() );
     99        $this->assertSame( $user_data['description'], $result['bio'] );
     100        $this->assertSame( $user_data['user_email'], $result['email'] );
     101        $this->assertSame( $user_data['nickname'], $result['nickname'] );
     102        $this->assertSame( $user_data['user_nicename'], $result['nicename'] );
     103        $this->assertSame( $user_data['user_url'], $result['url'] );
     104        $this->assertSame( $user_data['display_name'], $result['display_name'] );
     105        $this->assertSame( $user_data['user_login'], $result['username'] );
    106106        $this->assertContains( $user_data['role'], $result['roles'] );
    107107
     
    117117
    118118        $expected_fields = array( 'user_id' );
    119         $this->assertEquals( $expected_fields, array_keys( $result ) );
     119        $this->assertSame( $expected_fields, array_keys( $result ) );
    120120    }
    121121
Note: See TracChangeset for help on using the changeset viewer.