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/post/getPages.php

    r48937 r48939  
    125125
    126126        $cached_ids = wp_list_pluck( $cached, 'ID' );
    127         $this->assertEqualSets( array( $posts[0] ), $cached_ids );
     127        $this->assertSameSets( array( $posts[0] ), $cached_ids );
    128128
    129129        add_post_meta( $posts[1], 'foo', 'bar' );
     
    137137
    138138        $found_ids = wp_list_pluck( $found, 'ID' );
    139         $this->assertEqualSets( $posts, $found_ids );
     139        $this->assertSameSets( $posts, $found_ids );
    140140    }
    141141
     
    162162
    163163        $cached_ids = wp_list_pluck( $cached, 'ID' );
    164         $this->assertEqualSets( $posts, $cached_ids );
     164        $this->assertSameSets( $posts, $cached_ids );
    165165
    166166        update_post_meta( $posts[1], 'foo', 'baz' );
     
    174174
    175175        $found_ids = wp_list_pluck( $found, 'ID' );
    176         $this->assertEqualSets( array( $posts[0] ), $found_ids );
     176        $this->assertSameSets( array( $posts[0] ), $found_ids );
    177177    }
    178178
     
    199199
    200200        $cached_ids = wp_list_pluck( $cached, 'ID' );
    201         $this->assertEqualSets( $posts, $cached_ids );
     201        $this->assertSameSets( $posts, $cached_ids );
    202202
    203203        delete_post_meta( $posts[1], 'foo' );
     
    211211
    212212        $found_ids = wp_list_pluck( $found, 'ID' );
    213         $this->assertEqualSets( array( $posts[0] ), $found_ids );
     213        $this->assertSameSets( array( $posts[0] ), $found_ids );
    214214    }
    215215
     
    236236
    237237        $cached_ids = wp_list_pluck( $cached, 'ID' );
    238         $this->assertEqualSets( $posts, $cached_ids );
     238        $this->assertSameSets( $posts, $cached_ids );
    239239
    240240        delete_post_meta_by_key( 'foo' );
     
    248248
    249249        $found_ids = wp_list_pluck( $found, 'ID' );
    250         $this->assertEqualSets( array(), $found_ids );
     250        $this->assertSameSets( array(), $found_ids );
    251251    }
    252252
     
    341341            )
    342342        );
    343         $this->assertEqualSets( array( $page_id1 ), wp_list_pluck( $pages, 'ID' ) );
     343        $this->assertSameSets( array( $page_id1 ), wp_list_pluck( $pages, 'ID' ) );
    344344
    345345        $pages = get_pages(
     
    349349            )
    350350        );
    351         $this->assertEqualSets( array( $page_id2, $page_id4 ), wp_list_pluck( $pages, 'ID' ) );
     351        $this->assertSameSets( array( $page_id2, $page_id4 ), wp_list_pluck( $pages, 'ID' ) );
    352352
    353353        $pages = get_pages(
     
    357357            )
    358358        );
    359         $this->assertEqualSets( array( $page_id2, $page_id3, $page_id4 ), wp_list_pluck( $pages, 'ID' ) );
     359        $this->assertSameSets( array( $page_id2, $page_id3, $page_id4 ), wp_list_pluck( $pages, 'ID' ) );
    360360
    361361        $pages = get_pages( array( 'parent' => 0 ) );
    362         $this->assertEqualSets( array( $page_id1 ), wp_list_pluck( $pages, 'ID' ) );
     362        $this->assertSameSets( array( $page_id1 ), wp_list_pluck( $pages, 'ID' ) );
    363363
    364364        $pages = get_pages( array( 'parent' => $page_id1 ) );
    365         $this->assertEqualSets( array( $page_id2, $page_id4 ), wp_list_pluck( $pages, 'ID' ) );
     365        $this->assertSameSets( array( $page_id2, $page_id4 ), wp_list_pluck( $pages, 'ID' ) );
    366366
    367367        $pages = get_pages( array( 'parent' => array( $page_id1, $page_id2 ) ) );
    368         $this->assertEqualSets( array( $page_id2, $page_id3, $page_id4 ), wp_list_pluck( $pages, 'ID' ) );
     368        $this->assertSameSets( array( $page_id2, $page_id3, $page_id4 ), wp_list_pluck( $pages, 'ID' ) );
    369369    }
    370370
     
    393393            )
    394394        );
    395         $this->assertEqualSets( $child_ids, $post_ids );
     395        $this->assertSameSets( $child_ids, $post_ids );
    396396    }
    397397
     
    443443         */
    444444
    445         $this->assertEqualSets( array( $page_1, $page_2, $page_4, $page_3 ), wp_list_pluck( $pages, 'ID' ) );
     445        $this->assertSameSets( array( $page_1, $page_2, $page_4, $page_3 ), wp_list_pluck( $pages, 'ID' ) );
    446446    }
    447447
     
    489489        $found_pages = wp_list_filter( $pages, array( 'post_parent' => 0 ) );
    490490
    491         $this->assertEqualSets( array( $page_1, $page_2 ), wp_list_pluck( $found_pages, 'ID' ) );
     491        $this->assertSameSets( array( $page_1, $page_2 ), wp_list_pluck( $found_pages, 'ID' ) );
    492492    }
    493493
     
    525525         */
    526526
    527         $this->assertEqualSets( array( $page_1, $page_2, $page_3, $page_4 ), wp_list_pluck( $pages, 'ID' ) );
     527        $this->assertSameSets( array( $page_1, $page_2, $page_3, $page_4 ), wp_list_pluck( $pages, 'ID' ) );
    528528    }
    529529
     
    568568         */
    569569
    570         $this->assertEqualSets( array( $page_3, $page_4, $page_5 ), wp_list_pluck( $pages, 'ID' ) );
     570        $this->assertSameSets( array( $page_3, $page_4, $page_5 ), wp_list_pluck( $pages, 'ID' ) );
    571571    }
    572572
     
    615615         * hierarchically anyway in order of creation: 3, 4, 5.
    616616         */
    617         $this->assertEqualSets( array( $page_3, $page_4, $page_5 ), wp_list_pluck( $pages, 'ID' ) );
     617        $this->assertSameSets( array( $page_3, $page_4, $page_5 ), wp_list_pluck( $pages, 'ID' ) );
    618618
    619619        // How it should work.
    620620        $found_pages = wp_list_filter( $pages, array( 'post_parent' => $page_1 ) );
    621         $this->assertEqualSets( array( $page_3, $page_5 ), wp_list_pluck( $found_pages, 'ID' ) );
     621        $this->assertSameSets( array( $page_3, $page_5 ), wp_list_pluck( $found_pages, 'ID' ) );
    622622
    623623    }
Note: See TracChangeset for help on using the changeset viewer.