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

    r46586 r48937  
    7878        );
    7979        wp_trash_post( $trashed_about_page_id );
    80         $this->assertEquals( 'about__trashed', get_post( $trashed_about_page_id )->post_name );
     80        $this->assertSame( 'about__trashed', get_post( $trashed_about_page_id )->post_name );
    8181    }
    8282
     
    9494        );
    9595        wp_trash_post( $trashed_about_page_id );
    96         $this->assertEquals( 'foo__trashed__foo__trashed', get_post( $trashed_about_page_id )->post_name );
     96        $this->assertSame( 'foo__trashed__foo__trashed', get_post( $trashed_about_page_id )->post_name );
    9797    }
    9898
     
    111111
    112112        wp_untrash_post( $about_page_id );
    113         $this->assertEquals( 'about', get_post( $about_page_id )->post_name );
     113        $this->assertSame( 'about', get_post( $about_page_id )->post_name );
    114114    }
    115115
     
    134134        );
    135135
    136         $this->assertEquals( 'about__trashed', get_post( $trashed_about_page_id )->post_name );
    137         $this->assertEquals( 'about', get_post( $about_page_id )->post_name );
     136        $this->assertSame( 'about__trashed', get_post( $trashed_about_page_id )->post_name );
     137        $this->assertSame( 'about', get_post( $about_page_id )->post_name );
    138138    }
    139139
     
    161161        wp_untrash_post( $about_page_id );
    162162
    163         $this->assertEquals( 'about', get_post( $another_about_page_id )->post_name );
    164         $this->assertEquals( 'about-2', get_post( $about_page_id )->post_name );
     163        $this->assertSame( 'about', get_post( $another_about_page_id )->post_name );
     164        $this->assertSame( 'about-2', get_post( $about_page_id )->post_name );
    165165    }
    166166
     
    317317        );
    318318
    319         $this->assertEquals( 'publish', get_post_status( $post_id ) );
     319        $this->assertSame( 'publish', get_post_status( $post_id ) );
    320320
    321321        $post_id = $this->factory()->post->create(
     
    326326        );
    327327
    328         $this->assertEquals( 'future', get_post_status( $post_id ) );
     328        $this->assertSame( 'future', get_post_status( $post_id ) );
    329329    }
    330330}
Note: See TracChangeset for help on using the changeset viewer.