From 1ef40b14cd351eb40084dc92a1b2d3af8e3bd33e Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 23 Jul 2020 23:26:50 +0000 Subject: [PATCH] Build/Test Tools: Check if all the required constants are defined before running the test suite. Follow-up to [47904]. Props azaozz, TimothyBlynJacobs, SergeyBiryukov. Fixes #50251. git-svn-id: https://develop.svn.wordpress.org/trunk@48592 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/includes/bootstrap.php | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/includes/bootstrap.php b/tests/phpunit/includes/bootstrap.php index 8c88fc45e2..5c03c46d58 100644 --- a/tests/phpunit/includes/bootstrap.php +++ b/tests/phpunit/includes/bootstrap.php @@ -37,10 +37,12 @@ if ( ! is_readable( $config_file_path ) ) { require_once $config_file_path; require_once __DIR__ . '/functions.php'; -if ( version_compare( tests_get_phpunit_version(), '5.4', '<' ) || version_compare( tests_get_phpunit_version(), '8.0', '>=' ) ) { +$phpunit_version = tests_get_phpunit_version(); + +if ( version_compare( $phpunit_version, '5.4', '<' ) || version_compare( $phpunit_version, '8.0', '>=' ) ) { printf( "Error: Looks like you're using PHPUnit %s. WordPress requires at least PHPUnit 5.4 and is currently only compatible with PHPUnit up to 7.x.\n", - tests_get_phpunit_version() + $phpunit_version ); echo "Please use the latest PHPUnit version from the 7.x branch.\n"; exit( 1 ); @@ -51,6 +53,23 @@ if ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS && ! is_dir( ABSPATH ) exit( 1 ); } +$required_constants = array( + 'WP_TESTS_DOMAIN', + 'WP_TESTS_EMAIL', + 'WP_TESTS_TITLE', + 'WP_PHP_BINARY', +); + +foreach ( $required_constants as $constant ) { + if ( ! defined( $constant ) ) { + printf( + "Error: The required %s constant is not defined. Check out `wp-tests-config-sample.php` for an example.\n", + $constant + ); + exit( 1 ); + } +} + tests_reset__SERVER(); define( 'WP_TESTS_TABLE_PREFIX', $table_prefix );