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

    r47198 r48937  
    4444        $nodes = $admin_bar->get_nodes();
    4545        $this->assertFalse( $nodes['new-content']->parent );
    46         $this->assertEquals( 'new-content', $nodes['add-new-content']->parent );
     46        $this->assertSame( 'new-content', $nodes['add-new-content']->parent );
    4747
    4848        _unregister_post_type( 'content' );
     
    6565
    6666        $node1 = $admin_bar->get_node( 'test-node' );
    67         $this->assertEquals( array( 'class' => 'test-class' ), $node1->meta );
     67        $this->assertSame( array( 'class' => 'test-class' ), $node1->meta );
    6868
    6969        $admin_bar->add_node(
     
    7575
    7676        $node2 = $admin_bar->get_node( 'test-node' );
    77         $this->assertEquals(
     77        $this->assertSame(
    7878            array(
    7979                'class'     => 'test-class',
     
    101101
    102102        // Site menu points to the home page instead of the admin URL.
    103         $this->assertEquals( home_url( '/' ), $node_site_name->href );
     103        $this->assertSame( home_url( '/' ), $node_site_name->href );
    104104
    105105        // No profile links as the user doesn't have any permissions on the site.
     
    126126
    127127        // Site menu points to the admin URL.
    128         $this->assertEquals( admin_url( '/' ), $node_site_name->href );
     128        $this->assertSame( admin_url( '/' ), $node_site_name->href );
    129129
    130130        $profile_url = admin_url( 'profile.php' );
    131131
    132132        // Profile URLs point to profile.php.
    133         $this->assertEquals( $profile_url, $node_my_account->href );
    134         $this->assertEquals( $profile_url, $node_user_info->href );
    135         $this->assertEquals( $profile_url, $node_edit_profile->href );
     133        $this->assertSame( $profile_url, $node_my_account->href );
     134        $this->assertSame( $profile_url, $node_user_info->href );
     135        $this->assertSame( $profile_url, $node_edit_profile->href );
    136136    }
    137137
     
    178178
    179179        // Profile URLs should go to the user's primary blog.
    180         $this->assertEquals( $primary_profile_url, $node_my_account->href );
    181         $this->assertEquals( $primary_profile_url, $node_user_info->href );
    182         $this->assertEquals( $primary_profile_url, $node_edit_profile->href );
     180        $this->assertSame( $primary_profile_url, $node_my_account->href );
     181        $this->assertSame( $primary_profile_url, $node_user_info->href );
     182        $this->assertSame( $primary_profile_url, $node_edit_profile->href );
    183183
    184184        restore_current_blog();
     
    233233
    234234        // Profile URLs should go to the user's primary blog.
    235         $this->assertEquals( $user_profile_url, $node_my_account->href );
    236         $this->assertEquals( $user_profile_url, $node_user_info->href );
    237         $this->assertEquals( $user_profile_url, $node_edit_profile->href );
     235        $this->assertSame( $user_profile_url, $node_my_account->href );
     236        $this->assertSame( $user_profile_url, $node_user_info->href );
     237        $this->assertSame( $user_profile_url, $node_edit_profile->href );
    238238
    239239        restore_current_blog();
     
    464464
    465465        $this->assertNotNull( $wp_logo_node );
    466         $this->assertSame( false, $wp_logo_node->href );
     466        $this->assertFalse( $wp_logo_node->href );
    467467        $this->assertArrayHasKey( 'tabindex', $wp_logo_node->meta );
    468468        $this->assertSame( 0, $wp_logo_node->meta['tabindex'] );
     
    688688        $query_params = array();
    689689        wp_parse_str( $parsed_url['query'], $query_params );
    690         $this->assertEquals( $uuid, $query_params['changeset_uuid'] );
     690        $this->assertSame( $uuid, $query_params['changeset_uuid'] );
    691691        $this->assertNotContains( 'changeset_uuid', $query_params['url'] );
    692692    }
Note: See TracChangeset for help on using the changeset viewer.