Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (6 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/editorGd.php

    r47198 r48937  
    3535        public function test_supports_mime_type_jpeg() {
    3636                $gd_image_editor = new WP_Image_Editor_GD( null );
    37                 $expected        = imagetypes() & IMG_JPG;
    38                 $this->assertEquals( $expected, $gd_image_editor->supports_mime_type( 'image/jpeg' ) );
     37                $expected        = (bool) ( imagetypes() & IMG_JPG );
     38                $this->assertSame( $expected, $gd_image_editor->supports_mime_type( 'image/jpeg' ) );
    3939        }
    4040
    4141        public function test_supports_mime_type_png() {
    4242                $gd_image_editor = new WP_Image_Editor_GD( null );
    43                 $expected        = imagetypes() & IMG_PNG;
    44                 $this->assertEquals( $expected, $gd_image_editor->supports_mime_type( 'image/png' ) );
     43                $expected        = (bool) ( imagetypes() & IMG_PNG );
     44                $this->assertSame( $expected, $gd_image_editor->supports_mime_type( 'image/png' ) );
    4545        }
    4646
    4747        public function test_supports_mime_type_gif() {
    4848                $gd_image_editor = new WP_Image_Editor_GD( null );
    49                 $expected        = imagetypes() & IMG_GIF;
    50                 $this->assertEquals( $expected, $gd_image_editor->supports_mime_type( 'image/gif' ) );
     49                $expected        = (bool) ( imagetypes() & IMG_GIF );
     50                $this->assertSame( $expected, $gd_image_editor->supports_mime_type( 'image/gif' ) );
    5151        }
    5252
     
    6262                $gd_image_editor->resize( 100, 50 );
    6363
    64                 $this->assertEquals(
     64                $this->assertSame(
    6565                        array(
    6666                                'width'  => 75,
     
    9999                );
    100100
    101                 $this->assertEquals( $expected_array, $resized );
     101                $this->assertSame( $expected_array, $resized );
    102102
    103103                // Now, verify real dimensions are as expected.
     
    371371
    372372                $this->assertNotNull( $resized );
    373                 $this->assertEquals( $expected_array, $resized );
     373                $this->assertSame( $expected_array, $resized );
    374374
    375375                foreach ( $resized as $key => $image_data ) {
     
    396396                $gd_image_editor->resize( 100, 50, true );
    397397
    398                 $this->assertEquals(
     398                $this->assertSame(
    399399                        array(
    400400                                'width'  => 100,
     
    416416                $gd_image_editor->crop( 0, 0, 50, 50 );
    417417
    418                 $this->assertEquals(
     418                $this->assertSame(
    419419                        array(
    420420                                'width'  => 50,
     
    441441                $gd_image_editor->rotate( 180 );
    442442
    443                 $this->assertEquals( $color_top_left, imagecolorat( $property->getValue( $gd_image_editor ), 99, 99 ) );
     443                $this->assertSame( $color_top_left, imagecolorat( $property->getValue( $gd_image_editor ), 99, 99 ) );
    444444        }
    445445
     
    460460                $gd_image_editor->flip( true, false );
    461461
    462                 $this->assertEquals( $color_top_left, imagecolorat( $property->getValue( $gd_image_editor ), 0, 99 ) );
     462                $this->assertSame( $color_top_left, imagecolorat( $property->getValue( $gd_image_editor ), 0, 99 ) );
    463463        }
    464464
Note: See TracChangeset for help on using the changeset viewer.