Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (4 years 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/image/resize.php

    r47198 r48937  
    3030        $image = $this->resize_helper( DIR_TESTDATA . '/images/test-image.jpg', 25, 25 );
    3131
    32         $this->assertEquals( 'test-image-25x25.jpg', wp_basename( $image ) );
     32        $this->assertSame( 'test-image-25x25.jpg', wp_basename( $image ) );
    3333        list($w, $h, $type) = getimagesize( $image );
    34         $this->assertEquals( 25, $w );
    35         $this->assertEquals( 25, $h );
    36         $this->assertEquals( IMAGETYPE_JPEG, $type );
     34        $this->assertSame( 25, $w );
     35        $this->assertSame( 25, $h );
     36        $this->assertSame( IMAGETYPE_JPEG, $type );
    3737
    3838        unlink( $image );
     
    4646        }
    4747
    48         $this->assertEquals( 'test-image-25x25.png', wp_basename( $image ) );
     48        $this->assertSame( 'test-image-25x25.png', wp_basename( $image ) );
    4949        list($w, $h, $type) = getimagesize( $image );
    50         $this->assertEquals( 25, $w );
    51         $this->assertEquals( 25, $h );
    52         $this->assertEquals( IMAGETYPE_PNG, $type );
     50        $this->assertSame( 25, $w );
     51        $this->assertSame( 25, $h );
     52        $this->assertSame( IMAGETYPE_PNG, $type );
    5353
    5454        unlink( $image );
     
    6262        }
    6363
    64         $this->assertEquals( 'test-image-25x25.gif', wp_basename( $image ) );
     64        $this->assertSame( 'test-image-25x25.gif', wp_basename( $image ) );
    6565        list($w, $h, $type) = getimagesize( $image );
    66         $this->assertEquals( 25, $w );
    67         $this->assertEquals( 25, $h );
    68         $this->assertEquals( IMAGETYPE_GIF, $type );
     66        $this->assertSame( 25, $w );
     67        $this->assertSame( 25, $h );
     68        $this->assertSame( IMAGETYPE_GIF, $type );
    6969
    7070        unlink( $image );
     
    7676
    7777        $this->assertInstanceOf( 'WP_Error', $image );
    78         $this->assertEquals( 'error_getting_dimensions', $image->get_error_code() );
     78        $this->assertSame( 'error_getting_dimensions', $image->get_error_code() );
    7979    }
    8080
     
    8282        $image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 128, 96 );
    8383
    84         $this->assertEquals( '2007-06-17DSC_4173-64x96.jpg', wp_basename( $image ) );
     84        $this->assertSame( '2007-06-17DSC_4173-64x96.jpg', wp_basename( $image ) );
    8585        list($w, $h, $type) = getimagesize( $image );
    86         $this->assertEquals( 64, $w );
    87         $this->assertEquals( 96, $h );
    88         $this->assertEquals( IMAGETYPE_JPEG, $type );
     86        $this->assertSame( 64, $w );
     87        $this->assertSame( 96, $h );
     88        $this->assertSame( IMAGETYPE_JPEG, $type );
    8989
    9090        unlink( $image );
     
    9494        $image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 128, 0 );
    9595
    96         $this->assertEquals( '2007-06-17DSC_4173-128x193.jpg', wp_basename( $image ) );
     96        $this->assertSame( '2007-06-17DSC_4173-128x193.jpg', wp_basename( $image ) );
    9797        list($w, $h, $type) = getimagesize( $image );
    98         $this->assertEquals( 128, $w );
    99         $this->assertEquals( 193, $h );
    100         $this->assertEquals( IMAGETYPE_JPEG, $type );
     98        $this->assertSame( 128, $w );
     99        $this->assertSame( 193, $h );
     100        $this->assertSame( IMAGETYPE_JPEG, $type );
    101101
    102102        unlink( $image );
     
    106106        $image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 0, 96 );
    107107
    108         $this->assertEquals( '2007-06-17DSC_4173-64x96.jpg', wp_basename( $image ) );
     108        $this->assertSame( '2007-06-17DSC_4173-64x96.jpg', wp_basename( $image ) );
    109109        list($w, $h, $type) = getimagesize( $image );
    110         $this->assertEquals( 64, $w );
    111         $this->assertEquals( 96, $h );
    112         $this->assertEquals( IMAGETYPE_JPEG, $type );
     110        $this->assertSame( 64, $w );
     111        $this->assertSame( 96, $h );
     112        $this->assertSame( IMAGETYPE_JPEG, $type );
    113113
    114114        unlink( $image );
     
    118118        $image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 150, 150, true );
    119119
    120         $this->assertEquals( '2007-06-17DSC_4173-150x150.jpg', wp_basename( $image ) );
     120        $this->assertSame( '2007-06-17DSC_4173-150x150.jpg', wp_basename( $image ) );
    121121        list($w, $h, $type) = getimagesize( $image );
    122         $this->assertEquals( 150, $w );
    123         $this->assertEquals( 150, $h );
    124         $this->assertEquals( IMAGETYPE_JPEG, $type );
     122        $this->assertSame( 150, $w );
     123        $this->assertSame( 150, $h );
     124        $this->assertSame( IMAGETYPE_JPEG, $type );
    125125
    126126        unlink( $image );
     
    130130        $image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 150, 100, true );
    131131
    132         $this->assertEquals( '2007-06-17DSC_4173-150x100.jpg', wp_basename( $image ) );
     132        $this->assertSame( '2007-06-17DSC_4173-150x100.jpg', wp_basename( $image ) );
    133133        list($w, $h, $type) = getimagesize( $image );
    134         $this->assertEquals( 150, $w );
    135         $this->assertEquals( 100, $h );
    136         $this->assertEquals( IMAGETYPE_JPEG, $type );
     134        $this->assertSame( 150, $w );
     135        $this->assertSame( 100, $h );
     136        $this->assertSame( IMAGETYPE_JPEG, $type );
    137137
    138138        unlink( $image );
     
    142142        $image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 50, 150, true );
    143143
    144         $this->assertEquals( '2007-06-17DSC_4173-50x150.jpg', wp_basename( $image ) );
     144        $this->assertSame( '2007-06-17DSC_4173-50x150.jpg', wp_basename( $image ) );
    145145        list($w, $h, $type) = getimagesize( $image );
    146         $this->assertEquals( 50, $w );
    147         $this->assertEquals( 150, $h );
    148         $this->assertEquals( IMAGETYPE_JPEG, $type );
     146        $this->assertSame( 50, $w );
     147        $this->assertSame( 150, $h );
     148        $this->assertSame( IMAGETYPE_JPEG, $type );
    149149
    150150        unlink( $image );
     
    160160
    161161        $this->assertInstanceOf( 'WP_Error', $image );
    162         $this->assertEquals( 'error_loading_image', $image->get_error_code() );
     162        $this->assertSame( 'error_loading_image', $image->get_error_code() );
    163163    }
    164164
Note: See TracChangeset for help on using the changeset viewer.