diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 1cc4026cf..33b5a75cc 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -5,27 +5,18 @@ * @package PWA */ -define( 'TESTS_PLUGIN_DIR', dirname( __DIR__ ) ); +use Yoast\WPTestUtils\WPIntegration; -// Detect where to load the WordPress tests environment from. -if ( false !== getenv( 'WP_TESTS_DIR' ) ) { - $_test_root = getenv( 'WP_TESTS_DIR' ); -} elseif ( false !== getenv( 'WP_DEVELOP_DIR' ) ) { - $_test_root = getenv( 'WP_DEVELOP_DIR' ) . '/tests/phpunit'; -} elseif ( file_exists( '/tmp/wordpress-tests/includes/bootstrap.php' ) ) { - $_test_root = '/tmp/wordpress-tests'; -} elseif ( file_exists( '/var/www/wordpress-develop/tests/phpunit' ) ) { - $_test_root = '/var/www/wordpress-develop/tests/phpunit'; -} else { - $_test_root = dirname( dirname( dirname( dirname( TESTS_PLUGIN_DIR ) ) ) ) . '/tests/phpunit'; -} +define( 'TESTS_PLUGIN_DIR', dirname( __DIR__ ) ); // When run in wp-env context, set the test config file path. if ( ! defined( 'WP_TESTS_CONFIG_FILE_PATH' ) && false !== getenv( 'WP_PHPUNIT__TESTS_CONFIG' ) ) { define( 'WP_TESTS_CONFIG_FILE_PATH', getenv( 'WP_PHPUNIT__TESTS_CONFIG' ) ); } -require $_test_root . '/includes/functions.php'; +require_once TESTS_PLUGIN_DIR . '/vendor/yoast/wp-test-utils/src/WPIntegration/bootstrap-functions.php'; +$_tests_dir = WPIntegration\get_path_to_wp_test_dir(); +require_once $_tests_dir . '/includes/functions.php'; /** * Force plugins defined in a constant (supplied by phpunit.xml) to be active at runtime. @@ -67,13 +58,23 @@ function pwa_unit_test_load_plugin_file() { define( 'WP_CLI_ROOT', TESTS_PLUGIN_DIR . '/vendor/wp-cli/wp-cli' ); define( 'WP_CLI_VENDOR_DIR', TESTS_PLUGIN_DIR . '/vendor' ); +/* + * Load WordPress, which will load the Composer autoload file, and load the MockObject autoloader after that. + */ +WPIntegration\bootstrap_it(); + if ( file_exists( WP_CLI_ROOT . '/php/utils.php' ) ) { require_once WP_CLI_ROOT . '/php/utils.php'; - WP_CLI\Utils\load_dependencies(); $logger = new WP_CLI\Loggers\Regular( true ); WP_CLI::set_logger( $logger ); } -// Start up the WP testing environment. -require $_test_root . '/includes/bootstrap.php'; +// Fix up the SERVER_PORT which was just clobbered by tests_reset__SERVER(). +if ( defined( 'WP_HOME' ) ) { + $port = wp_parse_url( WP_HOME, PHP_URL_PORT ); + if ( ! $port ) { + $port = '80'; + } + $_SERVER['SERVER_PORT'] = $port; +}