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

    r48858 r48937  
    336336        );
    337337        $response = rest_get_server()->dispatch( $request );
    338         $this->assertEquals( 400, $response->get_status() );
     338        $this->assertSame( 400, $response->get_status() );
    339339    }
    340340
     
    357357        );
    358358        $response = rest_get_server()->dispatch( $request );
    359         $this->assertEquals( 400, $response->get_status() );
     359        $this->assertSame( 400, $response->get_status() );
    360360    }
    361361
     
    382382        $request->set_param( 'attributes', array() );
    383383        $response = rest_get_server()->dispatch( $request );
    384         $this->assertEquals( 200, $response->get_status() );
     384        $this->assertSame( 200, $response->get_status() );
    385385        $data = $response->get_data();
    386386
    387         $this->assertEquals( $defaults, json_decode( $data['rendered'], true ) );
     387        $this->assertSame( $defaults, json_decode( $data['rendered'], true ) );
    388388        $this->assertEquals(
    389389            json_decode( $block_type->render( $defaults ) ),
     
    417417        $request->set_param( 'attributes', $attributes );
    418418        $response = rest_get_server()->dispatch( $request );
    419         $this->assertEquals( 200, $response->get_status() );
     419        $this->assertSame( 200, $response->get_status() );
    420420        $data = $response->get_data();
    421421
    422         $this->assertEquals( $expected_attributes, json_decode( $data['rendered'], true ) );
     422        $this->assertSame( $expected_attributes, json_decode( $data['rendered'], true ) );
    423423        $this->assertEquals(
    424424            json_decode( $block_type->render( $attributes ), true ),
     
    452452        $request->set_param( 'attributes', $attributes );
    453453        $response = rest_get_server()->dispatch( $request );
    454         $this->assertEquals( 200, $response->get_status() );
     454        $this->assertSame( 200, $response->get_status() );
    455455
    456456        $data = $response->get_data();
    457         $this->assertEquals( '<p>Alternate content.</p>', $data['rendered'] );
     457        $this->assertSame( '<p>Alternate content.</p>', $data['rendered'] );
    458458
    459459        remove_filter( 'pre_render_block', $pre_render_filter );
     
    475475        $response = rest_get_server()->dispatch( $request );
    476476
    477         $this->assertEquals( 200, $response->get_status() );
     477        $this->assertSame( 200, $response->get_status() );
    478478        $data = $response->get_data();
    479479
     
    484484        $response = rest_get_server()->dispatch( $request );
    485485
    486         $this->assertEquals( 200, $response->get_status() );
     486        $this->assertSame( 200, $response->get_status() );
    487487        $data = $response->get_data();
    488488
    489         $this->assertEquals( $expected_title, $data['rendered'] );
     489        $this->assertSame( $expected_title, $data['rendered'] );
    490490    }
    491491
     
    505505        $response = rest_get_server()->dispatch( $request );
    506506
    507         $this->assertEquals( 200, $response->get_status() );
     507        $this->assertSame( 200, $response->get_status() );
    508508        $this->assertContains( $string_attribute, $response->get_data()['rendered'] );
    509509    }
     
    579579        $request->set_param( 'attributes', $attributes );
    580580        $response = rest_get_server()->dispatch( $request );
    581         $this->assertEquals( 200, $response->get_status() );
     581        $this->assertSame( 200, $response->get_status() );
    582582        $data = $response->get_data();
    583583
     
    602602            array_keys( $data['endpoints'][0]['args'] )
    603603        );
    604         $this->assertEquals( 'object', $data['endpoints'][0]['args']['attributes']['type'] );
     604        $this->assertSame( 'object', $data['endpoints'][0]['args']['attributes']['type'] );
    605605
    606606        $this->assertArrayHasKey( 'schema', $data );
    607         $this->assertEquals( 'rendered-block', $data['schema']['title'] );
    608         $this->assertEquals( 'object', $data['schema']['type'] );
     607        $this->assertSame( 'rendered-block', $data['schema']['title'] );
     608        $this->assertSame( 'object', $data['schema']['type'] );
    609609        $this->arrayHasKey( 'rendered', $data['schema']['properties'] );
    610610        $this->arrayHasKey( 'string', $data['schema']['properties']['rendered']['type'] );
    611         $this->assertEquals( array( 'edit' ), $data['schema']['properties']['rendered']['context'] );
     611        $this->assertSame( array( 'edit' ), $data['schema']['properties']['rendered']['context'] );
    612612    }
    613613
Note: See TracChangeset for help on using the changeset viewer.