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/xmlrpc/mw/getRecentPosts.php

    r47122 r48937  
    2626        $result = $this->myxmlrpcserver->mw_getRecentPosts( array( 1, 'username', 'password' ) );
    2727        $this->assertIXRError( $result );
    28         $this->assertEquals( 403, $result->code );
     28        $this->assertSame( 403, $result->code );
    2929    }
    3030
     
    3737        $result = $this->myxmlrpcserver->mw_getRecentPosts( array( 1, 'subscriber', 'subscriber' ) );
    3838        $this->assertIXRError( $result );
    39         $this->assertEquals( 401, $result->code );
     39        $this->assertSame( 401, $result->code );
    4040    }
    4141
     
    4545        $result = $this->myxmlrpcserver->mw_getRecentPosts( array( 1, 'author', 'author' ) );
    4646        $this->assertNotIXRError( $result );
    47         $this->assertEquals( 0, count( $result ) );
     47        $this->assertSame( 0, count( $result ) );
    4848    }
    4949
     
    8383            $this->assertStringMatchesFormat( '%d', $result['userid'] );
    8484            $this->assertStringMatchesFormat( '%d', $result['postid'] );
    85             $this->assertEquals( $post->post_title, $result['title'] );
    86             $this->assertEquals( 'draft', $result['post_status'] );
     85            $this->assertSame( $post->post_title, $result['title'] );
     86            $this->assertSame( 'draft', $result['post_status'] );
    8787            $this->assertStringMatchesFormat( '%d', $result['wp_author_id'] );
    88             $this->assertEquals( $post->post_excerpt, $result['mt_excerpt'] );
    89             $this->assertEquals( url_to_postid( $result['link'] ), $post->ID );
     88            $this->assertSame( $post->post_excerpt, $result['mt_excerpt'] );
     89            $this->assertSame( url_to_postid( $result['link'] ), $post->ID );
    9090
    91             $this->assertEquals( '', $result['wp_post_thumbnail'] );
     91            $this->assertSame( '', $result['wp_post_thumbnail'] );
    9292        }
    9393
     
    113113                $attachment_id = get_post_meta( $result['postid'], '_thumbnail_id', true );
    114114
    115                 $this->assertEquals( $attachment_id, $result['wp_post_thumbnail'] );
     115                $this->assertSame( $attachment_id, $result['wp_post_thumbnail'] );
    116116            }
    117117        }
     
    136136            $this->assertInstanceOf( 'IXR_Date', $result['date_modified_gmt'] );
    137137
    138             $this->assertEquals( strtotime( $post->post_date ), $result['dateCreated']->getTimestamp() );
    139             $this->assertEquals( $date_gmt, $result['date_created_gmt']->getTimestamp() );
    140             $this->assertEquals( strtotime( $post->post_date ), $result['date_modified']->getTimestamp() );
    141             $this->assertEquals( $date_modified_gmt, $result['date_modified_gmt']->getTimestamp() );
     138            $this->assertSame( strtotime( $post->post_date ), $result['dateCreated']->getTimestamp() );
     139            $this->assertSame( $date_gmt, $result['date_created_gmt']->getTimestamp() );
     140            $this->assertSame( strtotime( $post->post_date ), $result['date_modified']->getTimestamp() );
     141            $this->assertSame( $date_modified_gmt, $result['date_modified_gmt']->getTimestamp() );
    142142        }
    143143    }
Note: See TracChangeset for help on using the changeset viewer.