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/customize/selective-refresh-ajax.php

    r47198 r48937  
    8080        $output = json_decode( ob_get_clean(), true );
    8181        $this->assertFalse( $output['success'] );
    82         $this->assertEquals( 'expected_customize_preview', $output['data'] );
     82        $this->assertSame( 'expected_customize_preview', $output['data'] );
    8383
    8484        // Check expected_customize_preview.
     
    9393        $output = json_decode( ob_get_clean(), true );
    9494        $this->assertFalse( $output['success'] );
    95         $this->assertEquals( 'expected_customize_preview', $output['data'] );
     95        $this->assertSame( 'expected_customize_preview', $output['data'] );
    9696
    9797        // Check missing_partials.
     
    105105        $output = json_decode( ob_get_clean(), true );
    106106        $this->assertFalse( $output['success'] );
    107         $this->assertEquals( 'missing_partials', $output['data'] );
     107        $this->assertSame( 'missing_partials', $output['data'] );
    108108
    109109        // Check missing_partials.
     
    114114            $this->selective_refresh->handle_render_partials_request();
    115115        } catch ( WPDieException $e ) {
    116             $this->assertEquals( '', $e->getMessage() );
     116            $this->assertSame( '', $e->getMessage() );
    117117        }
    118118        $output = json_decode( ob_get_clean(), true );
    119119        $this->assertFalse( $output['success'] );
    120         $this->assertEquals( 'malformed_partials', $output['data'] );
     120        $this->assertSame( 'malformed_partials', $output['data'] );
    121121    }
    122122
     
    157157            $this->selective_refresh->handle_render_partials_request();
    158158        } catch ( WPDieException $e ) {
    159             $this->assertEquals( '', $e->getMessage() );
     159            $this->assertSame( '', $e->getMessage() );
    160160        }
    161161        $output = json_decode( ob_get_clean(), true );
     
    165165        $this->assertArrayHasKey( 'errors', $output['data'] );
    166166        $this->assertArrayHasKey( 'foo', $output['data']['contents'] );
    167         $this->assertEquals( null, $output['data']['contents']['foo'] );
     167        $this->assertNull( $output['data']['contents']['foo'] );
    168168    }
    169169
     
    199199            $this->selective_refresh->handle_render_partials_request();
    200200        } catch ( WPDieException $e ) {
    201             $this->assertEquals( '', $e->getMessage() );
     201            $this->assertSame( '', $e->getMessage() );
    202202        }
    203203        $this->assertEquals( $count_customize_render_partials_before + 1, has_action( 'customize_render_partials_before' ) );
    204204        $this->assertEquals( $count_customize_render_partials_after + 1, has_action( 'customize_render_partials_after' ) );
    205205        $output = json_decode( ob_get_clean(), true );
    206         $this->assertEquals( array( false ), $output['data']['contents']['foo'] );
     206        $this->assertSame( array( false ), $output['data']['contents']['foo'] );
    207207    }
    208208
     
    237237            $this->selective_refresh->handle_render_partials_request();
    238238        } catch ( WPDieException $e ) {
    239             $this->assertEquals( '', $e->getMessage() );
     239            $this->assertSame( '', $e->getMessage() );
    240240        }
    241241        $output = json_decode( ob_get_clean(), true );
     
    267267            $this->selective_refresh->handle_render_partials_request();
    268268        } catch ( WPDieException $e ) {
    269             $this->assertEquals( '', $e->getMessage() );
     269            $this->assertSame( '', $e->getMessage() );
    270270        }
    271271        $output = json_decode( ob_get_clean(), true );
     
    337337            $this->selective_refresh->handle_render_partials_request();
    338338        } catch ( WPDieException $e ) {
    339             $this->assertEquals( '', $e->getMessage() );
     339            $this->assertSame( '', $e->getMessage() );
    340340        }
    341341        $this->assertEquals( $count_customize_render_partials_before + 1, has_action( 'customize_render_partials_before' ) );
    342342        $this->assertEquals( $count_customize_render_partials_after + 1, has_action( 'customize_render_partials_after' ) );
    343343        $output = json_decode( ob_get_clean(), true );
    344         $this->assertEquals( array( get_bloginfo( 'name', 'display' ) ), $output['data']['contents']['test_blogname'] );
     344        $this->assertSame( array( get_bloginfo( 'name', 'display' ) ), $output['data']['contents']['test_blogname'] );
    345345        $this->assertArrayHasKey( 'setting_validities', $output['data'] );
    346346    }
     
    446446            $this->selective_refresh->handle_render_partials_request();
    447447        } catch ( WPDieException $e ) {
    448             $this->assertEquals( '', $e->getMessage() );
     448            $this->assertSame( '', $e->getMessage() );
    449449        }
    450450        $this->assertEquals( $count_customize_render_partials_before + 1, has_action( 'customize_render_partials_before' ) );
    451451        $this->assertEquals( $count_customize_render_partials_after + 1, has_action( 'customize_render_partials_after' ) );
    452452        $output = json_decode( ob_get_clean(), true );
    453         $this->assertEquals( array( get_bloginfo( 'name', 'display' ) ), $output['data']['contents']['test_dynamic_blogname'] );
     453        $this->assertSame( array( get_bloginfo( 'name', 'display' ) ), $output['data']['contents']['test_dynamic_blogname'] );
    454454    }
    455455
     
    498498            $this->selective_refresh->handle_render_partials_request();
    499499        } catch ( WPDieException $e ) {
    500             $this->assertEquals( '', $e->getMessage() );
     500            $this->assertSame( '', $e->getMessage() );
    501501        }
    502502        $this->assertEquals( $count_customize_render_partials_before + 1, has_action( 'customize_render_partials_before' ) );
    503503        $this->assertEquals( $count_customize_render_partials_after + 1, has_action( 'customize_render_partials_after' ) );
    504504        $output = json_decode( ob_get_clean(), true );
    505         $this->assertEquals( array( get_bloginfo( 'name', 'display' ) ), $output['data']['contents']['test_blogname'] );
    506         $this->assertEquals( array_fill( 0, 2, get_bloginfo( 'description', 'display' ) ), $output['data']['contents']['test_blogdescription'] );
     505        $this->assertSame( array( get_bloginfo( 'name', 'display' ) ), $output['data']['contents']['test_blogname'] );
     506        $this->assertSame( array_fill( 0, 2, get_bloginfo( 'description', 'display' ) ), $output['data']['contents']['test_blogdescription'] );
    507507    }
    508508
Note: See TracChangeset for help on using the changeset viewer.