Make WordPress Core


Ignore:
Timestamp:
11/07/2020 01:18:24 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Build/Test Tools: Check if all the required PHP extensions are loaded before running the test suite.

Add the GD extension as a hard requirement.

This improves the reliability of the test suite and ensures that if the test infrastructure changes in the future and a platform requirement such as GD accidentally gets removed, the tests fail with an appropriate error message.

Follow-up to [48592].

Props ayeshrajans, jrf, johnbillion.
Fixes #50640.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/bootstrap.php

    r49491 r49535  
    3838require_once __DIR__ . '/functions.php';
    3939
     40if ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS && ! is_dir( ABSPATH ) ) {
     41    echo "Error: The /build/ directory is missing! Please run `npm run build` prior to running PHPUnit.\n";
     42    exit( 1 );
     43}
     44
    4045$phpunit_version = tests_get_phpunit_version();
    4146
     
    4954}
    5055
    51 if ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS && ! is_dir( ABSPATH ) ) {
    52     echo "Error: The /build/ directory is missing! Please run `npm run build` prior to running PHPUnit.\n";
     56$required_extensions = array(
     57    'gd',
     58);
     59$missing_extensions  = array();
     60
     61foreach ( $required_extensions as $extension ) {
     62    if ( ! extension_loaded( $extension ) ) {
     63        $missing_extensions[] = $extension;
     64    }
     65}
     66
     67if ( $missing_extensions ) {
     68    printf(
     69        "Error: The following required PHP extensions are missing from the testing environment: %s.\n",
     70        implode( ', ', $missing_extensions )
     71    );
     72    echo "Please make sure they are installed and enabled.\n",
    5373    exit( 1 );
    5474}
     
    6080    'WP_PHP_BINARY',
    6181);
     82$missing_constants  = array();
    6283
    6384foreach ( $required_constants as $constant ) {
    6485    if ( ! defined( $constant ) ) {
    65         printf(
    66             "Error: The required %s constant is not defined. Check out `wp-tests-config-sample.php` for an example.\n",
    67             $constant
    68         );
    69         exit( 1 );
    70     }
     86        $missing_constants[] = $constant;
     87    }
     88}
     89
     90if ( $missing_constants ) {
     91    printf(
     92        "Error: The following required constants are not defined: %s.\n",
     93        implode( ', ', $missing_constants )
     94    );
     95    echo "Please check out `wp-tests-config-sample.php` for an example.\n",
     96    exit( 1 );
    7197}
    7298
Note: See TracChangeset for help on using the changeset viewer.