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/widgets/media-widget.php

    r48858 r48937  
    7777            array_keys( $widget->l10n )
    7878        );
    79         $this->assertEquals( count( $widget->l10n ), count( array_filter( $widget->l10n ) ), 'Expected all translation strings to be defined.' );
    80         $this->assertEquals( 10, has_action( 'admin_print_scripts-widgets.php', array( $widget, 'enqueue_admin_scripts' ) ) );
     79        $this->assertSame( count( $widget->l10n ), count( array_filter( $widget->l10n ) ), 'Expected all translation strings to be defined.' );
     80        $this->assertSame( 10, has_action( 'admin_print_scripts-widgets.php', array( $widget, 'enqueue_admin_scripts' ) ) );
    8181        $this->assertFalse( has_action( 'wp_enqueue_scripts', array( $widget, 'enqueue_preview_scripts' ) ), 'Did not expect preview scripts to be enqueued when not in customize preview context.' );
    82         $this->assertEquals( 10, has_action( 'admin_footer-widgets.php', array( $widget, 'render_control_template_scripts' ) ) );
     82        $this->assertSame( 10, has_action( 'admin_footer-widgets.php', array( $widget, 'render_control_template_scripts' ) ) );
    8383
    8484        // With non-default args.
     
    9393        );
    9494        $widget          = $this->get_mocked_class_instance( $id_base, $name, $widget_options, $control_options );
    95         $this->assertEquals( $id_base, $widget->id_base );
    96         $this->assertEquals( $name, $widget->name );
     95        $this->assertSame( $id_base, $widget->id_base );
     96        $this->assertSame( $name, $widget->name );
    9797
    9898        // Method assertArraySubset doesn't exist in phpunit versions compatible with PHP 5.2.
     
    129129        $widget = $this->get_mocked_class_instance();
    130130        $widget->_register();
    131         $this->assertEquals( 10, has_action( 'wp_enqueue_scripts', array( $widget, 'enqueue_preview_scripts' ) ) );
     131        $this->assertSame( 10, has_action( 'wp_enqueue_scripts', array( $widget, 'enqueue_preview_scripts' ) ) );
    132132    }
    133133
     
    170170
    171171        $result = $widget->sanitize_token_list( 'What A false class with-token <a href="#">and link</a>' );
    172         $this->assertEquals( 'What A false class with-token a hrefand linka', $result );
     172        $this->assertSame( 'What A false class with-token a hrefand linka', $result );
    173173
    174174        $result = $widget->sanitize_token_list( array( 'foo', '<i>bar', '">NO' ) );
    175         $this->assertEquals( $result, 'foo ibar NO' );
     175        $this->assertSame( $result, 'foo ibar NO' );
    176176    }
    177177
     
    340340        $this->assertCount( 3, $this->widget_instance_filter_args );
    341341        $this->assertEquals( $instance, $this->widget_instance_filter_args[0] );
    342         $this->assertEquals( $args, $this->widget_instance_filter_args[1] );
    343         $this->assertEquals( $widget, $this->widget_instance_filter_args[2] );
     342        $this->assertSame( $args, $this->widget_instance_filter_args[1] );
     343        $this->assertSame( $widget, $this->widget_instance_filter_args[2] );
    344344        $output = ob_get_clean();
    345345
Note: See TracChangeset for help on using the changeset viewer.