Skip to content

Commit 370bdad

Browse files
committed
style: clean up the bootstrap file
1 parent 2ad1f8b commit 370bdad

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

tests/bootstrap.php

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
<?php
22
/**
33
* PHPUnit bootstrap file
4-
*
5-
* @package eyepatch-manager
64
*/
75

8-
if ( getenv( 'WP_LOCAL_TESTING' ) === 'true' ) {
9-
require dirname(dirname(__FILE__)) . '/vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php';
10-
}
11-
126
$_tests_dir = getenv( 'WP_TESTS_DIR' );
7+
138
if ( ! $_tests_dir ) {
14-
$_tests_dir = '/tmp/wordpress-tests-lib';
9+
$_tests_dir = rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib';
10+
}
11+
12+
// Forward custom PHPUnit Polyfills configuration to PHPUnit bootstrap file.
13+
$_phpunit_polyfills_path = getenv( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH' );
14+
if ( false !== $_phpunit_polyfills_path ) {
15+
define( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH', $_phpunit_polyfills_path );
16+
}
17+
18+
if ( ! file_exists( "{$_tests_dir}/includes/functions.php" ) ) {
19+
echo "Could not find {$_tests_dir}/includes/functions.php, have you run bin/install-wp-tests.sh ?" . PHP_EOL; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
20+
exit( 1 );
1521
}
1622

17-
/**
18-
* The path to the main file of the plugin to test.
19-
*/
2023
define( 'WP_USE_THEMES', false );
2124
define( 'WP_TESTS_FORCE_KNOWN_BUGS', true );
2225
define( 'OPTML_PHPUNIT_TESTING', true );
2326
// Give access to tests_add_filter() function.
24-
require_once $_tests_dir . '/includes/functions.php';
25-
27+
require_once "{$_tests_dir}/includes/functions.php";
2628

2729
/**
2830
* Manually load the plugin being tested.
@@ -67,10 +69,17 @@ function( $message ) {
6769
}
6870

6971
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
72+
7073
// Start up the WP testing environment.
7174
require $_tests_dir . '/includes/bootstrap.php';
75+
76+
// Activate Optimole plugin
7277
activate_plugin( 'optimole-wp/optimole-wp.php' );
78+
79+
// Set up the current logged in user
7380
global $current_user;
81+
7482
$current_user = new WP_User( 1 );
7583
$current_user->set_role( 'administrator' );
84+
7685
wp_update_user( array( 'ID' => 1, 'first_name' => 'Admin', 'last_name' => 'User' ) );

0 commit comments

Comments
 (0)