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

    r48220 r48937  
    8989
    9090        // Ensure everything is correct.
    91         $this->assertEquals( $comment->comment_ID, (string) $xml->response[0]->comment['id'] );
    92         $this->assertEquals( 'delete-comment_' . $comment->comment_ID, (string) $xml->response['action'] );
     91        $this->assertSame( $comment->comment_ID, (string) $xml->response[0]->comment['id'] );
     92        $this->assertSame( 'delete-comment_' . $comment->comment_ID, (string) $xml->response['action'] );
    9393        $this->assertGreaterThanOrEqual( time() - 10, (int) $xml->response[0]->comment[0]->supplemental[0]->time[0] );
    9494        $this->assertLessThanOrEqual( time(), (int) $xml->response[0]->comment[0]->supplemental[0]->time[0] );
     
    203203            $this->fail( 'Expected exception: WPAjaxDieStopException' );
    204204        } catch ( WPAjaxDieStopException $e ) {
    205             $this->assertEquals( 10, strlen( $e->getMessage() ) );
     205            $this->assertSame( 10, strlen( $e->getMessage() ) );
    206206            $this->assertTrue( is_numeric( $e->getMessage() ) );
    207207        } catch ( Exception $e ) {
     
    253253            $this->fail( 'Expected exception: WPAjaxDieStopException' );
    254254        } catch ( WPAjaxDieStopException $e ) {
    255             $this->assertEquals( 10, strlen( $e->getMessage() ) );
     255            $this->assertSame( 10, strlen( $e->getMessage() ) );
    256256            $this->assertTrue( is_numeric( $e->getMessage() ) );
    257257        } catch ( Exception $e ) {
Note: See TracChangeset for help on using the changeset viewer.