使用这个网站上的答案和其他资源,我已经开始使用PHPUnit测试和WordPress测试环境编写下一个插件。提取插件中的内容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...
 在每个示例中,WordPress测试环境
bootstrap.php 最后加载。
这似乎很奇怪,因为如果我更早地加载它,我可以访问如下函数is_plugin_active 我想这在测试需要其他插件的插件时会很有用。。。如果由于某种原因没有加载需求,那么就退出。
Is there a reason the test environment is bootstrapped at the end...other than habit/convention?
 
                    最合适的回答,由SO网友:J.D. 整理而成
                    WordPress测试引导程序在最后加载的原因正是因为它loads WordPress:
// Load WordPress
require_once ABSPATH . \'/wp-settings.php\';
 如果你没有钩住你的函数来加载你的插件
\'muplugins_loaded\' <在包含引导程序之前,您的插件不会加载WordPress。在大多数情况下,这意味着您的插件无法正确设置(例如。,
\'init\' 将在插件功能连接之前被触发)。
至于检查依赖关系,您可能可以通过连接\'plugins_loaded\' 措施:
function _check_for_dependencies() {
    if ( ! is_plugin_active( \'some-plugin/some-plugin.php\' ) ) {
        exit( \'Some Plugin must be active to run the tests.\' . PHP_EOL );
    }
}
tests_add_filter( \'plugins_loaded\', \'_check_for_dependencies\' );
 或者,您可以让WordPress的引导程序完全加载,然后检查您的依赖关系。