-
Notifications
You must be signed in to change notification settings - Fork 814
/
Copy pathbootstrap.php
78 lines (68 loc) · 2.99 KB
/
bootstrap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/**
* PHPUnit bootstrap file.
*
* @package automattic/jetpack
*/
// Assume we're in tests/php/bootstrap.php.
$_plugin_root = dirname( __DIR__, 2 );
// Locate WordPress or wordpress-develop. We look in several places.
if ( false !== getenv( 'WORDPRESS_DEVELOP_DIR' ) ) {
// Jetpack Monorepo environment variable.
$_tests_dir = getenv( 'WORDPRESS_DEVELOP_DIR' );
if ( file_exists( "$_tests_dir/tests/phpunit/" ) ) {
$_tests_dir .= '/tests/phpunit/';
}
} elseif ( false !== getenv( 'WP_TESTS_DIR' ) ) {
// WordPress core environment variable.
$_tests_dir = getenv( 'WP_TESTS_DIR' );
} elseif ( file_exists( dirname( $_plugin_root, 2 ) . '/tests/phpunit/includes/bootstrap.php' ) ) {
// Installed inside wordpress-develop.
$_tests_dir = dirname( $_plugin_root, 2 ) . '/tests/phpunit/includes/bootstrap.php';
} elseif ( file_exists( '/vagrant/www/wordpress-develop/public_html/tests/phpunit/includes/bootstrap.php' ) ) {
// VVV.
$_tests_dir = '/vagrant/www/wordpress-develop/public_html/tests/phpunit';
} elseif ( file_exists( '/srv/www/wordpress-trunk/public_html/tests/phpunit/includes/bootstrap.php' ) ) {
// VVV 3.0.
$_tests_dir = '/srv/www/wordpress-trunk/public_html/tests/phpunit';
} elseif ( file_exists( '/tmp/wordpress-develop/tests/phpunit/includes/bootstrap.php' ) ) {
// Manual checkout & Jetpack's docker environment.
$_tests_dir = '/tmp/wordpress-develop/tests/phpunit';
} elseif ( file_exists( rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib/includes/bootstrap.php' ) ) {
// Legacy tests.
$_tests_dir = rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib';
}
if ( ! isset( $_tests_dir ) || ! file_exists( $_tests_dir . '/includes/bootstrap.php' ) ) {
echo 'Failed to automatically locate WordPress or wordpress-develop to run tests.' . PHP_EOL;
echo PHP_EOL;
echo 'Set the WORDPRESS_DEVELOP_DIR environment variable to point to a copy of WordPress' . PHP_EOL;
echo 'or wordpress-develop.' . PHP_EOL;
exit( 1 );
}
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo "Using test root $_tests_dir\n";
if ( ! is_readable( $_plugin_root . '/vendor/autoload.php' ) ) {
echo 'The plugin is not ready for testing.' . PHP_EOL;
echo PHP_EOL;
echo 'Composer dependencies must be installed.' . PHP_EOL;
exit( 1 );
}
// Give access to tests_add_filter() function.
require_once $_tests_dir . '/includes/functions.php';
/**
* Manually load the plugin being tested.
*/
function _manually_load_plugin() {
global $_plugin_root;
require $_plugin_root . '/plugin.php';
}
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
// Override WP_TESTS_CONFIG_FILE_PATH via environment.
// Important for monorepo CI, if you don't do this then different test runs might collide!
if ( false !== getenv( 'WP_TESTS_CONFIG_FILE_PATH' ) ) {
define( 'WP_TESTS_CONFIG_FILE_PATH', getenv( 'WP_TESTS_CONFIG_FILE_PATH' ) );
}
// Start up the WP testing environment.
require $_tests_dir . '/includes/bootstrap.php';
// Load Composer autoloader.
require $_plugin_root . '/vendor/autoload.php';