Make WordPress Core


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

    r48100 r48937  
    4646         */
    4747        function test_construct() {
    48                 $this->assertEquals( $this->selective_refresh, $this->wp_customize->selective_refresh );
     48                $this->assertSame( $this->selective_refresh, $this->wp_customize->selective_refresh );
    4949        }
    5050
    … …  
    8484        function test_crud_partial() {
    8585                $partial = $this->selective_refresh->add_partial( 'foo' );
    86                 $this->assertEquals( $this->selective_refresh, $partial->component );
     86                $this->assertSame( $this->selective_refresh, $partial->component );
    8787                $this->assertInstanceOf( 'WP_Customize_Partial', $partial );
    88                 $this->assertEquals( $partial, $this->selective_refresh->get_partial( $partial->id ) );
     88                $this->assertSame( $partial, $this->selective_refresh->get_partial( $partial->id ) );
    8989                $this->assertArrayHasKey( $partial->id, $this->selective_refresh->partials() );
    9090
    … …  
    9494
    9595                $partial = new WP_Customize_Partial( $this->selective_refresh, 'bar' );
    96                 $this->assertEquals( $partial, $this->selective_refresh->add_partial( $partial ) );
    97                 $this->assertEquals( $partial, $this->selective_refresh->get_partial( 'bar' ) );
     96                $this->assertSame( $partial, $this->selective_refresh->add_partial( $partial ) );
     97                $this->assertSame( $partial, $this->selective_refresh->get_partial( 'bar' ) );
    9898                $this->assertEqualSets( array( 'bar' ), array_keys( $this->selective_refresh->partials() ) );
    9999
    … …  
    103103                $partial = $this->selective_refresh->add_partial( 'recognized-class' );
    104104                $this->assertInstanceOf( 'Tested_Custom_Partial', $partial );
    105                 $this->assertEquals( '.recognized', $partial->selector );
     105                $this->assertSame( '.recognized', $partial->selector );
    106106        }
    107107
    … …  
    113113        function test_init_preview() {
    114114                $this->selective_refresh->init_preview();
    115                 $this->assertEquals( 10, has_action( 'template_redirect', array( $this->selective_refresh, 'handle_render_partials_request' ) ) );
    116                 $this->assertEquals( 10, has_action( 'wp_enqueue_scripts', array( $this->selective_refresh, 'enqueue_preview_scripts' ) ) );
     115                $this->assertSame( 10, has_action( 'template_redirect', array( $this->selective_refresh, 'handle_render_partials_request' ) ) );
     116                $this->assertSame( 10, has_action( 'wp_enqueue_scripts', array( $this->selective_refresh, 'enqueue_preview_scripts' ) ) );
    117117        }
    118118
    … …  
    127127                $this->selective_refresh->enqueue_preview_scripts();
    128128                $this->assertContains( 'customize-selective-refresh', $scripts->queue );
    129                 $this->assertEquals( 1000, has_action( 'wp_footer', array( $this->selective_refresh, 'export_preview_data' ) ) );
     129                $this->assertSame( 1000, has_action( 'wp_footer', array( $this->selective_refresh, 'export_preview_data' ) ) );
    130130        }
    131131
    … …  
    169169                $this->assertArrayHasKey( 'blogname', $exported_data['partials'] );
    170170                $this->assertArrayNotHasKey( 'top_secret_message', $exported_data['partials'] );
    171                 $this->assertEquals( '#site-title', $exported_data['partials']['blogname']['selector'] );
     171                $this->assertSame( '#site-title', $exported_data['partials']['blogname']['selector'] );
    172172                $this->assertArrayHasKey( 'renderQueryVar', $exported_data );
    173173                $this->assertArrayHasKey( 'l10n', $exported_data );
    … …  
    195195                $this->assertInstanceOf( 'Tested_Custom_Partial', $this->selective_refresh->get_partial( 'recognized-class' ) );
    196196                $this->assertNotInstanceOf( 'Tested_Custom_Partial', $this->selective_refresh->get_partial( 'recognized' ) );
    197                 $this->assertEquals( '.recognized', $this->selective_refresh->get_partial( 'recognized' )->selector );
     197                $this->assertSame( '.recognized', $this->selective_refresh->get_partial( 'recognized' )->selector );
    198198        }
    199199
Note: See TracChangeset for help on using the changeset viewer.