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/ajax/DimComment.php

    r48220 r48937  
    8383
    8484        // Ensure everything is correct.
    85         $this->assertEquals( $comment->comment_ID, (string) $xml->response[0]->comment['id'] );
    86         $this->assertEquals( 'dim-comment_' . $comment->comment_ID, (string) $xml->response['action'] );
     85        $this->assertSame( $comment->comment_ID, (string) $xml->response[0]->comment['id'] );
     86        $this->assertSame( 'dim-comment_' . $comment->comment_ID, (string) $xml->response['action'] );
    8787        $this->assertGreaterThanOrEqual( time() - 10, (int) $xml->response[0]->comment[0]->supplemental[0]->time[0] );
    8888        $this->assertLessThanOrEqual( time(), (int) $xml->response[0]->comment[0]->supplemental[0]->time[0] );
     
    9191        $current = wp_get_comment_status( $comment->comment_ID );
    9292        if ( in_array( $prev_status, array( 'unapproved', 'spam' ), true ) ) {
    93             $this->assertEquals( 'approved', $current );
     93            $this->assertSame( 'approved', $current );
    9494        } else {
    95             $this->assertEquals( 'unapproved', $current );
     95            $this->assertSame( 'unapproved', $current );
    9696        }
    9797
     
    194194
    195195            // Ensure everything is correct.
    196             $this->assertEquals( '0', (string) $xml->response[0]->comment['id'] );
    197             $this->assertEquals( 'dim-comment_0', (string) $xml->response['action'] );
     196            $this->assertSame( '0', (string) $xml->response[0]->comment['id'] );
     197            $this->assertSame( 'dim-comment_0', (string) $xml->response['action'] );
    198198            $this->assertContains( 'Comment ' . $_POST['id'] . ' does not exist', $this->_last_response );
    199199
Note: See TracChangeset for help on using the changeset viewer.