WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (17 months ago)
Author:
SergeyBiryukov
Message:

Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests.

This ensures that not only the return values match the expected results, but also that their type is the same.

Going forward, stricter type checking by using assertSame() should generally be preferred to assertEquals() where appropriate, to make the tests more reliable.

Props johnbillion, jrf, SergeyBiryukov.
See #38266.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/query/taxQuery.php

    r47122 r48937  
    3434        );
    3535
    36         $this->assertEquals( array( $p1 ), $q->posts );
     36        $this->assertSame( array( $p1 ), $q->posts );
    3737    }
    3838
     
    6565        );
    6666
    67         $this->assertEquals( array( $p1 ), $q->posts );
     67        $this->assertSame( array( $p1 ), $q->posts );
    6868    }
    6969
     
    9999        );
    100100
    101         $this->assertEquals( array( $p1 ), $q->posts );
     101        $this->assertSame( array( $p1 ), $q->posts );
    102102    }
    103103
     
    130130        );
    131131
    132         $this->assertEquals( array( $p1 ), $q->posts );
     132        $this->assertSame( array( $p1 ), $q->posts );
    133133    }
    134134
     
    161161        );
    162162
    163         $this->assertEquals( array( $p1 ), $q->posts );
     163        $this->assertSame( array( $p1 ), $q->posts );
    164164    }
    165165
     
    193193        );
    194194
    195         $this->assertEquals( array( $p1 ), $q->posts );
     195        $this->assertSame( array( $p1 ), $q->posts );
    196196    }
    197197
     
    225225        );
    226226
    227         $this->assertEquals( array( $p2 ), $q->posts );
     227        $this->assertSame( array( $p2 ), $q->posts );
    228228    }
    229229
     
    257257        );
    258258
    259         $this->assertEquals( array( $p1 ), $q->posts );
     259        $this->assertSame( array( $p1 ), $q->posts );
    260260    }
    261261
     
    339339        );
    340340
    341         $this->assertEquals( array( $p3 ), $q->posts );
     341        $this->assertSame( array( $p3 ), $q->posts );
    342342    }
    343343
     
    390390        );
    391391
    392         $this->assertEquals( array( $p3 ), $q->posts );
     392        $this->assertSame( array( $p3 ), $q->posts );
    393393    }
    394394
     
    431431        );
    432432
    433         $this->assertEquals( array( $p2 ), $q->posts );
     433        $this->assertSame( array( $p2 ), $q->posts );
    434434    }
    435435
     
    660660        );
    661661
    662         $this->assertEquals( array( $p2 ), $q->posts );
     662        $this->assertSame( array( $p2 ), $q->posts );
    663663    }
    664664
     
    10261026
    10271027        $posts = $query->get_posts();
    1028         $this->assertEquals( 0, count( $posts ) );
     1028        $this->assertSame( 0, count( $posts ) );
    10291029    }
    10301030
     
    10611061
    10621062        $posts = $query->get_posts();
    1063         $this->assertEquals( 0, count( $posts ) );
     1063        $this->assertSame( 0, count( $posts ) );
    10641064    }
    10651065
     
    11131113        );
    11141114
    1115         $this->assertEquals( 4, count( $posts ) );
     1115        $this->assertSame( 4, count( $posts ) );
    11161116
    11171117        $posts = get_posts(
     
    11311131        );
    11321132
    1133         $this->assertEquals( 1, count( $posts ) );
     1133        $this->assertSame( 1, count( $posts ) );
    11341134
    11351135        $posts = get_posts(
     
    11481148        );
    11491149
    1150         $this->assertEquals( 3, count( $posts ) );
     1150        $this->assertSame( 3, count( $posts ) );
    11511151
    11521152        $posts = get_posts(
     
    11661166        );
    11671167
    1168         $this->assertEquals( 1, count( $posts ) );
     1168        $this->assertSame( 1, count( $posts ) );
    11691169
    11701170        $posts = get_posts(
     
    11831183        );
    11841184
    1185         $this->assertEquals( 1, count( $posts ) );
     1185        $this->assertSame( 1, count( $posts ) );
    11861186
    11871187        $posts = get_posts(
     
    12011201        );
    12021202
    1203         $this->assertEquals( 1, count( $posts ) );
     1203        $this->assertSame( 1, count( $posts ) );
    12041204    }
    12051205
     
    12411241        );
    12421242
    1243         $this->assertEquals( array( $image_id ), $posts );
     1243        $this->assertSame( array( $image_id ), $posts );
    12441244    }
    12451245
     
    13461346        );
    13471347
    1348         $this->assertEquals( array( $posts[0], $posts[1], $posts[2] ), $results1, 'Relation: OR; Operator: AND' );
     1348        $this->assertSame( array( $posts[0], $posts[1], $posts[2] ), $results1, 'Relation: OR; Operator: AND' );
    13491349
    13501350        $results2 = $q->query(
     
    13731373        );
    13741374
    1375         $this->assertEquals( array( $posts[0], $posts[3] ), $results2, 'Relation: AND; Operator: IN' );
     1375        $this->assertSame( array( $posts[0], $posts[3] ), $results2, 'Relation: AND; Operator: IN' );
    13761376    }
    13771377
     
    14941494        );
    14951495
    1496         $this->assertEquals( $t, $q->get( 'term_id' ) );
     1496        $this->assertSame( $t, $q->get( 'term_id' ) );
    14971497
    14981498        _unregister_taxonomy( 'foo' );
     
    15401540        );
    15411541
    1542         $this->assertEquals( $c, $q->get( 'cat' ) );
    1543         $this->assertEquals( 'bar', $q->get( 'category_name' ) );
     1542        $this->assertSame( $c, $q->get( 'cat' ) );
     1543        $this->assertSame( 'bar', $q->get( 'category_name' ) );
    15441544
    15451545        _unregister_taxonomy( 'foo' );
     
    15871587        );
    15881588
    1589         $this->assertEquals( $tag, $q->get( 'tag_id' ) );
     1589        $this->assertSame( $tag, $q->get( 'tag_id' ) );
    15901590
    15911591        _unregister_taxonomy( 'foo' );
Note: See TracChangeset for help on using the changeset viewer.