WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/14/2021 06:40:30 PM (3 months ago)
Author:
hellofromTonya
Message:

Build/Test Tools: Improve messaging when PHPUnit Polyfills cannot be found.

Previously, two situations were taken in to account:

  1. The WP_TESTS_PHPUNIT_POLYFILLS_PATH constant is defined => show message specific to that constant not being set correctly.

This message would typically be shown for plugin/theme integration tests which are already aware of the changes in WP 5.9.

  1. The constant is not defined => show a message to run composer update.

This message is intended for people trying to run the WP Core tests.

This left two situations unaccounted for:

  • Someone trying to run the WP Core tests, but not having set the WP_RUN_CORE_TESTS constant or not having set it to 1.
  • Someone trying to run plugin/theme integration tests without the new WP_TESTS_PHPUNIT_POLYFILLS_PATH constant being defined as they are not (yet) aware of the changes made in WP 5.9.

The changes made in this commit, are intended to improve the error messages displayed in those situations.

Follow-up to [51598], [51810].

Props jrf, schlessera, hellofromTonya, jeherve, lucatume.
See #46149.

File:
1 edited

Legend:

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

    r51810 r51811  
    106106    if ( $phpunit_polyfills_error || ! file_exists( $phpunit_polyfills_autoloader ) ) {
    107107        echo 'Error: The PHPUnit Polyfills library is a requirement for running the WP test suite.' . PHP_EOL;
    108         if ( isset( $phpunit_polyfills_path ) ) {
     108        if ( defined( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH' ) ) {
    109109            printf(
    110110                'The PHPUnit Polyfills autoload file was not found in "%s"' . PHP_EOL,
     
    112112            );
    113113            echo 'Please verify that the file path provided in the WP_TESTS_PHPUNIT_POLYFILLS_PATH constant is correct.' . PHP_EOL;
     114        } elseif ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS ) {
     115            echo 'You need to run `composer update` before running the tests.' . PHP_EOL;
     116            echo 'Once the dependencies are installed, you can run the tests using the Composer-installed version of PHPUnit or using a PHPUnit phar file, but the dependencies do need to be installed whichever way the tests are run.' . PHP_EOL;
    114117        } else {
    115             echo 'You need to run `composer update` before running the tests.' . PHP_EOL;
     118            echo 'If you are trying to run plugin/theme integration tests, make sure the PHPUnit Polyfills library is available and either load the autoload file of this library in your own test bootstrap before calling the WP Core test bootstrap file; or set the path to the PHPUnit Polyfills library in a "WP_TESTS_PHPUNIT_POLYFILLS_PATH" constant to allow the WP Core bootstrap to load the Polyfills.' . PHP_EOL . PHP_EOL;
     119            echo 'If you are trying to run the WP Core tests, make sure to set the "WP_RUN_CORE_TESTS" constant to 1 and run `composer update` before running the tests.' . PHP_EOL;
    116120            echo 'Once the dependencies are installed, you can run the tests using the Composer-installed version of PHPUnit or using a PHPUnit phar file, but the dependencies do need to be installed whichever way the tests are run.' . PHP_EOL;
    117121        }
Note: See TracChangeset for help on using the changeset viewer.