Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (5 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/partial.php

    r47198 r48937  
    4848        $partial_id = 'blogname';
    4949        $partial    = new WP_Customize_Partial( $this->selective_refresh, $partial_id );
    50         $this->assertEquals( $partial_id, $partial->id );
    51         $this->assertEquals( $this->selective_refresh, $partial->component );
    52         $this->assertEquals( 'default', $partial->type );
     50        $this->assertSame( $partial_id, $partial->id );
     51        $this->assertSame( $this->selective_refresh, $partial->component );
     52        $this->assertSame( 'default', $partial->type );
    5353        $this->assertEmpty( $partial->selector );
    54         $this->assertEquals( array( $partial_id ), $partial->settings );
    55         $this->assertEquals( $partial_id, $partial->primary_setting );
    56         $this->assertEquals( array( $partial, 'render_callback' ), $partial->render_callback );
    57         $this->assertEquals( false, $partial->container_inclusive );
    58         $this->assertEquals( true, $partial->fallback_refresh );
     54        $this->assertSame( array( $partial_id ), $partial->settings );
     55        $this->assertSame( $partial_id, $partial->primary_setting );
     56        $this->assertSame( array( $partial, 'render_callback' ), $partial->render_callback );
     57        $this->assertFalse( $partial->container_inclusive );
     58        $this->assertTrue( $partial->fallback_refresh );
    5959    }
    6060
     
    103103        );
    104104        $partial    = new WP_Customize_Partial( $this->selective_refresh, $partial_id, $args );
    105         $this->assertEquals( $partial_id, $partial->id );
    106         $this->assertEquals( $this->selective_refresh, $partial->component );
    107         $this->assertEquals( $args['type'], $partial->type );
    108         $this->assertEquals( $args['selector'], $partial->selector );
     105        $this->assertSame( $partial_id, $partial->id );
     106        $this->assertSame( $this->selective_refresh, $partial->component );
     107        $this->assertSame( $args['type'], $partial->type );
     108        $this->assertSame( $args['selector'], $partial->selector );
    109109        $this->assertEqualSets( $args['settings'], $partial->settings );
    110         $this->assertEquals( $args['primary_setting'], $partial->primary_setting );
    111         $this->assertEquals( $args['render_callback'], $partial->render_callback );
    112         $this->assertEquals( false, $partial->container_inclusive );
    113         $this->assertEquals( false, $partial->fallback_refresh );
     110        $this->assertSame( $args['primary_setting'], $partial->primary_setting );
     111        $this->assertSame( $args['render_callback'], $partial->render_callback );
     112        $this->assertFalse( $partial->container_inclusive );
     113        $this->assertFalse( $partial->fallback_refresh );
    114114        $this->assertContains( 'Lorem Ipsum', $partial->render() );
    115115
     
    121121            )
    122122        );
    123         $this->assertEquals( array( 'blogdescription' ), $partial->settings );
    124         $this->assertEquals( 'blogdescription', $partial->primary_setting );
     123        $this->assertSame( array( 'blogdescription' ), $partial->settings );
     124        $this->assertSame( 'blogdescription', $partial->primary_setting );
    125125    }
    126126
     
    133133        $partial = new WP_Customize_Partial( $this->selective_refresh, 'foo' );
    134134        $id_data = $partial->id_data();
    135         $this->assertEquals( 'foo', $id_data['base'] );
    136         $this->assertEquals( array(), $id_data['keys'] );
     135        $this->assertSame( 'foo', $id_data['base'] );
     136        $this->assertSame( array(), $id_data['keys'] );
    137137
    138138        $partial = new WP_Customize_Partial( $this->selective_refresh, 'bar[baz][quux]' );
    139139        $id_data = $partial->id_data();
    140         $this->assertEquals( 'bar', $id_data['base'] );
    141         $this->assertEquals( array( 'baz', 'quux' ), $id_data['keys'] );
     140        $this->assertSame( 'bar', $id_data['base'] );
     141        $this->assertSame( array( 'baz', 'quux' ), $id_data['keys'] );
    142142    }
    143143
     
    181181     */
    182182    function filter_customize_partial_render_with_id( $rendered, $partial, $container_context ) {
    183         $this->assertEquals( sprintf( 'customize_partial_render_%s', $partial->id ), current_filter() );
     183        $this->assertSame( sprintf( 'customize_partial_render_%s', $partial->id ), current_filter() );
    184184        $this->assertTrue( false === $rendered || is_string( $rendered ) );
    185185        $this->assertInstanceOf( 'WP_Customize_Partial', $partial );
     
    250250        add_filter( "customize_partial_render_{$partial->id}", array( $this, 'filter_customize_partial_render_with_id' ), 10, 3 );
    251251        $rendered = $partial->render();
    252         $this->assertEquals( 'foo', $rendered );
    253         $this->assertEquals( $count_filter_customize_partial_render + 1, $this->count_filter_customize_partial_render );
    254         $this->assertEquals( $count_filter_customize_partial_render_with_id + 1, $this->count_filter_customize_partial_render_with_id );
     252        $this->assertSame( 'foo', $rendered );
     253        $this->assertSame( $count_filter_customize_partial_render + 1, $this->count_filter_customize_partial_render );
     254        $this->assertSame( $count_filter_customize_partial_render_with_id + 1, $this->count_filter_customize_partial_render_with_id );
    255255    }
    256256
     
    273273        add_filter( "customize_partial_render_{$partial->id}", array( $this, 'filter_customize_partial_render_with_id' ), 10, 3 );
    274274        $rendered = $partial->render();
    275         $this->assertEquals( 'bar', $rendered );
    276         $this->assertEquals( $count_filter_customize_partial_render + 1, $this->count_filter_customize_partial_render );
    277         $this->assertEquals( $count_filter_customize_partial_render_with_id + 1, $this->count_filter_customize_partial_render_with_id );
     275        $this->assertSame( 'bar', $rendered );
     276        $this->assertSame( $count_filter_customize_partial_render + 1, $this->count_filter_customize_partial_render );
     277        $this->assertSame( $count_filter_customize_partial_render_with_id + 1, $this->count_filter_customize_partial_render_with_id );
    278278    }
    279279
Note: See TracChangeset for help on using the changeset viewer.