Skip to content

Commit 563d1ae

Browse files
committed
fix: preserve preinstalled multisite schema
1 parent 0ce09b8 commit 563d1ae

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

packages/runtime-playground/src/phpunit-command-handlers.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
464466
function 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+
781814
function 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+
}
12261263
pg_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');

packages/runtime-playground/src/wordpress-command-runners.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,7 @@ export async function runPhpunitCommand({
953953
bootstrapMode,
954954
projectBootstrap: argValue(args, "project-bootstrap")?.trim() || "",
955955
multisite,
956+
preinstalledMultisite: bootstrapMode === "managed" && databaseType === "mysql" && multisite,
956957
databaseType,
957958
resultFile,
958959
})

tests/phpunit-project-autoload.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ await runPhpunitCommand({
704704
assert.equal(mysqlMultisiteInvocations.length, 2, "managed MySQL multisite runs a separate preinstall before PHPUnit")
705705
assert.ok(mysqlMultisiteInvocations[0].includes("'run_ms_tests'"))
706706
assert.ok(mysqlMultisiteInvocations[1].includes("$phpunit_argv = pg_build_phpunit_argv"), "normal managed PHPUnit behavior follows preinstall")
707+
assert.ok(mysqlMultisiteInvocations[1].includes("$preinstalled_multisite = true"), "normal managed PHPUnit preserves the preinstalled network")
708+
assert.ok(mysqlMultisiteInvocations[1].includes("pg_run_preinstalled_multisite_stage"), "normal managed PHPUnit boots without destructively reinstalling multisite")
707709

708710
const failedPreinstallInvocations: string[] = []
709711
await assert.rejects(

0 commit comments

Comments
 (0)