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/post/nav-menu.php

    r48858 r48937  
    4141        );
    4242
    43         $this->assertEquals( 0, strpos( $menu, '<ul' ) );
     43        $this->assertSame( 0, strpos( $menu, '<ul' ) );
    4444    }
    4545
     
    157157        // Confirm it saved properly.
    158158        $custom_item = wp_setup_nav_menu_item( get_post( $custom_item_id ) );
    159         $this->assertEquals( 'Wordpress.org', $custom_item->title );
     159        $this->assertSame( 'Wordpress.org', $custom_item->title );
    160160
    161161        // Update the orphan with an associated nav menu.
     
    170170        $custom_item = wp_filter_object_list( $menu_items, array( 'db_id' => $custom_item_id ) );
    171171        $custom_item = array_pop( $custom_item );
    172         $this->assertEquals( 'WordPress.org', $custom_item->title );
     172        $this->assertSame( 'WordPress.org', $custom_item->title );
    173173
    174174    }
     
    219219        set_theme_mod( 'nav_menu_locations', $locations );
    220220
    221         $this->assertEquals( 'My Menu', wp_get_nav_menu_name( 'primary' ) );
     221        $this->assertSame( 'My Menu', wp_get_nav_menu_name( 'primary' ) );
    222222    }
    223223
     
    248248        $nav_menus_names = wp_list_pluck( wp_get_nav_menus(), 'name' );
    249249
    250         $this->assertEquals( $nav_menus_names, $expected_nav_menus_names );
     250        $this->assertSame( $nav_menus_names, $expected_nav_menus_names );
    251251    }
    252252
     
    280280        $post_type_archive_item    = wp_setup_nav_menu_item( get_post( $post_type_archive_item_id ) );
    281281
    282         $this->assertEquals( $post_type_slug, $post_type_archive_item->title );
    283         $this->assertEquals( $post_type_description, $post_type_archive_item->description );
     282        $this->assertSame( $post_type_slug, $post_type_archive_item->title );
     283        $this->assertSame( $post_type_description, $post_type_archive_item->description );
    284284    }
    285285
     
    311311        $post_type_archive_item    = wp_setup_nav_menu_item( get_post( $post_type_archive_item_id ) );
    312312
    313         $this->assertEquals( $post_type_slug, $post_type_archive_item->title );
    314         $this->assertEquals( $post_type_description, $post_type_archive_item->description ); // Fail!
     313        $this->assertSame( $post_type_slug, $post_type_archive_item->title );
     314        $this->assertSame( $post_type_description, $post_type_archive_item->description ); // Fail!
    315315    }
    316316
     
    346346        $post_type_archive_item    = wp_setup_nav_menu_item( get_post( $post_type_archive_item_id ) );
    347347
    348         $this->assertEquals( $post_type_slug, $post_type_archive_item->title );
    349         $this->assertEquals( $menu_item_description, $post_type_archive_item->description );
     348        $this->assertSame( $post_type_slug, $post_type_archive_item->title );
     349        $this->assertSame( $menu_item_description, $post_type_archive_item->description );
    350350    }
    351351
     
    724724            )
    725725        );
    726         $this->assertEquals( 'auto-draft', get_post_status( $auto_draft_post_id ) );
    727         $this->assertEquals( 'draft', get_post_status( $draft_post_id ) );
    728         $this->assertEquals( 'private', get_post_status( $private_post_id ) );
     726        $this->assertSame( 'auto-draft', get_post_status( $auto_draft_post_id ) );
     727        $this->assertSame( 'draft', get_post_status( $draft_post_id ) );
     728        $this->assertSame( 'private', get_post_status( $private_post_id ) );
    729729        wp_delete_post( $wp_customize->changeset_post_id(), true );
    730730        $this->assertFalse( get_post_status( $auto_draft_post_id ) );
    731         $this->assertEquals( 'trash', get_post_status( $draft_post_id ) );
    732         $this->assertEquals( 'private', get_post_status( $private_post_id ) );
     731        $this->assertSame( 'trash', get_post_status( $draft_post_id ) );
     732        $this->assertSame( 'private', get_post_status( $private_post_id ) );
    733733    }
    734734
     
    944944
    945945        $custom_item = wp_setup_nav_menu_item( get_post( $custom_item_id ) );
    946         $this->assertEquals( $correct_url, $custom_item->url );
     946        $this->assertSame( $correct_url, $custom_item->url );
    947947    }
    948948
Note: See TracChangeset for help on using the changeset viewer.