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/term/query.php

    r48937 r48939  
    2323        );
    2424
    25         $this->assertEqualSets( array( $term_2 ), $q->terms );
     25        $this->assertSameSets( array( $term_2 ), $q->terms );
    2626    }
    2727
     
    4141        );
    4242
    43         $this->assertEqualSets( array( $term_2 ), $q->terms );
     43        $this->assertSameSets( array( $term_2 ), $q->terms );
    4444    }
    4545
     
    6969        );
    7070
    71         $this->assertEqualSets( array( $terms[0] ), $q->terms );
     71        $this->assertSameSets( array( $terms[0] ), $q->terms );
    7272    }
    7373
     
    103103        );
    104104
    105         $this->assertEqualSets( array( $terms[0], $terms[2] ), $q->terms );
     105        $this->assertSameSets( array( $terms[0], $terms[2] ), $q->terms );
    106106    }
    107107
     
    244244        );
    245245
    246         $this->assertEqualSets( array( $t ), $query->terms );
     246        $this->assertSameSets( array( $t ), $query->terms );
    247247    }
    248248
     
    266266        );
    267267
    268         $this->assertEqualSets( array( $t ), $query->terms );
     268        $this->assertSameSets( array( $t ), $query->terms );
    269269    }
    270270
     
    375375        $found = $query->get_terms();
    376376
    377         $this->assertEqualSets( array( $terms[0] ), $found );
     377        $this->assertSameSets( array( $terms[0] ), $found );
    378378
    379379        wp_set_object_terms( $p, array( $terms[1] ), 'wptests_tax_1' );
     
    388388        $found = $query->get_terms();
    389389
    390         $this->assertEqualSets( array( $terms[1] ), $found );
     390        $this->assertSameSets( array( $terms[1] ), $found );
    391391    }
    392392
     
    691691        $expected = array( $terms[0], $terms[2] );
    692692
    693         $this->assertEqualSets( $expected, wp_list_pluck( $found, 'term_id' ) );
     693        $this->assertSameSets( $expected, wp_list_pluck( $found, 'term_id' ) );
    694694    }
    695695
     
    728728        $expected = array( $terms[0], $terms[2] );
    729729
    730         $this->assertEqualSets( $expected, wp_list_pluck( $found, 'term_id' ) );
     730        $this->assertSameSets( $expected, wp_list_pluck( $found, 'term_id' ) );
    731731    }
    732732
Note: See TracChangeset for help on using the changeset viewer.