Make WordPress Core


Ignore:
Timestamp:
09/04/2020 07:01:00 AM (4 years ago)
Author:
SergeyBiryukov
Message:

Tests: Introduce assertSameSets() and assertSameSetsWithIndex(), and use them where appropriate.

This ensures that not only the array values being compared are equal, but also that their type is the same.

These new methods replace most of the existing instances of assertEqualSets() and assertEqualSetsWithIndex().

Going forward, stricter type checking by using assertSameSets() or assertSameSetsWithIndex() should generally be preferred, to make the tests more reliable.

Follow-up to [48937].

See #38266.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-search-controller.php

    r48937 r48939  
    112112
    113113        $this->assertSame( 200, $response->get_status() );
    114         $this->assertEqualSets(
     114        $this->assertSameSets(
    115115            array_merge(
    116116                self::$my_title_post_ids,
     
    148148
    149149        $this->assertSame( 200, $response->get_status() );
    150         $this->assertEqualSets(
     150        $this->assertSameSets(
    151151            array_merge(
    152152                self::$my_title_post_ids,
     
    171171
    172172        $this->assertSame( 200, $response->get_status() );
    173         $this->assertEqualSets(
     173        $this->assertSameSets(
    174174            array_merge(
    175175                self::$my_title_post_ids,
     
    193193
    194194        $this->assertSame( 200, $response->get_status() );
    195         $this->assertEqualSets(
     195        $this->assertSameSets(
    196196            self::$my_title_page_ids,
    197197            wp_list_pluck( $response->get_data(), 'id' )
     
    241241
    242242        $this->assertSame( 200, $response->get_status() );
    243         $this->assertEqualSets(
     243        $this->assertSameSets(
    244244            array_merge(
    245245                self::$my_title_post_ids,
     
    263263
    264264        $this->assertSame( 200, $response->get_status() );
    265         $this->assertEqualSets(
     265        $this->assertSameSets(
    266266            array_merge(
    267267                self::$my_title_post_ids,
     
    284284
    285285        $this->assertSame( 200, $response->get_status() );
    286         $this->assertEqualSets(
     286        $this->assertSameSets(
    287287            self::$my_content_post_ids,
    288288            wp_list_pluck( $response->get_data(), 'id' )
     
    421421        );
    422422        $response = $controller->get_items( $request );
    423         $this->assertEqualSets( range( 1, 10 ), wp_list_pluck( $response->get_data(), 'id' ) );
     423        $this->assertSameSets( range( 1, 10 ), wp_list_pluck( $response->get_data(), 'id' ) );
    424424
    425425        $request  = $this->get_request(
     
    432432        );
    433433        $response = $controller->get_items( $request );
    434         $this->assertEqualSets( range( 1, 5 ), wp_list_pluck( $response->get_data(), 'id' ) );
     434        $this->assertSameSets( range( 1, 5 ), wp_list_pluck( $response->get_data(), 'id' ) );
    435435    }
    436436
     
    497497        $params = $controller->get_collection_params();
    498498        $this->assertSame( 'test', $params[ WP_REST_Search_Controller::PROP_TYPE ]['default'] );
    499         $this->assertEqualSets( array( 'test' ), $params[ WP_REST_Search_Controller::PROP_TYPE ]['enum'] );
    500         $this->assertEqualSets( array( 'test_first_type', 'test_second_type', WP_REST_Search_Controller::TYPE_ANY ), $params[ WP_REST_Search_Controller::PROP_SUBTYPE ]['items']['enum'] );
     499        $this->assertSameSets( array( 'test' ), $params[ WP_REST_Search_Controller::PROP_TYPE ]['enum'] );
     500        $this->assertSameSets( array( 'test_first_type', 'test_second_type', WP_REST_Search_Controller::TYPE_ANY ), $params[ WP_REST_Search_Controller::PROP_SUBTYPE ]['items']['enum'] );
    501501    }
    502502
Note: See TracChangeset for help on using the changeset viewer.