Skip to content

Commit

Permalink
Update WP laoding in testsuite
Browse files Browse the repository at this point in the history
  • Loading branch information
thelovekesh committed Jan 18, 2024
1 parent fb95cfa commit 96a6b84
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

0 comments on commit 96a6b84

Please sign in to comment.