WordPress.org

Make WordPress Core


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

    r48758 r48937  
    7979
    8080        $this->assertArrayHasKey( 'X-WP-Total', $headers );
    81         $this->assertEquals( 1, $headers['X-WP-Total'] );
     81        $this->assertSame( 1, $headers['X-WP-Total'] );
    8282        $this->assertArrayHasKey( 'X-WP-TotalPages', $headers );
    83         $this->assertEquals( 1, $headers['X-WP-TotalPages'] );
     83        $this->assertSame( 1, $headers['X-WP-TotalPages'] );
    8484    }
    8585
     
    147147        $response = self::perform_active_theme_request();
    148148
    149         $this->assertEquals( 200, $response->get_status() );
     149        $this->assertSame( 200, $response->get_status() );
    150150        $data = $response->get_data();
    151151
     
    199199
    200200        $response = self::perform_active_theme_request();
    201         $this->assertEquals( 200, $response->get_status() );
     201        $this->assertSame( 200, $response->get_status() );
    202202    }
    203203
     
    209209    public function test_prepare_item() {
    210210        $response = self::perform_active_theme_request();
    211         $this->assertEquals( 200, $response->get_status() );
     211        $this->assertSame( 200, $response->get_status() );
    212212        $this->check_get_theme_response( $response );
    213213    }
     
    222222        $data       = $response->get_data();
    223223        $properties = $data['schema']['properties'];
    224         $this->assertEquals( 14, count( $properties ) );
     224        $this->assertSame( 14, count( $properties ) );
    225225
    226226        $this->assertArrayHasKey( 'author', $properties );
     
    530530        $result   = $response->get_data();
    531531        $this->assertArrayHasKey( 'theme_supports', $result[0] );
    532         $this->assertEquals( array( $wordpress_blue ), $result[0]['theme_supports']['editor-color-palette'] );
     532        $this->assertSame( array( $wordpress_blue ), $result[0]['theme_supports']['editor-color-palette'] );
    533533    }
    534534
     
    575575        remove_theme_support( 'custom-logo' );
    576576        $wordpress_logo = array(
     577            'width'                => 400,
    577578            'height'               => 100,
    578             'width'                => 400,
     579            'flex-width'           => true,
    579580            'flex-height'          => true,
    580             'flex-width'           => true,
    581581            'header-text'          => array( 'site-title', 'site-description' ),
    582582            'unlink-homepage-logo' => false,
     
    586586        $result   = $response->get_data();
    587587        $this->assertArrayHasKey( 'theme_supports', $result[0] );
    588         $this->assertEquals( $wordpress_logo, $result[0]['theme_supports']['custom-logo'] );
     588        $this->assertSame( $wordpress_logo, $result[0]['theme_supports']['custom-logo'] );
    589589    }
    590590
     
    634634
    635635        $expected = array_diff_key( $wordpress_header, array_flip( $excluded ) );
    636         $this->assertEquals( $expected, $result[0]['theme_supports']['custom-header'] );
     636        $this->assertSame( $expected, $result[0]['theme_supports']['custom-header'] );
    637637    }
    638638
     
    678678
    679679        $expected = array_diff_key( $background, array_flip( $excluded ) );
    680         $this->assertEquals( $expected, $result[0]['theme_supports']['custom-background'] );
     680        $this->assertSame( $expected, $result[0]['theme_supports']['custom-background'] );
    681681    }
    682682
     
    711711        $result   = $response->get_data();
    712712        $this->assertArrayHasKey( 'theme_supports', $result[0] );
    713         $this->assertEquals( $html5, $result[0]['theme_supports']['html5'] );
     713        $this->assertSame( $html5, $result[0]['theme_supports']['html5'] );
    714714    }
    715715
     
    896896        $result   = $response->get_data();
    897897        $this->assertArrayHasKey( 'theme_supports', $result[0] );
    898         $this->assertEquals( array( $gradient ), $result[0]['theme_supports']['editor-gradient-presets'] );
     898        $this->assertSame( array( $gradient ), $result[0]['theme_supports']['editor-gradient-presets'] );
    899899    }
    900900
     
    996996        $result   = $response->get_data();
    997997        $this->assertTrue( isset( $result[0]['theme_supports'] ) );
    998         $this->assertEquals( array( 'post' ), $result[0]['theme_supports']['post-thumbnails'] );
     998        $this->assertSame( array( 'post' ), $result[0]['theme_supports']['post-thumbnails'] );
    999999    }
    10001000
     
    10221022        $result   = $response->get_data();
    10231023        $this->assertTrue( isset( $result[0]['theme_supports'] ) );
    1024         $this->assertEquals( array( 'a', 'b', 'c' ), $result[0]['theme_supports']['test-feature'] );
     1024        $this->assertSame( array( 'a', 'b', 'c' ), $result[0]['theme_supports']['test-feature'] );
    10251025    }
    10261026
     
    10501050
    10511051        $this->assertArrayHasKey( 'my_custom_int', $data['schema']['properties'] );
    1052         $this->assertEquals( $schema, $data['schema']['properties']['my_custom_int'] );
     1052        $this->assertSame( $schema, $data['schema']['properties']['my_custom_int'] );
    10531053
    10541054        $response = self::perform_active_theme_request( 'GET' );
Note: See TracChangeset for help on using the changeset viewer.