Make WordPress Core


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

    r47198 r48937  
    3333        $panel = new WP_Customize_Panel( $this->manager, 'foo' );
    3434        $this->assertInternalType( 'int', $panel->instance_number );
    35         $this->assertEquals( $this->manager, $panel->manager );
    36         $this->assertEquals( 'foo', $panel->id );
    37         $this->assertEquals( 160, $panel->priority );
    38         $this->assertEquals( 'edit_theme_options', $panel->capability );
    39         $this->assertEquals( '', $panel->theme_supports );
    40         $this->assertEquals( '', $panel->title );
    41         $this->assertEquals( '', $panel->description );
     35        $this->assertSame( $this->manager, $panel->manager );
     36        $this->assertSame( 'foo', $panel->id );
     37        $this->assertSame( 160, $panel->priority );
     38        $this->assertSame( 'edit_theme_options', $panel->capability );
     39        $this->assertSame( '', $panel->theme_supports );
     40        $this->assertSame( '', $panel->title );
     41        $this->assertSame( '', $panel->description );
    4242        $this->assertEmpty( $panel->sections );
    43         $this->assertEquals( 'default', $panel->type );
    44         $this->assertEquals( array( $panel, 'active_callback' ), $panel->active_callback );
     43        $this->assertSame( 'default', $panel->type );
     44        $this->assertSame( array( $panel, 'active_callback' ), $panel->active_callback );
    4545    }
    4646
     
    6161        $panel = new WP_Customize_Panel( $this->manager, 'foo', $args );
    6262        foreach ( $args as $key => $value ) {
    63             $this->assertEquals( $value, $panel->$key );
     63            $this->assertSame( $value, $panel->$key );
    6464        }
    6565    }
     
    7070    function test_construct_custom_type() {
    7171        $panel = new Custom_Panel_Test( $this->manager, 'foo' );
    72         $this->assertEquals( 'titleless', $panel->type );
     72        $this->assertSame( 'titleless', $panel->type );
    7373    }
    7474
     
    120120        $panel = new WP_Customize_Panel( $this->manager, 'foo', $args );
    121121        $data  = $panel->json();
    122         $this->assertEquals( 'foo', $data['id'] );
     122        $this->assertSame( 'foo', $data['id'] );
    123123        foreach ( array( 'title', 'description', 'priority', 'type' ) as $key ) {
    124             $this->assertEquals( $args[ $key ], $data[ $key ] );
     124            $this->assertSame( $args[ $key ], $data[ $key ] );
    125125        }
    126126        $this->assertEmpty( $data['content'] );
     
    168168        $this->assertTrue( $panel->check_capabilities() );
    169169        $this->assertEmpty( $content );
    170         $this->assertEquals( $customize_render_panel_count + 1, did_action( 'customize_render_panel' ), 'Unexpected did_action count for customize_render_panel' );
    171         $this->assertEquals( 1, did_action( "customize_render_panel_{$panel->id}" ), "Unexpected did_action count for customize_render_panel_{$panel->id}" );
     170        $this->assertSame( $customize_render_panel_count + 1, did_action( 'customize_render_panel' ), 'Unexpected did_action count for customize_render_panel' );
     171        $this->assertSame( 1, did_action( "customize_render_panel_{$panel->id}" ), "Unexpected did_action count for customize_render_panel_{$panel->id}" );
    172172    }
    173173
Note: See TracChangeset for help on using the changeset viewer.