Make WordPress Core

Changeset 53524


Ignore:
Timestamp:
06/19/2022 03:19:17 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Tests: Refactor Tests_Image_Functions::test_is_image_negative() to use a data provider.

Using a data provider has a number of advantages:

  1. If the first test case fails, it won't prevent the other test cases from being tested.
  2. While the assertion used in this test method does have a "failure message" (👍), the output from PHPUnit itself will already be more descriptive in case of failure when using a data provider.
  3. Using named test cases in the data provider will also make the --testdox output much more descriptive and informative.

The actual cases being tested, or the test itself have not been changed.

Includes:

  • Adding a @covers annotation.

Follow-up to [184/tests], [53495], [53497], [53521], [53523].

Props jrf.
See #55652.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/image/functions.php

    r53523 r53524  
    8080
    8181    /**
    82      * Data Provider.
     82     * Data provider.
    8383     *
    8484     * @return array
     
    108108    }
    109109
    110     public function test_is_image_negative() {
     110    /**
     111     * @dataProvider data_is_image_negative
     112     *
     113     * @covers ::file_is_valid_image
     114     * @covers ::wp_getimagesize
     115     *
     116     * @param string $file File name.
     117     */
     118    public function test_is_image_negative( $file ) {
     119        $this->assertFalse(
     120            file_is_valid_image( DIR_TESTDATA . '/images/' . $file ),
     121            "file_is_valid_image( '$file' ) should return false"
     122        );
     123    }
     124
     125    /**
     126     * Data provider.
     127     *
     128     * @return array
     129     */
     130    public function data_is_image_negative() {
    111131        // These are actually image files but aren't recognized or usable by PHP.
    112132        $files = array(
     
    116136        );
    117137
    118         foreach ( $files as $file ) {
    119             $this->assertFalse( file_is_valid_image( DIR_TESTDATA . '/images/' . $file ), "file_is_valid_image($file) should return false" );
    120         }
     138        return $this->text_array_to_dataprovider( $files );
    121139    }
    122140
Note: See TracChangeset for help on using the changeset viewer.