@@ -21,6 +21,7 @@ export interface PhpunitRunCodeOptions {
2121 bootstrapMode : string
2222 projectBootstrap : string
2323 multisite : boolean
24+ preinstalledMultisite ?: boolean
2425 databaseType : "sqlite" | "mysql"
2526 /**
2627 * Sandbox-internal, writable path for the structured diagnostics log. Defaults
@@ -459,6 +460,7 @@ $preload_files = json_decode(${JSON.stringify(JSON.stringify(options.preloadFile
459460$bootstrap_mode = ${ JSON . stringify ( options . bootstrapMode || "managed" ) } ;
460461$project_bootstrap = ${ JSON . stringify ( options . projectBootstrap ) } ;
461462$multisite = ${ JSON . stringify ( options . multisite ) } ;
463+ $preinstalled_multisite = ${ JSON . stringify ( options . preinstalledMultisite ?? false ) } ;
462464$database_type = ${ JSON . stringify ( options . databaseType ) } ;
463465
464466function pg_build_phpunit_argv($raw): array {
@@ -778,6 +780,37 @@ function pg_run_boot_stage(array $cfg = []): ?string {
778780 }
779781}
780782
783+ function pg_run_preinstalled_multisite_stage(array $cfg): void {
784+ pg_stage_begin('install');
785+ try {
786+ $config_path = (string) ($cfg['config_path'] ?? '');
787+ $tests_dir = (string) ($cfg['tests_dir'] ?? '');
788+ if ($config_path === '' || !is_readable($config_path)) {
789+ throw new RuntimeException('managed multisite config is not readable: ' . $config_path);
790+ }
791+ if ($tests_dir === '' || !is_readable($tests_dir . '/includes/functions.php')) {
792+ throw new RuntimeException('managed multisite test library is not readable: ' . $tests_dir);
793+ }
794+ if (!defined('WP_INSTALLING')) {
795+ define('WP_INSTALLING', true);
796+ }
797+ if (!defined('DISABLE_WP_CRON')) {
798+ define('DISABLE_WP_CRON', true);
799+ }
800+ require_once $config_path;
801+ require_once $tests_dir . '/includes/functions.php';
802+ tests_reset__SERVER();
803+ $GLOBALS['PHP_SELF'] = '/index.php';
804+ $_SERVER['PHP_SELF'] = '/index.php';
805+ tests_add_filter('wp_die_handler', '_wp_die_handler_filter_exit');
806+ require_once ABSPATH . 'wp-settings.php';
807+ pg_stage_ok('install');
808+ } catch (Throwable $e) {
809+ pg_stage_fail('install', $e);
810+ exit(1);
811+ }
812+ }
813+
781814function pg_resolve_runtime_cwd(string $cwd, string $plugin_path): string {
782815 $cwd = trim(str_replace('\\\\', '/', $cwd));
783816 if ($cwd === '') {
@@ -1222,7 +1255,11 @@ tests_add_filter('muplugins_loaded', function () use ($plugin_slug, $plugin_path
12221255 $deferred_install_init_callbacks = pg_defer_new_wordpress_hook_callbacks('init', $pre_component_init_callbacks);
12231256});
12241257
1225- pg_run_install_stage(array('config_path' => $config_path, 'tests_dir' => $tests_dir, 'multisite' => $multisite));
1258+ if ($preinstalled_multisite) {
1259+ pg_run_preinstalled_multisite_stage(array('config_path' => $config_path, 'tests_dir' => $tests_dir));
1260+ } else {
1261+ pg_run_install_stage(array('config_path' => $config_path, 'tests_dir' => $tests_dir, 'multisite' => $multisite));
1262+ }
12261263pg_remove_new_wordpress_hook_callbacks('shutdown', $pre_component_shutdown_callbacks);
12271264$pre_dependency_plugins_loaded_callbacks = pg_snapshot_wordpress_hook_callbacks('plugins_loaded');
12281265$pre_dependency_init_callbacks = pg_snapshot_wordpress_hook_callbacks('init');
0 commit comments