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/widgets/media-widget.php

    r48937 r48939  
    6363        $this->assertTrue( $widget->widget_options['customize_selective_refresh'] );
    6464        $this->assertEmpty( $widget->widget_options['mime_type'] );
    65         $this->assertEqualSets(
     65        $this->assertSameSets(
    6666            array(
    6767                'add_to_widget',
     
    207207        $schema = $widget->get_instance_schema();
    208208
    209         $this->assertEqualSets(
     209        $this->assertSameSets(
    210210            array(
    211211                'attachment_id',
     
    222222        $this->assertInternalType( 'array', $this->filter_instance_schema_args );
    223223        $this->assertSame( $widget, $this->filter_instance_schema_args['widget'] );
    224         $this->assertEqualSets( array( 'attachment_id', 'title', 'url' ), array_keys( $this->filter_instance_schema_args['schema'] ) );
     224        $this->assertSameSets( array( 'attachment_id', 'title', 'url' ), array_keys( $this->filter_instance_schema_args['schema'] ) );
    225225        $this->assertArrayHasKey( 'injected', $schema );
    226226    }
     
    420420
    421421        $result = $widget->display_media_state( array(), get_post( $attachment_id ) );
    422         $this->assertEqualSets( array(), $result );
     422        $this->assertSameSets( array(), $result );
    423423
    424424        $widget->save_settings(
     
    430430        );
    431431        $result = $widget->display_media_state( array(), get_post( $attachment_id ) );
    432         $this->assertEqualSets( array( $widget->l10n['media_library_state_single'] ), $result );
     432        $this->assertSameSets( array( $widget->l10n['media_library_state_single'] ), $result );
    433433
    434434        $widget->save_settings(
     
    443443        );
    444444        $result = $widget->display_media_state( array(), get_post( $attachment_id ) );
    445         $this->assertEqualSets( array( sprintf( $widget->l10n['media_library_state_multi']['singular'], 2 ) ), $result );
     445        $this->assertSameSets( array( sprintf( $widget->l10n['media_library_state_multi']['singular'], 2 ) ), $result );
    446446    }
    447447
Note: See TracChangeset for help on using the changeset viewer.