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/db/charset.php

    r47451 r48937  
    417417            // Make sure PHP's multibyte conversions are working correctly.
    418418            $this->assertNotEquals( $utf8, $big5 );
    419             $this->assertEquals( $utf8, $conv_utf8 );
     419            $this->assertSame( $utf8, $conv_utf8 );
    420420
    421421            $fields['big5'] = array(
     
    648648        $expected = 'H€lloWorld¢';
    649649        $actual   = $wpdb->strip_invalid_text_for_column( $wpdb->posts, 'post_content', $value );
    650         $this->assertEquals( $expected, $actual );
     650        $this->assertSame( $expected, $actual );
    651651    }
    652652
     
    755755
    756756        $charset = self::$_wpdb->get_table_charset( $table );
    757         $this->assertEquals( $charset, $expected_charset );
     757        $this->assertSame( $charset, $expected_charset );
    758758
    759759        $charset = self::$_wpdb->get_table_charset( strtoupper( $table ) );
    760         $this->assertEquals( $charset, $expected_charset );
     760        $this->assertSame( $charset, $expected_charset );
    761761
    762762        self::$_wpdb->query( $drop );
     
    795795
    796796        foreach ( $expected_charset as $column => $charset ) {
    797             $this->assertEquals( $charset, self::$_wpdb->get_col_charset( $table, $column ) );
    798             $this->assertEquals( $charset, self::$_wpdb->get_col_charset( strtoupper( $table ), strtoupper( $column ) ) );
     797            $this->assertSame( $charset, self::$_wpdb->get_col_charset( $table, $column ) );
     798            $this->assertSame( $charset, self::$_wpdb->get_col_charset( strtoupper( $table ), strtoupper( $column ) ) );
    799799        }
    800800
     
    820820        $columns = array_keys( $columns );
    821821        foreach ( $columns as $column => $charset ) {
    822             $this->assertEquals( false, self::$_wpdb->get_col_charset( $table, $column ) );
     822            $this->assertFalse( self::$_wpdb->get_col_charset( $table, $column ) );
    823823        }
    824824
     
    846846        $columns = array_keys( $columns );
    847847        foreach ( $columns as $column => $charset ) {
    848             $this->assertEquals( false, self::$_wpdb->get_col_charset( $table, $column ) );
     848            $this->assertFalse( self::$_wpdb->get_col_charset( $table, $column ) );
    849849        }
    850850
     
    902902
    903903        $return = self::$_wpdb->strip_invalid_text_from_query( $query );
    904         $this->assertEquals( $expected, $return );
     904        $this->assertSame( $expected, $return );
    905905
    906906        self::$_wpdb->query( $drop );
     
    936936    function test_dont_strip_text_from_schema_queries( $query ) {
    937937        $return = self::$_wpdb->strip_invalid_text_from_query( $query );
    938         $this->assertEquals( $query, $return );
     938        $this->assertSame( $query, $return );
    939939    }
    940940
     
    10181018
    10191019        $return = self::$_wpdb->check_safe_collation( $query );
    1020         $this->assertEquals( $expected, $return );
     1020        $this->assertSame( $expected, $return );
    10211021
    10221022        foreach ( $always_true as $true_query ) {
     
    10331033        // TEXT column.
    10341034        $stripped = $wpdb->strip_invalid_text_for_column( $wpdb->comments, 'comment_content', str_repeat( 'A', 65536 ) );
    1035         $this->assertEquals( 65535, strlen( $stripped ) );
     1035        $this->assertSame( 65535, strlen( $stripped ) );
    10361036
    10371037        // VARCHAR column.
    10381038        $stripped = $wpdb->strip_invalid_text_for_column( $wpdb->comments, 'comment_agent', str_repeat( 'A', 256 ) );
    1039         $this->assertEquals( 255, strlen( $stripped ) );
     1039        $this->assertSame( 255, strlen( $stripped ) );
    10401040    }
    10411041
     
    10541054        self::$_wpdb->query( "DROP TABLE $tablename" );
    10551055
    1056         $this->assertEquals( $safe_query, $stripped_query );
     1056        $this->assertSame( $safe_query, $stripped_query );
    10571057    }
    10581058
     
    10761076        self::$_wpdb->charset = $charset;
    10771077
    1078         $this->assertEquals( $safe_query, $stripped_query );
     1078        $this->assertSame( $safe_query, $stripped_query );
    10791079    }
    10801080
     
    10851085        self::$_wpdb->set_charset( self::$_wpdb->dbh, 'utf8', 'utf8_general_ci' );
    10861086        $results = self::$_wpdb->get_results( "SHOW VARIABLES WHERE Variable_name='collation_connection'" );
    1087         $this->assertEquals( 'utf8_general_ci', $results[0]->Value );
     1087        $this->assertSame( 'utf8_general_ci', $results[0]->Value );
    10881088
    10891089        self::$_wpdb->set_charset( self::$_wpdb->dbh, 'utf8mb4', 'utf8mb4_unicode_ci' );
    10901090        $results = self::$_wpdb->get_results( "SHOW VARIABLES WHERE Variable_name='collation_connection'" );
    1091         $this->assertEquals( 'utf8mb4_unicode_ci', $results[0]->Value );
     1091        $this->assertSame( 'utf8mb4_unicode_ci', $results[0]->Value );
    10921092
    10931093        self::$_wpdb->set_charset( self::$_wpdb->dbh );
Note: See TracChangeset for help on using the changeset viewer.