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

    r47122 r48937  
    4141        $post    = get_post( $post_id );
    4242
    43         $this->assertEquals( $this->slash_1, $post->post_title );
    44         $this->assertEquals( $this->slash_5, $post->post_content );
    45         $this->assertEquals( $this->slash_7, $post->post_excerpt );
     43        $this->assertSame( $this->slash_1, $post->post_title );
     44        $this->assertSame( $this->slash_5, $post->post_content );
     45        $this->assertSame( $this->slash_7, $post->post_excerpt );
    4646
    4747        $_POST               = array();
     
    5656        $post    = get_post( $post_id );
    5757
    58         $this->assertEquals( $this->slash_2, $post->post_title );
    59         $this->assertEquals( $this->slash_4, $post->post_content );
    60         $this->assertEquals( $this->slash_6, $post->post_excerpt );
     58        $this->assertSame( $this->slash_2, $post->post_title );
     59        $this->assertSame( $this->slash_4, $post->post_content );
     60        $this->assertSame( $this->slash_6, $post->post_excerpt );
    6161    }
    6262
     
    7777        $post = get_post( $id );
    7878
    79         $this->assertEquals( wp_unslash( $this->slash_1 ), $post->post_title );
    80         $this->assertEquals( wp_unslash( $this->slash_3 ), $post->post_content );
    81         $this->assertEquals( wp_unslash( $this->slash_5 ), $post->post_excerpt );
     79        $this->assertSame( wp_unslash( $this->slash_1 ), $post->post_title );
     80        $this->assertSame( wp_unslash( $this->slash_3 ), $post->post_content );
     81        $this->assertSame( wp_unslash( $this->slash_5 ), $post->post_excerpt );
    8282
    8383        $id   = wp_insert_post(
     
    9292        $post = get_post( $id );
    9393
    94         $this->assertEquals( wp_unslash( $this->slash_2 ), $post->post_title );
    95         $this->assertEquals( wp_unslash( $this->slash_4 ), $post->post_content );
    96         $this->assertEquals( wp_unslash( $this->slash_6 ), $post->post_excerpt );
     94        $this->assertSame( wp_unslash( $this->slash_2 ), $post->post_title );
     95        $this->assertSame( wp_unslash( $this->slash_4 ), $post->post_content );
     96        $this->assertSame( wp_unslash( $this->slash_6 ), $post->post_excerpt );
    9797    }
    9898
     
    113113        $post = get_post( $id );
    114114
    115         $this->assertEquals( wp_unslash( $this->slash_1 ), $post->post_title );
    116         $this->assertEquals( wp_unslash( $this->slash_3 ), $post->post_content );
    117         $this->assertEquals( wp_unslash( $this->slash_5 ), $post->post_excerpt );
     115        $this->assertSame( wp_unslash( $this->slash_1 ), $post->post_title );
     116        $this->assertSame( wp_unslash( $this->slash_3 ), $post->post_content );
     117        $this->assertSame( wp_unslash( $this->slash_5 ), $post->post_excerpt );
    118118
    119119        wp_update_post(
     
    127127        $post = get_post( $id );
    128128
    129         $this->assertEquals( wp_unslash( $this->slash_2 ), $post->post_title );
    130         $this->assertEquals( wp_unslash( $this->slash_4 ), $post->post_content );
    131         $this->assertEquals( wp_unslash( $this->slash_6 ), $post->post_excerpt );
     129        $this->assertSame( wp_unslash( $this->slash_2 ), $post->post_title );
     130        $this->assertSame( wp_unslash( $this->slash_4 ), $post->post_content );
     131        $this->assertSame( wp_unslash( $this->slash_6 ), $post->post_excerpt );
    132132    }
    133133
     
    148148        $post = get_post( $id );
    149149
    150         $this->assertEquals( $this->slash_1, $post->post_title );
    151         $this->assertEquals( $this->slash_3, $post->post_content );
    152         $this->assertEquals( $this->slash_5, $post->post_excerpt );
     150        $this->assertSame( $this->slash_1, $post->post_title );
     151        $this->assertSame( $this->slash_3, $post->post_content );
     152        $this->assertSame( $this->slash_5, $post->post_excerpt );
    153153
    154154        $untrashed = wp_untrash_post( $id );
     
    157157        $post = get_post( $id );
    158158
    159         $this->assertEquals( $this->slash_1, $post->post_title );
    160         $this->assertEquals( $this->slash_3, $post->post_content );
    161         $this->assertEquals( $this->slash_5, $post->post_excerpt );
     159        $this->assertSame( $this->slash_1, $post->post_title );
     160        $this->assertSame( $this->slash_3, $post->post_content );
     161        $this->assertSame( $this->slash_5, $post->post_excerpt );
    162162    }
    163163}
Note: See TracChangeset for help on using the changeset viewer.