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/rewrite/rewriteTags.php

    r44577 r48939  
    4949
    5050        add_rewrite_tag( $tag, $regex );
    51         $this->assertEqualSets( $this->rewritecode, $wp_rewrite->rewritecode );
    52         $this->assertEqualSets( $this->rewritereplace, $wp_rewrite->rewritereplace );
    53         $this->assertEqualSets( $this->queryreplace, $wp_rewrite->queryreplace );
     51        $this->assertSameSets( $this->rewritecode, $wp_rewrite->rewritecode );
     52        $this->assertSameSets( $this->rewritereplace, $wp_rewrite->rewritereplace );
     53        $this->assertSameSets( $this->queryreplace, $wp_rewrite->queryreplace );
    5454    }
    5555
     
    6161        add_rewrite_tag( '%foo%', 'bar' );
    6262
    63         $this->assertEqualSets( $rewritecode, $wp_rewrite->rewritecode );
    64         $this->assertEqualSets( array_merge( $this->rewritereplace, array( 'bar' ) ), $wp_rewrite->rewritereplace );
    65         $this->assertEqualSets( array_merge( $this->queryreplace, array( 'foo=' ) ), $wp_rewrite->queryreplace );
     63        $this->assertSameSets( $rewritecode, $wp_rewrite->rewritecode );
     64        $this->assertSameSets( array_merge( $this->rewritereplace, array( 'bar' ) ), $wp_rewrite->rewritereplace );
     65        $this->assertSameSets( array_merge( $this->queryreplace, array( 'foo=' ) ), $wp_rewrite->queryreplace );
    6666    }
    6767
     
    7373        add_rewrite_tag( '%foo%', 'bar', 'baz=' );
    7474
    75         $this->assertEqualSets( $rewritecode, $wp_rewrite->rewritecode );
    76         $this->assertEqualSets( array_merge( $this->rewritereplace, array( 'bar' ) ), $wp_rewrite->rewritereplace );
    77         $this->assertEqualSets( array_merge( $this->queryreplace, array( 'baz=' ) ), $wp_rewrite->queryreplace );
     75        $this->assertSameSets( $rewritecode, $wp_rewrite->rewritecode );
     76        $this->assertSameSets( array_merge( $this->rewritereplace, array( 'bar' ) ), $wp_rewrite->rewritereplace );
     77        $this->assertSameSets( array_merge( $this->queryreplace, array( 'baz=' ) ), $wp_rewrite->queryreplace );
    7878    }
    7979
     
    9595        $rewritecode[] = '%foo%';
    9696        add_rewrite_tag( '%foo%', 'bar', 'baz=' );
    97         $this->assertEqualSets( $rewritecode, $wp_rewrite->rewritecode );
    98         $this->assertEqualSets( array_merge( $this->rewritereplace, array( 'bar' ) ), $wp_rewrite->rewritereplace );
    99         $this->assertEqualSets( array_merge( $this->queryreplace, array( 'baz=' ) ), $wp_rewrite->queryreplace );
     97        $this->assertSameSets( $rewritecode, $wp_rewrite->rewritecode );
     98        $this->assertSameSets( array_merge( $this->rewritereplace, array( 'bar' ) ), $wp_rewrite->rewritereplace );
     99        $this->assertSameSets( array_merge( $this->queryreplace, array( 'baz=' ) ), $wp_rewrite->queryreplace );
    100100
    101101        remove_rewrite_tag( '%foo%' );
    102         $this->assertEqualSets( $this->rewritecode, $wp_rewrite->rewritecode );
    103         $this->assertEqualSets( $this->rewritereplace, $wp_rewrite->rewritereplace );
    104         $this->assertEqualSets( $this->queryreplace, $wp_rewrite->queryreplace );
     102        $this->assertSameSets( $this->rewritecode, $wp_rewrite->rewritecode );
     103        $this->assertSameSets( $this->rewritereplace, $wp_rewrite->rewritereplace );
     104        $this->assertSameSets( $this->queryreplace, $wp_rewrite->queryreplace );
    105105    }
    106106
     
    127127        $rewritereplace[] = '([0-9]{1,2})';
    128128        add_rewrite_tag( '%foo%', '([0-9]{1,2})', 'post_type=foo&name=' );
    129         $this->assertEqualSets( $rewritecode, $wp_rewrite->rewritecode );
    130         $this->assertEqualSets( $rewritereplace, $wp_rewrite->rewritereplace );
    131         $this->assertEqualSets( array_merge( $this->queryreplace, array( 'post_type=foo&name=' ) ), $wp_rewrite->queryreplace );
     129        $this->assertSameSets( $rewritecode, $wp_rewrite->rewritecode );
     130        $this->assertSameSets( $rewritereplace, $wp_rewrite->rewritereplace );
     131        $this->assertSameSets( array_merge( $this->queryreplace, array( 'post_type=foo&name=' ) ), $wp_rewrite->queryreplace );
    132132
    133133        remove_rewrite_tag( '%foo%' );
    134         $this->assertEqualSets( $this->rewritecode, $wp_rewrite->rewritecode );
    135         $this->assertEqualSets( $this->rewritereplace, $wp_rewrite->rewritereplace );
    136         $this->assertEqualSets( $this->queryreplace, $wp_rewrite->queryreplace );
     134        $this->assertSameSets( $this->rewritecode, $wp_rewrite->rewritecode );
     135        $this->assertSameSets( $this->rewritereplace, $wp_rewrite->rewritereplace );
     136        $this->assertSameSets( $this->queryreplace, $wp_rewrite->queryreplace );
    137137
    138138        $this->assertNotContains( '%foo%', $wp_rewrite->rewritecode );
Note: See TracChangeset for help on using the changeset viewer.