Skip to content

Commit 3c90756

Browse files
committed
fix: defer MySQL multisite setup to PHPUnit
1 parent 6e95f70 commit 3c90756

4 files changed

Lines changed: 10 additions & 41 deletions

File tree

packages/runtime-core/src/recipe-builders.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export function buildWordPressPhpunitRecipe(options: WordPressPhpunitRecipeOptio
8282
wp: options.wordpressVersion ?? DEFAULT_WORDPRESS_VERSION,
8383
...(options.phpVersion ? { phpVersion: options.phpVersion } : {}),
8484
...(options.wordpressInstallMode ? { wordpressInstallMode: options.wordpressInstallMode } : {}),
85-
blueprint: blueprintWithMultisite(options.blueprint ?? { steps: [] }, options.multisite ?? false),
85+
blueprint: blueprintWithMultisite(options.blueprint ?? { steps: [] }, (options.multisite ?? false) && options.databaseType !== "mysql"),
8686
...(options.preview || options.multisite ? { preview: multisitePreview(options.preview, options.multisite ?? false) } : {}),
8787
...(options.extensions?.length ? { extensions: options.extensions } : {}),
8888
...(options.backendPackage ? { backendPackage: options.backendPackage } : {}),

packages/runtime-playground/src/playground-cli-runner.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,6 @@ function externalDatabaseWpConfig(spec: RuntimeCreateSpec): string | undefined {
460460
const host = spec.runtimeEnv?.DB_HOST
461461
if (!host) return undefined
462462
const port = spec.runtimeEnv?.DB_PORT
463-
const multisite = blueprintEnablesMultisite(spec.environment.blueprint)
464-
const multisiteSite = multisiteSiteIdentity(spec.preview?.siteUrl)
465463
const values = {
466464
DB_NAME: spec.runtimeEnv?.DB_NAME ?? "runtime",
467465
DB_USER: spec.runtimeEnv?.DB_USER ?? "root",
@@ -476,33 +474,11 @@ define('DB_HOST', ${phpLiteral(values.DB_HOST)});
476474
define('DB_CHARSET', 'utf8mb4');
477475
define('DB_COLLATE', '');
478476
$table_prefix = 'wp_';
479-
${multisite ? `define('MULTISITE', true);
480-
define('SUBDOMAIN_INSTALL', false);
481-
define('DOMAIN_CURRENT_SITE', ${phpLiteral(multisiteSite.domain)});
482-
define('PATH_CURRENT_SITE', ${phpLiteral(multisiteSite.path)});
483-
define('SITE_ID_CURRENT_SITE', 1);
484-
define('BLOG_ID_CURRENT_SITE', 1);
485-
` : ""}if (!defined('ABSPATH')) define('ABSPATH', __DIR__ . '/');
477+
if (!defined('ABSPATH')) define('ABSPATH', __DIR__ . '/');
486478
require_once ABSPATH . 'wp-settings.php';
487479
`
488480
}
489481

490-
function blueprintEnablesMultisite(blueprint: unknown): boolean {
491-
if (!blueprint || typeof blueprint !== "object" || Array.isArray(blueprint)) return false
492-
const steps = Array.isArray((blueprint as { steps?: unknown }).steps) ? (blueprint as { steps: unknown[] }).steps : []
493-
return steps.some((step) => Boolean(step && typeof step === "object" && !Array.isArray(step) && (step as { step?: unknown }).step === "enableMultisite"))
494-
}
495-
496-
function multisiteSiteIdentity(siteUrl?: string): { domain: string; path: string } {
497-
try {
498-
const url = new URL(siteUrl || "http://localhost")
499-
const path = `/${url.pathname.replace(/^\/+|\/+$/g, "")}`
500-
return { domain: url.hostname || "localhost", path: path === "/" ? path : `${path}/` }
501-
} catch {
502-
return { domain: "localhost", path: "/" }
503-
}
504-
}
505-
506482
function distributionBootstrapPhp(spec: RuntimeCreateSpec): string {
507483
const distribution = recipeDistribution(spec)
508484
if (!distribution) {

tests/phpunit-project-autoload.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,14 @@ assert.deepEqual((multisiteRecipe.runtime.blueprint as { steps: unknown[] }).ste
770770
assert.equal(multisiteRecipe.runtime.preview?.siteUrl, "http://localhost", "multisite PHPUnit recipes need a canonical site URL without the dynamic Playground port")
771771
assert.ok(multisiteRecipe.workflow.steps[0].args.includes("multisite=1"))
772772

773+
const externalMysqlMultisiteRecipe = buildWordPressPhpunitRecipe({
774+
pluginSlug: "network-plugin",
775+
databaseType: "mysql",
776+
multisite: true,
777+
})
778+
assert.deepEqual((externalMysqlMultisiteRecipe.runtime.blueprint as { steps: unknown[] }).steps, [], "external MySQL must boot single-site until the managed PHPUnit installer creates network tables")
779+
assert.ok(externalMysqlMultisiteRecipe.workflow.steps[0].args.includes("multisite=1"), "managed PHPUnit still receives the declared multisite contract")
780+
773781
const phpunitCacheAllocator = extractPhpFunction(managedModeCode, "wp_codebox_phpunit_args_private_cache_result_file")
774782
const phpunitArgsFunction = extractPhpFunction(managedModeCode, "wp_codebox_phpunit_args")
775783
const phpunitArgsProbe = join(mkdtempSync(join(tmpdir(), "wp-codebox-phpunit-cache-args-")), "probe.php")

tests/playground-cli-runner-bootstrap-ini.test.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -103,21 +103,6 @@ try {
103103
const externalWpConfig = await readFile(externalWpConfigPath as string, "utf8")
104104
assert.match(externalWpConfig, /define\('DB_HOST', "127\.0\.0\.1:33061"\)/)
105105
assert.match(externalWpConfig, /define\('DB_PASSWORD', "secret"\)/)
106-
assert.doesNotMatch(externalWpConfig, /define\('MULTISITE'/)
107-
108-
calls.length = 0
109-
const externalMultisiteSpec: RuntimeCreateSpec = {
110-
...spec,
111-
environment: { ...spec.environment, blueprint: { steps: [{ step: "enableMultisite" }] } },
112-
}
113-
const externalMultisiteServer = await startPlaygroundCliServer(externalMultisiteSpec, [], { cliModule })
114-
await externalMultisiteServer[Symbol.asyncDispose]()
115-
const externalMultisiteConfigPath = calls[0]["mount-before-install"]?.find((mount) => mount.vfsPath === "/wordpress/wp-config.php")?.hostPath
116-
assert.equal(typeof externalMultisiteConfigPath, "string")
117-
const externalMultisiteConfig = await readFile(externalMultisiteConfigPath as string, "utf8")
118-
assert.match(externalMultisiteConfig, /define\('MULTISITE', true\)/)
119-
assert.match(externalMultisiteConfig, /define\('SUBDOMAIN_INSTALL', false\)/)
120-
assert.match(externalMultisiteConfig, /define\('DOMAIN_CURRENT_SITE', "localhost"\)/)
121106

122107
calls.length = 0
123108
const defaultRuntimeIniSpec: RuntimeCreateSpec = {

0 commit comments

Comments
 (0)