WordPress.org

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/general/wpError.php

    r48937 r48939  
    113113        $this->wp_error->add( 'code', 'message' );
    114114
    115         $this->assertEqualSets( array( 'code' ), $this->wp_error->get_error_codes() );
     115        $this->assertSameSets( array( 'code' ), $this->wp_error->get_error_codes() );
    116116    }
    117117
     
    125125        $expected = array( 'code', 'code2' );
    126126
    127         $this->assertEqualSets( $expected, $this->wp_error->get_error_codes() );
     127        $this->assertSameSets( $expected, $this->wp_error->get_error_codes() );
    128128    }
    129129
     
    167167        $this->wp_error->add( 'code', 'message' );
    168168
    169         $this->assertEqualSets( array( 'message' ), $this->wp_error->get_error_messages() );
     169        $this->assertSameSets( array( 'message' ), $this->wp_error->get_error_messages() );
    170170    }
    171171
     
    177177        $this->wp_error->add( 'code2', 'message2' );
    178178
    179         $this->assertEqualSets( array( 'message', 'message2' ), $this->wp_error->get_error_messages() );
     179        $this->assertSameSets( array( 'message', 'message2' ), $this->wp_error->get_error_messages() );
    180180    }
    181181
     
    193193        $this->wp_error->add( 'code', 'message' );
    194194
    195         $this->assertEqualSets( array( 'message' ), $this->wp_error->get_error_messages( 'code' ) );
     195        $this->assertSameSets( array( 'message' ), $this->wp_error->get_error_messages( 'code' ) );
    196196    }
    197197
     
    302302        $this->wp_error->add( 'code', 'message', $expected );
    303303
    304         $this->assertEqualSetsWithIndex( $expected, $this->wp_error->get_error_data() );
     304        $this->assertSameSetsWithIndex( $expected, $this->wp_error->get_error_data() );
    305305    }
    306306
     
    313313        $this->wp_error->add( 'code2', 'message2', 'data2' );
    314314
    315         $this->assertEqualSetsWithIndex( $expected, $this->wp_error->get_error_data() );
     315        $this->assertSameSetsWithIndex( $expected, $this->wp_error->get_error_data() );
    316316    }
    317317
     
    350350        $this->wp_error->add( 'code', 'message', $expected );
    351351
    352         $this->assertEqualSetsWithIndex( $expected, $this->wp_error->get_error_data( 'code' ) );
     352        $this->assertSameSetsWithIndex( $expected, $this->wp_error->get_error_data( 'code' ) );
    353353    }
    354354
     
    362362        $this->wp_error->add( 'code', 'message3', $expected );
    363363
    364         $this->assertEqualSetsWithIndex( $expected, $this->wp_error->get_error_data( 'code' ) );
     364        $this->assertSameSetsWithIndex( $expected, $this->wp_error->get_error_data( 'code' ) );
    365365    }
    366366
     
    406406        $this->wp_error->add( '', '', 'data' );
    407407
    408         $this->assertEqualSetsWithIndex( array( '' => array( '' ) ), $this->wp_error->errors );
     408        $this->assertSameSetsWithIndex( array( '' => array( '' ) ), $this->wp_error->errors );
    409409    }
    410410
     
    424424        $this->wp_error->add( '', '', 'data' );
    425425
    426         $this->assertEqualSetsWithIndex( array( '' => 'data' ), $this->wp_error->error_data );
     426        $this->assertSameSetsWithIndex( array( '' => 'data' ), $this->wp_error->error_data );
    427427    }
    428428
     
    526526        $expected = array( 'message', 'message2' );
    527527
    528         $this->assertEqualSets( $expected, $this->wp_error->get_error_messages( 'code' ) );
     528        $this->assertSameSets( $expected, $this->wp_error->get_error_messages( 'code' ) );
    529529    }
    530530
     
    554554        $this->wp_error->add_data( '' );
    555555
    556         $this->assertEqualSets( array( '' => '' ), $this->wp_error->error_data );
     556        $this->assertSameSets( array( '' => '' ), $this->wp_error->error_data );
    557557    }
    558558
     
    607607        $this->wp_error->add_data( 'data', 'code' );
    608608
    609         $this->assertEqualSets( array( 'code' => 'data' ), $this->wp_error->error_data );
     609        $this->assertSameSets( array( 'code' => 'data' ), $this->wp_error->error_data );
    610610    }
    611611
     
    618618        $this->wp_error->add_data( 'data', 'code2' );
    619619
    620         $this->assertEqualSetsWithIndex( array( 'code' => array( 'message' ) ), $this->wp_error->errors );
     620        $this->assertSameSetsWithIndex( array( 'code' => array( 'message' ) ), $this->wp_error->errors );
    621621    }
    622622
     
    629629        $this->wp_error->add_data( 'data', 'code2' );
    630630
    631         $this->assertEqualSetsWithIndex( array( 'code2' => 'data' ), $this->wp_error->error_data );
     631        $this->assertSameSetsWithIndex( array( 'code2' => 'data' ), $this->wp_error->error_data );
    632632    }
    633633
     
    653653        $after = $this->wp_error->errors;
    654654
    655         $this->assertEqualSetsWithIndex( $before, $after );
     655        $this->assertSameSetsWithIndex( $before, $after );
    656656    }
    657657
     
    666666        $after = $this->wp_error->errors;
    667667
    668         $this->assertEqualSetsWithIndex( $before, $after );
     668        $this->assertSameSetsWithIndex( $before, $after );
    669669    }
    670670
     
    681681        $after = $this->wp_error->errors;
    682682
    683         $this->assertEqualSetsWithIndex( $before, $after );
     683        $this->assertSameSetsWithIndex( $before, $after );
    684684    }
    685685
Note: See TracChangeset for help on using the changeset viewer.