質問: '/tmp/buddypress/tests/phpunit'; define( 'bp_tests_dir', $bp_tests_dir ); echo 'done defining stuff! '; require_once $wp_tests_dir . '/includes/bootstrap.php'; require_once $wp_tests_dir . '/includes/functions.php'; echo 'done requiring test dirs! ' ; // this is my debugging file, which ensures that tests won't fail // if there's a call to `_log()`. require dirname( __file__ ) . '/debug.php'; function _manually_load_plugin() { require bp_tests_dir . '/includes/loader.php'; // override this class to load mock data require dirname( __file__ ) . '/class-mockmlaapi.php'; // don't get the whole plugin now, just a few classes, because // to test them individually we feed them mock data above. require dirname( __file__ ) . '/../class-customauthentication.php'; // requiring this file gives you access to bp_unittestcase require $bp_tests_dir . '/includes/testcase.php'; } tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
回答: 私はここでの主な問題はあなたがwordpressのブートストラップを早くロードしすぎているということです。これに変更することでそれを修正することができます(私は物事がそれらがある順にある理由を説明する散在したコメント):// this file contains tests_add_filter(), so we need to load it // so that we can hook the _manually_load_plugin() function to // muplugins_loaded. we can't use add_action() because wordpress // isn't loaded yet, and we can't load it quite yet (see below). require_once $wp_tests_dir . '/includes/functions.php'; // this function loads the plugin and dependencies. we need to // define it and hook it to muplugins_loaded before including // wordpress's bootstrap, since that will load wordpress. if // we don't hook this up first, the hook will be fired when // wordpress is loaded, and adding a hook to this after that // will have no effect. function _manually_load_plugin() { /* code in here is probably the same. */ } tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' ); // now that our function is hooked up, we can load wordpress, and // the plugin and dependencies will be loaded when the hook gets // called. require_once $wp_tests_dir . '/includes/bootstrap.php';