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/rest-api/rest-block-directory-controller.php

    r48656 r48937  
    6161        $response = rest_get_server()->dispatch( $request );
    6262        $data     = $response->get_data();
    63         $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
    64         $this->assertEquals( array( 'view' ), $data['endpoints'][0]['args']['context']['enum'] );
     63        $this->assertSame( 'view', $data['endpoints'][0]['args']['context']['default'] );
     64        $this->assertSame( array( 'view' ), $data['endpoints'][0]['args']['context']['enum'] );
    6565    }
    6666
     
    7676        $result = rest_do_request( $request );
    7777        $this->assertNotWPError( $result->as_error() );
    78         $this->assertEquals( 200, $result->status );
     78        $this->assertSame( 200, $result->status );
    7979    }
    8080
     
    117117
    118118        // Should produce a 200 status with an empty array.
    119         $this->assertEquals( 200, $response->status );
    120         $this->assertEquals( array(), $data );
     119        $this->assertSame( 200, $response->status );
     120        $this->assertSame( array(), $data );
    121121    }
    122122
     
    167167        );
    168168
    169         $this->assertEquals( $expected, $response->get_data() );
     169        $this->assertSame( $expected, $response->get_data() );
    170170    }
    171171
     
    182182
    183183        // Check endpoints
    184         $this->assertEquals( array( 'GET' ), $data['endpoints'][0]['methods'] );
     184        $this->assertSame( array( 'GET' ), $data['endpoints'][0]['methods'] );
    185185        $this->assertTrue( $data['endpoints'][0]['args']['term']['required'] );
    186186
Note: See TracChangeset for help on using the changeset viewer.