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.

git-svn-id: https://develop.svn.wordpress.org/trunk@51813 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Tonya Mork 2021-09-14 18:52:57 +00:00
parent 3062b3d803
commit f44a995297

View File

@ -61,22 +61,25 @@ if ( version_compare( $phpunit_version, '5.7.21', '<' ) ) {
*
* The PHPUnit Polyfills are a requirement for the WP test suite.
*
* For running the Core tests, the Make WordPress Core handbook contains step-by-step instructions
* on how to get up and running for a variety of supported workflows:
* {@link https://make.wordpress.org/core/handbook/testing/automated-testing/phpunit/#test-running-workflow-options}
*
* Plugin/theme integration tests can handle this in any of the following ways:
* - When using a full WP install: run `composer update` for the WP install prior to running the tests.
* - When using a partial WP test suite install:
* - Add a `yoast/phpunit-polyfills` (dev) requirement to their own `composer.json` file.
* - Add a `yoast/phpunit-polyfills` (dev) requirement to the plugin/theme's own `composer.json` file.
* - And then:
* - Either load the PHPUnit Polyfills autoload file prior to running the WP core bootstrap file.
* - Or declare a `WP_TESTS_PHPUNIT_POLYFILLS_PATH` constant pointing to the root directory
* of the PHPUnit Polyfills installation.
* This constant can be declared in the `phpunit.xml[.dist]` file like this:
* `<php><const name="WP_TESTS_PHPUNIT_POLYFILLS_PATH" value="path/to/yoast/phpunit-polyfills"/></php>
* or can be declared as a PHP constant in the `wp-tests-config.php` file or the plugin/theme
* test bootstrap file.
* - Or declare a `WP_TESTS_PHPUNIT_POLYFILLS_PATH` constant containing the absolute path to the
* root directory of the PHPUnit Polyfills installation.
* If the constant is used, it is strongly recommended to declare this constant in the plugin/theme's
* own test bootstrap file.
* The constant MUST be declared prior to calling this file.
*/
if ( ! class_exists( 'Yoast\PHPUnitPolyfills\Autoload' ) ) {
// Default location of the autoloader for WP core test runs.
$phpunit_polyfills_autoloader = __DIR__ . '/../../../vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php';
$phpunit_polyfills_autoloader = dirname( dirname( dirname( __DIR__ ) ) ) . '/vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php';
$phpunit_polyfills_error = false;
// Allow for a custom installation location to be provided for plugin/theme integration tests.
@ -92,12 +95,7 @@ if ( ! class_exists( 'Yoast\PHPUnitPolyfills\Autoload' ) ) {
$phpunit_polyfills_path = $phpunit_polyfills_path . '/phpunitpolyfills-autoload.php';
}
$phpunit_polyfills_path = realpath( $phpunit_polyfills_path );
if ( false !== $phpunit_polyfills_path ) {
$phpunit_polyfills_autoloader = $phpunit_polyfills_path;
} else {
$phpunit_polyfills_error = true;
}
$phpunit_polyfills_autoloader = $phpunit_polyfills_path;
} else {
$phpunit_polyfills_error = true;
}
@ -111,13 +109,24 @@ if ( ! class_exists( 'Yoast\PHPUnitPolyfills\Autoload' ) ) {
WP_TESTS_PHPUNIT_POLYFILLS_PATH
);
echo 'Please verify that the file path provided in the WP_TESTS_PHPUNIT_POLYFILLS_PATH constant is correct.' . PHP_EOL;
echo 'The WP_TESTS_PHPUNIT_POLYFILLS_PATH constant should contain an absolute path to the root directory'
. ' of the PHPUnit Polyfills library.' . PHP_EOL;
} elseif ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS ) {
echo 'You need to run `composer update` before running the tests.' . PHP_EOL;
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;
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;
} else {
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;
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;
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;
echo 'If you are trying to run plugin/theme integration tests, make sure the PHPUnit Polyfills library'
. ' (https://github.com/Yoast/PHPUnit-Polyfills) 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 absolute 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;
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;
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;
}
exit( 1 );
}
@ -136,13 +145,14 @@ if ( class_exists( '\Yoast\PHPUnitPolyfills\Autoload' )
|| version_compare( Yoast\PHPUnitPolyfills\Autoload::VERSION, $phpunit_polyfills_minimum_version, '<' ) )
) {
printf(
'Error: Version mismatch detected for the PHPUnit Polyfills. Please ensure that PHPUnit Polyfills %s or higher is loaded. Found version: %s' . PHP_EOL,
'Error: Version mismatch detected for the PHPUnit Polyfills.'
. ' Please ensure that PHPUnit Polyfills %s or higher is loaded. Found version: %s' . PHP_EOL,
$phpunit_polyfills_minimum_version,
defined( '\Yoast\PHPUnitPolyfills\Autoload::VERSION' ) ? Yoast\PHPUnitPolyfills\Autoload::VERSION : '1.0.0 or lower'
);
if ( defined( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH' ) ) {
printf(
'Please ensure that the PHPUnit Polyfill install in "%s" is updated to version %s or higher.' . PHP_EOL,
'Please ensure that the PHPUnit Polyfill installation in "%s" is updated to version %s or higher.' . PHP_EOL,
WP_TESTS_PHPUNIT_POLYFILLS_PATH,
$phpunit_polyfills_minimum_version
);