Make WordPress Core

Changeset 51813


Ignore:
Timestamp:
09/14/2021 06:52:57 PM (3 years ago)
Author:
hellofromTonya
Message:

Build/Test Tools: Expect an absolute path in WP_TESTS_PHPUNIT_POLYFILLS_PATH constant.

This commit:

  • Removes the use of realpath() to prevent issues with WSL and other virtualized filesystems.
  • Changes the logic of the Polyfill bootstrap loading to expect an absolute path, rather than a relative path to the root directory of the PHPUnit Polyfills library.
  • Adjusts the relevant inline documentation and error messages to expect an absolute path.
  • Breaks up error messages into smaller line lengths for readability.

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

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

File:
1 edited

Legend:

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

    r51812 r51813  
    6262 * The PHPUnit Polyfills are a requirement for the WP test suite.
    6363 *
     64 * For running the Core tests, the Make WordPress Core handbook contains step-by-step instructions
     65 * on how to get up and running for a variety of supported workflows:
     66 * {@link https://make.wordpress.org/core/handbook/testing/automated-testing/phpunit/#test-running-workflow-options}
     67 *
    6468 * Plugin/theme integration tests can handle this in any of the following ways:
    6569 * - When using a full WP install: run `composer update` for the WP install prior to running the tests.
    6670 * - When using a partial WP test suite install:
    67  *   - Add a `yoast/phpunit-polyfills` (dev) requirement to their own `composer.json` file.
     71 *   - Add a `yoast/phpunit-polyfills` (dev) requirement to the plugin/theme's own `composer.json` file.
    6872 *   - And then:
    6973 *     - Either load the PHPUnit Polyfills autoload file prior to running the WP core bootstrap file.
    70  *     - Or declare a `WP_TESTS_PHPUNIT_POLYFILLS_PATH` constant pointing to the root directory
    71  *       of the PHPUnit Polyfills installation.
    72  *       This constant can be declared in the `phpunit.xml[.dist]` file like this:
    73  *       `<php><const name="WP_TESTS_PHPUNIT_POLYFILLS_PATH" value="path/to/yoast/phpunit-polyfills"/></php>
    74  *       or can be declared as a PHP constant in the `wp-tests-config.php` file or the plugin/theme
    75  *       test bootstrap file.
     74 *     - Or declare a `WP_TESTS_PHPUNIT_POLYFILLS_PATH` constant containing the absolute path to the
     75 *       root directory of the PHPUnit Polyfills installation.
     76 *       If the constant is used, it is strongly recommended to declare this constant in the plugin/theme's
     77 *       own test bootstrap file.
     78 *       The constant MUST be declared prior to calling this file.
    7679 */
    7780if ( ! class_exists( 'Yoast\PHPUnitPolyfills\Autoload' ) ) {
    7881    // Default location of the autoloader for WP core test runs.
    79     $phpunit_polyfills_autoloader = __DIR__ . '/../../../vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php';
     82    $phpunit_polyfills_autoloader = dirname( dirname( dirname( __DIR__ ) ) ) . '/vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php';
    8083    $phpunit_polyfills_error      = false;
    8184
     
    9396            }
    9497
    95             $phpunit_polyfills_path = realpath( $phpunit_polyfills_path );
    96             if ( false !== $phpunit_polyfills_path ) {
    97                 $phpunit_polyfills_autoloader = $phpunit_polyfills_path;
    98             } else {
    99                 $phpunit_polyfills_error = true;
    100             }
     98            $phpunit_polyfills_autoloader = $phpunit_polyfills_path;
    10199        } else {
    102100            $phpunit_polyfills_error = true;
     
    112110            );
    113111            echo 'Please verify that the file path provided in the WP_TESTS_PHPUNIT_POLYFILLS_PATH constant is correct.' . PHP_EOL;
     112            echo 'The WP_TESTS_PHPUNIT_POLYFILLS_PATH constant should contain an absolute path to the root directory'
     113                . ' of the PHPUnit Polyfills library.' . PHP_EOL;
    114114        } elseif ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS ) {
    115115            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;
     116            echo 'Once the dependencies are installed, you can run the tests using the Composer-installed version'
     117                . ' of PHPUnit or using a PHPUnit phar file, but the dependencies do need to be installed'
     118                . ' whichever way the tests are run.' . PHP_EOL;
    117119        } else {
    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;
    120             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;
     120            echo 'If you are trying to run plugin/theme integration tests, make sure the PHPUnit Polyfills library'
     121                . ' (https://github.com/Yoast/PHPUnit-Polyfills) is available and either load the autoload file'
     122                . ' of this library in your own test bootstrap before calling the WP Core test bootstrap file;'
     123                . ' or set the absolute path to the PHPUnit Polyfills library in a "WP_TESTS_PHPUNIT_POLYFILLS_PATH"'
     124                . ' constant to allow the WP Core bootstrap to load the Polyfills.' . PHP_EOL . PHP_EOL;
     125            echo 'If you are trying to run the WP Core tests, make sure to set the "WP_RUN_CORE_TESTS" constant'
     126                . ' to 1 and run `composer update` before running the tests.' . PHP_EOL;
     127            echo 'Once the dependencies are installed, you can run the tests using the Composer-installed'
     128                . ' version of PHPUnit or using a PHPUnit phar file, but the dependencies do need to be'
     129                . ' installed whichever way the tests are run.' . PHP_EOL;
    121130        }
    122131        exit( 1 );
     
    137146) {
    138147    printf(
    139         'Error: Version mismatch detected for the PHPUnit Polyfills. Please ensure that PHPUnit Polyfills %s or higher is loaded. Found version: %s' . PHP_EOL,
     148        'Error: Version mismatch detected for the PHPUnit Polyfills.'
     149        . ' Please ensure that PHPUnit Polyfills %s or higher is loaded. Found version: %s' . PHP_EOL,
    140150        $phpunit_polyfills_minimum_version,
    141151        defined( '\Yoast\PHPUnitPolyfills\Autoload::VERSION' ) ? Yoast\PHPUnitPolyfills\Autoload::VERSION : '1.0.0 or lower'
     
    143153    if ( defined( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH' ) ) {
    144154        printf(
    145             'Please ensure that the PHPUnit Polyfill install in "%s" is updated to version %s or higher.' . PHP_EOL,
     155            'Please ensure that the PHPUnit Polyfill installation in "%s" is updated to version %s or higher.' . PHP_EOL,
    146156            WP_TESTS_PHPUNIT_POLYFILLS_PATH,
    147157            $phpunit_polyfills_minimum_version
Note: See TracChangeset for help on using the changeset viewer.