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/customize/section.php

    r47198 r48937  
    4040        $section = new WP_Customize_Section( $this->manager, 'foo' );
    4141        $this->assertInternalType( 'int', $section->instance_number );
    42         $this->assertEquals( $this->manager, $section->manager );
    43         $this->assertEquals( 'foo', $section->id );
    44         $this->assertEquals( 160, $section->priority );
    45         $this->assertEquals( 'edit_theme_options', $section->capability );
    46         $this->assertEquals( '', $section->theme_supports );
    47         $this->assertEquals( '', $section->title );
    48         $this->assertEquals( '', $section->description );
     42        $this->assertSame( $this->manager, $section->manager );
     43        $this->assertSame( 'foo', $section->id );
     44        $this->assertSame( 160, $section->priority );
     45        $this->assertSame( 'edit_theme_options', $section->capability );
     46        $this->assertSame( '', $section->theme_supports );
     47        $this->assertSame( '', $section->title );
     48        $this->assertSame( '', $section->description );
    4949        $this->assertEmpty( $section->panel );
    50         $this->assertEquals( 'default', $section->type );
    51         $this->assertEquals( array( $section, 'active_callback' ), $section->active_callback );
     50        $this->assertSame( 'default', $section->type );
     51        $this->assertSame( array( $section, 'active_callback' ), $section->active_callback );
    5252    }
    5353
     
    7171        $section = new WP_Customize_Section( $this->manager, 'foo', $args );
    7272        foreach ( $args as $key => $value ) {
    73             $this->assertEquals( $value, $section->$key );
     73            $this->assertSame( $value, $section->$key );
    7474        }
    7575    }
     
    8080    function test_construct_custom_type() {
    8181        $section = new Custom_Section_Test( $this->manager, 'foo' );
    82         $this->assertEquals( 'titleless', $section->type );
     82        $this->assertSame( 'titleless', $section->type );
    8383    }
    8484
     
    134134        $section = new WP_Customize_Section( $this->manager, 'foo', $args );
    135135        $data    = $section->json();
    136         $this->assertEquals( 'foo', $data['id'] );
     136        $this->assertSame( 'foo', $data['id'] );
    137137        foreach ( array( 'title', 'description', 'priority', 'panel', 'type' ) as $key ) {
    138             $this->assertEquals( $args[ $key ], $data[ $key ] );
     138            $this->assertSame( $args[ $key ], $data[ $key ] );
    139139        }
    140140        $this->assertEmpty( $data['content'] );
     
    181181        $this->assertTrue( $section->check_capabilities() );
    182182        $this->assertEmpty( $content );
    183         $this->assertEquals( $customize_render_section_count + 1, did_action( 'customize_render_section' ), 'Unexpected did_action count for customize_render_section' );
    184         $this->assertEquals( 1, did_action( "customize_render_section_{$section->id}" ), "Unexpected did_action count for customize_render_section_{$section->id}" );
     183        $this->assertSame( $customize_render_section_count + 1, did_action( 'customize_render_section' ), 'Unexpected did_action count for customize_render_section' );
     184        $this->assertSame( 1, did_action( "customize_render_section_{$section->id}" ), "Unexpected did_action count for customize_render_section_{$section->id}" );
    185185    }
    186186
Note: See TracChangeset for help on using the changeset viewer.