Make WordPress Core


Ignore:
Timestamp:
09/04/2020 07:01:00 AM (17 months 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/customize/nav-menu-setting.php

    r48937 r48939  
    203203        $term = (array) wp_get_nav_menu_object( $menu_id );
    204204
    205         $this->assertEqualSets(
     205        $this->assertSameSets(
    206206            wp_array_slice_assoc( $value, array( 'name', 'description', 'parent' ) ),
    207207            wp_array_slice_assoc( $term, array( 'name', 'description', 'parent' ) )
     
    214214        $this->assertSame( 1, $value['parent'] );
    215215        $term = (array) wp_get_nav_menu_object( $menu_id );
    216         $this->assertEqualSets( $value, wp_array_slice_assoc( $term, array_keys( $value ) ) );
     216        $this->assertSameSets( $value, wp_array_slice_assoc( $term, array_keys( $value ) ) );
    217217
    218218        $menu_object = wp_get_nav_menu_object( $menu_id );
     
    257257        $this->assertNotEmpty( $term );
    258258        $this->assertNotWPError( $term );
    259         $this->assertEqualSets( $post_value, wp_array_slice_assoc( $term, array_keys( $value ) ) );
     259        $this->assertSameSets( $post_value, wp_array_slice_assoc( $term, array_keys( $value ) ) );
    260260        $this->assertSame( $menu_id, $term['term_id'] );
    261261        $this->assertSame( $menu_id, $term['term_taxonomy_id'] );
     
    339339        $this->assertSame( 0, $sanitized['parent'] );
    340340        $this->assertTrue( $sanitized['auto_add'] );
    341         $this->assertEqualSets( array( 'name', 'description', 'parent', 'auto_add' ), array_keys( $sanitized ) );
     341        $this->assertSameSets( array( 'name', 'description', 'parent', 'auto_add' ), array_keys( $sanitized ) );
    342342
    343343        $value['name'] = '    '; // Blank spaces.
     
    386386            $this->assertSame( $new_value[ $key ], $menu_object->$key );
    387387        }
    388         $this->assertEqualSets(
     388        $this->assertSameSets(
    389389            wp_array_slice_assoc( $new_value, array( 'name', 'description', 'parent' ) ),
    390390            wp_array_slice_assoc( (array) $menu_object, array( 'name', 'description', 'parent' ) )
     
    442442        $menu = wp_get_nav_menu_object( $setting->term_id );
    443443        unset( $post_value['auto_add'] );
    444         $this->assertEqualSets( $post_value, wp_array_slice_assoc( (array) $menu, array_keys( $post_value ) ) );
     444        $this->assertSameSets( $post_value, wp_array_slice_assoc( (array) $menu, array_keys( $post_value ) ) );
    445445
    446446        $save_response = apply_filters( 'customize_save_response', array() );
Note: See TracChangeset for help on using the changeset viewer.