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

    r48310 r48937  
    6161        set_post_thumbnail( self::$post, self::$attachment_id );
    6262
    63         $this->assertEquals( self::$attachment_id, get_post_thumbnail_id( self::$post ) );
    64         $this->assertEquals( self::$attachment_id, get_post_thumbnail_id( self::$post->ID ) );
    65 
    66         $GLOBALS['post'] = self::$post;
    67 
    68         $this->assertEquals( self::$attachment_id, get_post_thumbnail_id() );
     63        $this->assertSame( self::$attachment_id, get_post_thumbnail_id( self::$post ) );
     64        $this->assertSame( self::$attachment_id, get_post_thumbnail_id( self::$post->ID ) );
     65
     66        $GLOBALS['post'] = self::$post;
     67
     68        $this->assertSame( self::$attachment_id, get_post_thumbnail_id() );
    6969    }
    7070
     
    9191     */
    9292    function test_get_the_post_thumbnail_caption() {
    93         $this->assertEquals( '', get_the_post_thumbnail_caption() );
     93        $this->assertSame( '', get_the_post_thumbnail_caption() );
    9494
    9595        $caption = 'This is a caption.';
     
    108108        set_post_thumbnail( $post_id, $attachment_id );
    109109
    110         $this->assertEquals( $caption, get_the_post_thumbnail_caption( $post_id ) );
     110        $this->assertSame( $caption, get_the_post_thumbnail_caption( $post_id ) );
    111111    }
    112112
     
    128128        set_post_thumbnail( $post_id, $attachment_id );
    129129
    130         $this->assertEquals( '', get_the_post_thumbnail_caption( $post_id ) );
     130        $this->assertSame( '', get_the_post_thumbnail_caption( $post_id ) );
    131131    }
    132132
     
    155155
    156156    function test_get_the_post_thumbnail() {
    157         $this->assertEquals( '', get_the_post_thumbnail() );
    158         $this->assertEquals( '', get_the_post_thumbnail( self::$post ) );
     157        $this->assertSame( '', get_the_post_thumbnail() );
     158        $this->assertSame( '', get_the_post_thumbnail( self::$post ) );
    159159        set_post_thumbnail( self::$post, self::$attachment_id );
    160160
     
    168168        );
    169169
    170         $this->assertEquals( $expected, get_the_post_thumbnail( self::$post ) );
    171 
    172         $GLOBALS['post'] = self::$post;
    173 
    174         $this->assertEquals( $expected, get_the_post_thumbnail() );
     170        $this->assertSame( $expected, get_the_post_thumbnail( self::$post ) );
     171
     172        $GLOBALS['post'] = self::$post;
     173
     174        $this->assertSame( $expected, get_the_post_thumbnail() );
    175175    }
    176176
     
    211211
    212212        $this->assertFalse( get_the_post_thumbnail_url() );
    213         $this->assertEquals( wp_get_attachment_url( self::$attachment_id ), get_the_post_thumbnail_url( self::$post ) );
    214 
    215         $GLOBALS['post'] = self::$post;
    216 
    217         $this->assertEquals( wp_get_attachment_url( self::$attachment_id ), get_the_post_thumbnail_url() );
     213        $this->assertSame( wp_get_attachment_url( self::$attachment_id ), get_the_post_thumbnail_url( self::$post ) );
     214
     215        $GLOBALS['post'] = self::$post;
     216
     217        $this->assertSame( wp_get_attachment_url( self::$attachment_id ), get_the_post_thumbnail_url() );
    218218    }
    219219
     
    308308
    309309        $thumbnail_id = get_post_thumbnail_id( $post_id );
    310         $this->assertEquals( self::$attachment_id, $thumbnail_id );
     310        $this->assertSame( self::$attachment_id, $thumbnail_id );
    311311
    312312        $post_id = wp_insert_post(
     
    343343
    344344        $thumbnail_id = get_post_thumbnail_id( $post_id );
    345         $this->assertEquals( self::$attachment_id, $thumbnail_id );
     345        $this->assertSame( self::$attachment_id, $thumbnail_id );
    346346
    347347        // Images do not support featured images.
Note: See TracChangeset for help on using the changeset viewer.