Using answers on this site and from other resources, I have started writing my next plugin using PHPUnit tests and the WordPress test environment. Distilling down what I have in my plugin’s bootstrap.php
:
define( 'WP_TESTS_DIR', 'pathToMyWordPressTestsFromSVN');
define( 'TEST_PLUGIN_FILE', 'pathToMyPlugin/myPlugin.php' );
require_once WP_TESTS_DIR . 'includes/functions.php';
require WP_TESTS_DIR . 'includes/bootstrap.php';
function _manually_load_plugin() {
require TEST_PLUGIN_FILE;
if(is_plugin_active(TEST_PLUGIN_FILE)){
echo "PLUGIN IS LOADED AND WORKING!!!!";
}
}
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
// Normally you'd find "require WP_TESTS_DIR . 'includes/bootstrap.php';" down here...
In essentially every example, the WordPress test environment bootstrap.php
is loaded last.
This seems strange because if I load it earlier, I get access to functions like is_plugin_active
which I imagine will be useful when testing plugins that require others…and bailing out if the requirements aren’t loaded for some reason.
Is there a reason the test environment is bootstrapped at the end…other than habit/convention?