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/http/base.php

    r47122 r48937  
    5858        $this->skipTestOnTimeout( $res );
    5959        $this->assertNotWPError( $res );
    60         $this->assertEquals( 200, (int) $res['response']['code'] );
     60        $this->assertSame( 200, (int) $res['response']['code'] );
    6161    }
    6262
     
    6767        $this->skipTestOnTimeout( $res );
    6868        $this->assertNotWPError( $res );
    69         $this->assertEquals( 200, (int) $res['response']['code'] );
     69        $this->assertSame( 200, (int) $res['response']['code'] );
    7070    }
    7171
     
    7979        $this->skipTestOnTimeout( $res );
    8080        $this->assertNotWPError( $res );
    81         $this->assertEquals( 301, (int) $res['response']['code'] );
     81        $this->assertSame( 301, (int) $res['response']['code'] );
    8282    }
    8383
     
    9191        $this->skipTestOnTimeout( $res );
    9292        $this->assertNotWPError( $res );
    93         $this->assertEquals( 302, (int) $res['response']['code'] );
     93        $this->assertSame( 302, (int) $res['response']['code'] );
    9494    }
    9595
     
    100100        $this->skipTestOnTimeout( $res );
    101101        $this->assertNotWPError( $res );
    102         $this->assertEquals( 200, (int) $res['response']['code'] );
     102        $this->assertSame( 200, (int) $res['response']['code'] );
    103103    }
    104104
     
    109109        $this->skipTestOnTimeout( $res );
    110110        $this->assertNotWPError( $res );
    111         $this->assertEquals( 302, (int) $res['response']['code'] );
     111        $this->assertSame( 302, (int) $res['response']['code'] );
    112112    }
    113113
     
    127127        $this->skipTestOnTimeout( $res );
    128128        $this->assertNotWPError( $res );
    129         $this->assertEquals( 200, (int) $res['response']['code'] );
     129        $this->assertSame( 200, (int) $res['response']['code'] );
    130130    }
    131131
     
    163163        $this->skipTestOnTimeout( $res );
    164164        $this->assertNotWPError( $res );
    165         $this->assertEquals( 302, (int) $res['response']['code'] );
     165        $this->assertSame( 302, (int) $res['response']['code'] );
    166166    }
    167167
     
    177177        $this->skipTestOnTimeout( $res );
    178178        $this->assertNotWPError( $res );
    179         $this->assertEquals( 'PASS', $res['body'] );
     179        $this->assertSame( 'PASS', $res['body'] );
    180180    }
    181181
     
    198198
    199199        $this->skipTestOnTimeout( $res );
    200         $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
     200        $this->assertSame( 'PASS', wp_remote_retrieve_body( $res ) );
    201201        $this->assertTrue( ! empty( $res['headers']['location'] ) );
    202202    }
     
    253253        $this->skipTestOnTimeout( $res );
    254254        $this->assertNotWPError( $res );
    255         $this->assertEquals( '', $res['body'] ); // The body should be empty.
     255        $this->assertSame( '', $res['body'] ); // The body should be empty.
    256256        $this->assertEquals( $size, $res['headers']['content-length'] );   // Check the headers are returned (and the size is the same).
    257         $this->assertEquals( $size, $filesize ); // Check that the file is written to disk correctly without any extra characters.
     257        $this->assertSame( $size, $filesize ); // Check that the file is written to disk correctly without any extra characters.
    258258        $this->assertStringStartsWith( get_temp_dir(), $res['filename'] ); // Check it's saving within the temp directory.
    259259    }
     
    282282        $this->skipTestOnTimeout( $res );
    283283        $this->assertNotWPError( $res );
    284         $this->assertEquals( $size, $filesize ); // Check that the file is written to disk correctly without any extra characters.
     284        $this->assertSame( $size, $filesize ); // Check that the file is written to disk correctly without any extra characters.
    285285
    286286    }
     
    305305        $this->skipTestOnTimeout( $res );
    306306        $this->assertNotWPError( $res );
    307         $this->assertEquals( $size, strlen( $res['body'] ) );
     307        $this->assertSame( $size, strlen( $res['body'] ) );
    308308    }
    309309
     
    321321
    322322        $this->skipTestOnTimeout( $res );
    323         $this->assertEquals( $method, wp_remote_retrieve_body( $res ) );
     323        $this->assertSame( $method, wp_remote_retrieve_body( $res ) );
    324324    }
    325325
     
    368368
    369369        $this->skipTestOnTimeout( $res );
    370         $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
     370        $this->assertSame( 'PASS', wp_remote_retrieve_body( $res ) );
    371371
    372372    }
     
    410410
    411411        $this->skipTestOnTimeout( $res );
    412         $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
     412        $this->assertSame( 'PASS', wp_remote_retrieve_body( $res ) );
    413413
    414414    }
     
    425425
    426426        $this->skipTestOnTimeout( $res );
    427         $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) );
     427        $this->assertSame( 'PASS', wp_remote_retrieve_body( $res ) );
    428428    }
    429429
Note: See TracChangeset for help on using the changeset viewer.