Tests: Improve bootstrap error message for when ABSPATH folder does not exist.

The PHPUnit tests are/should generally be run on the `src` directory, so changes just made can be tested. While testing via the `build` directory is also still supported, this is not the default.

This was last changed in [50441], but that commit did not remove/update the error message thrown by the test bootstrap file.

This last change also did not take into account that that change meant that people had to update their own `wp`tests-config.php` file to match the change made in Core and would otherwise still get the outdated error message.

This commit changes the messaging in the test bootstrap file to be more in line with the current reality, while still accounting for the fact that tests can be run from both `src` as well as `build`.

Follow-up to [49569], [50441], [51581].
Props jrf, hellofromTonya.

git-svn-id: https://develop.svn.wordpress.org/trunk@51669 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Tonya Mork 2021-08-26 17:55:02 +00:00
parent d616b931e0
commit 6201d437e8

View File

@ -31,8 +31,18 @@ require_once $config_file_path;
require_once __DIR__ . '/functions.php';
if ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS && ! is_dir( ABSPATH ) ) {
echo 'Error: The /build/ directory is missing! Please run `npm run build` prior to running PHPUnit.' . PHP_EOL;
exit( 1 );
if ( substr( ABSPATH, -7 ) !== '/build/' ) {
printf(
'Error: The ABSPATH constant in the `wp-tests-config.php` file is set to a non-existent path "%s". Please verify.' . PHP_EOL,
ABSPATH
);
exit( 1 );
} else {
echo 'Error: The PHPUnit tests should be run on the /src/ directory, not the /build/ directory.'
. ' Please update the ABSPATH constant in your `wp-tests-config.php` file to `dirname( __FILE__ ) . \'/src/\'`'
. ' or run `npm run build` prior to running PHPUnit.' . PHP_EOL;
exit( 1 );
}
}
$phpunit_version = tests_get_phpunit_version();