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/image/meta.php

    r48221 r48937  
    2323
    2424        $this->assertEquals( 6.3, $out['aperture'] );
    25         $this->assertEquals( '', $out['credit'] );
    26         $this->assertEquals( 'NIKON D70', $out['camera'] );
    27         $this->assertEquals( '', $out['caption'] );
     25        $this->assertSame( '', $out['credit'] );
     26        $this->assertSame( 'NIKON D70', $out['camera'] );
     27        $this->assertSame( '', $out['caption'] );
    2828        $this->assertEquals( strtotime( '2004-07-22 17:14:59' ), $out['created_timestamp'] );
    29         $this->assertEquals( '', $out['copyright'] );
     29        $this->assertSame( '', $out['copyright'] );
    3030        $this->assertEquals( 27, $out['focal_length'] );
    3131        $this->assertEquals( 400, $out['iso'] );
    3232        $this->assertEquals( 1 / 40, $out['shutter_speed'] );
    33         $this->assertEquals( '', $out['title'] );
     33        $this->assertSame( '', $out['title'] );
    3434    }
    3535
     
    3838        $out = wp_read_image_metadata( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG' );
    3939
    40         $this->assertEquals( 0, $out['aperture'] );
    41         $this->assertEquals( '', $out['credit'] );
    42         $this->assertEquals( 'NIKON D70', $out['camera'] );
    43         $this->assertEquals( '', $out['caption'] );
     40        $this->assertSame( '0', $out['aperture'] );
     41        $this->assertSame( '', $out['credit'] );
     42        $this->assertSame( 'NIKON D70', $out['camera'] );
     43        $this->assertSame( '', $out['caption'] );
    4444        $this->assertEquals( strtotime( '2007-06-17 21:18:00' ), $out['created_timestamp'] );
    45         $this->assertEquals( '', $out['copyright'] );
     45        $this->assertSame( '', $out['copyright'] );
    4646        $this->assertEquals( 0, $out['focal_length'] );
    4747        $this->assertEquals( 0, $out['iso'] ); // Interesting - a Nikon bug?
    4848        $this->assertEquals( 1 / 500, $out['shutter_speed'] );
    49         $this->assertEquals( '', $out['title'] );
    50         // $this->assertEquals( array( 'Flowers' ), $out['keywords'] );
     49        $this->assertSame( '', $out['title'] );
     50        // $this->assertSame( array( 'Flowers' ), $out['keywords'] );
    5151    }
    5252
     
    5656
    5757        $this->assertEquals( 6.3, $out['aperture'] );
    58         $this->assertEquals( 'IPTC Creator', $out['credit'] );
    59         $this->assertEquals( 'NIKON D70', $out['camera'] );
    60         $this->assertEquals( 'IPTC Caption', $out['caption'] );
     58        $this->assertSame( 'IPTC Creator', $out['credit'] );
     59        $this->assertSame( 'NIKON D70', $out['camera'] );
     60        $this->assertSame( 'IPTC Caption', $out['caption'] );
    6161        $this->assertEquals( strtotime( '2004-07-22 17:14:35' ), $out['created_timestamp'] );
    62         $this->assertEquals( 'IPTC Copyright', $out['copyright'] );
     62        $this->assertSame( 'IPTC Copyright', $out['copyright'] );
    6363        $this->assertEquals( 18, $out['focal_length'] );
    6464        $this->assertEquals( 200, $out['iso'] );
    6565        $this->assertEquals( 1 / 25, $out['shutter_speed'] );
    66         $this->assertEquals( 'IPTC Headline', $out['title'] );
     66        $this->assertSame( 'IPTC Headline', $out['title'] );
    6767    }
    6868
     
    7272
    7373        $this->assertEquals( 4.5, $out['aperture'] );
    74         $this->assertEquals( '', $out['credit'] );
    75         $this->assertEquals( 'FinePix S5600', $out['camera'] );
    76         $this->assertEquals( '', $out['caption'] );
     74        $this->assertSame( '', $out['credit'] );
     75        $this->assertSame( 'FinePix S5600', $out['camera'] );
     76        $this->assertSame( '', $out['caption'] );
    7777        $this->assertEquals( strtotime( '2007-09-03 10:17:03' ), $out['created_timestamp'] );
    78         $this->assertEquals( '', $out['copyright'] );
     78        $this->assertSame( '', $out['copyright'] );
    7979        $this->assertEquals( 6.3, $out['focal_length'] );
    8080        $this->assertEquals( 64, $out['iso'] );
    8181        $this->assertEquals( 1 / 320, $out['shutter_speed'] );
    82         $this->assertEquals( '', $out['title'] );
     82        $this->assertSame( '', $out['title'] );
    8383
    8484    }
     
    9393
    9494        $this->assertEquals( 0, $out['aperture'] );
    95         $this->assertEquals( '', $out['credit'] );
    96         $this->assertEquals( '', $out['camera'] );
    97         $this->assertEquals( '', $out['caption'] );
     95        $this->assertSame( '', $out['credit'] );
     96        $this->assertSame( '', $out['camera'] );
     97        $this->assertSame( '', $out['caption'] );
    9898        $this->assertEquals( 0, $out['created_timestamp'] );
    99         $this->assertEquals( '', $out['copyright'] );
     99        $this->assertSame( '', $out['copyright'] );
    100100        $this->assertEquals( 0, $out['focal_length'] );
    101101        $this->assertEquals( 0, $out['iso'] );
    102102        $this->assertEquals( 0, $out['shutter_speed'] );
    103         $this->assertEquals( '', $out['title'] );
     103        $this->assertSame( '', $out['title'] );
    104104    }
    105105
     
    109109
    110110        $this->assertEquals( 0, $out['aperture'] );
    111         $this->assertEquals( '', $out['credit'] );
    112         $this->assertEquals( '', $out['camera'] );
    113         $this->assertEquals( '', $out['caption'] );
     111        $this->assertSame( '', $out['credit'] );
     112        $this->assertSame( '', $out['camera'] );
     113        $this->assertSame( '', $out['caption'] );
    114114        $this->assertEquals( 0, $out['created_timestamp'] );
    115         $this->assertEquals( '', $out['copyright'] );
     115        $this->assertSame( '', $out['copyright'] );
    116116        $this->assertEquals( 0, $out['focal_length'] );
    117117        $this->assertEquals( 0, $out['iso'] );
    118118        $this->assertEquals( 0, $out['shutter_speed'] );
    119         $this->assertEquals( '', $out['title'] );
     119        $this->assertSame( '', $out['title'] );
    120120    }
    121121
     
    127127        $out = wp_read_image_metadata( DIR_TESTDATA . '/images/test-image-iptc.jpg' );
    128128
    129         $this->assertEquals( 'This is a comment. / Это комментарий. / Βλέπετε ένα σχόλιο.', $out['caption'] );
     129        $this->assertSame( 'This is a comment. / Это комментарий. / Βλέπετε ένα σχόλιο.', $out['caption'] );
    130130    }
    131131
     
    145145        $out = wp_read_image_metadata( DIR_TESTDATA . '/images/33772.jpg' );
    146146
    147         $this->assertEquals( '8', $out['aperture'] );
    148         $this->assertEquals( 'Photoshop Author', $out['credit'] );
    149         $this->assertEquals( 'DMC-LX2', $out['camera'] );
    150         $this->assertEquals( 'Photoshop Description', $out['caption'] );
     147        $this->assertSame( '8', $out['aperture'] );
     148        $this->assertSame( 'Photoshop Author', $out['credit'] );
     149        $this->assertSame( 'DMC-LX2', $out['camera'] );
     150        $this->assertSame( 'Photoshop Description', $out['caption'] );
    151151        $this->assertEquals( 1306315327, $out['created_timestamp'] );
    152         $this->assertEquals( 'Photoshop Copyrright Notice', $out['copyright'] );
    153         $this->assertEquals( '6.3', $out['focal_length'] );
    154         $this->assertEquals( '100', $out['iso'] );
    155         $this->assertEquals( '0.0025', $out['shutter_speed'] );
    156         $this->assertEquals( 'Photoshop Document Ttitle', $out['title'] );
     152        $this->assertSame( 'Photoshop Copyrright Notice', $out['copyright'] );
     153        $this->assertSame( '6.3', $out['focal_length'] );
     154        $this->assertSame( '100', $out['iso'] );
     155        $this->assertSame( '0.0025', $out['shutter_speed'] );
     156        $this->assertSame( 'Photoshop Document Ttitle', $out['title'] );
    157157        $this->assertEquals( 1, $out['orientation'] );
    158         $this->assertEquals( array( 'beach', 'baywatch', 'LA', 'sunset' ), $out['keywords'] );
     158        $this->assertSame( array( 'beach', 'baywatch', 'LA', 'sunset' ), $out['keywords'] );
    159159    }
    160160
Note: See TracChangeset for help on using the changeset viewer.