Skip to content

Commit d373084

Browse files
authored
Fix project PHPUnit autoload default
1 parent 9b32333 commit d373084

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -905,11 +905,13 @@ export async function runPhpunitCommand({
905905
const args = spec.args ?? []
906906
const explicitCode = argValue(args, "code") || argValue(args, "code-file")
907907
const pluginSlug = argValue(args, "plugin-slug")?.trim() || ""
908+
const bootstrapMode = argValue(args, "bootstrap-mode")?.trim() || "managed"
909+
const autoloadFile = argValue(args, "autoload-file")?.trim() || (bootstrapMode === "project" ? "" : "/wp-codebox-vendor/autoload.php")
908910
const resultFile = PLUGIN_PHPUNIT_RESULT_FILE
909911
const code = explicitCode ? await phpCodeFromArgs(args, "wordpress.phpunit") : normalizePhpCode(phpunitRunCode({
910912
pluginSlug,
911913
cwd: argValue(args, "cwd")?.trim() || `/wordpress/wp-content/plugins/${pluginSlug}`,
912-
autoloadFile: argValue(args, "autoload-file")?.trim() || "/wp-codebox-vendor/autoload.php",
914+
autoloadFile,
913915
projectAutoloadFile: argValue(args, "project-autoload-file")?.trim() || "",
914916
testsDir: argValue(args, "tests-dir")?.trim() || "/wp-codebox-vendor/wp-phpunit/wp-phpunit",
915917
testRoot: argValue(args, "test-root")?.trim() || `/wordpress/wp-content/plugins/${pluginSlug}/tests`,
@@ -922,7 +924,7 @@ export async function runPhpunitCommand({
922924
dependencyMounts: commaListArg(args, "dependency-mounts"),
923925
bootstrapFiles: jsonArrayArg(args, "bootstrap-files-json").filter((value): value is string => typeof value === "string"),
924926
preloadFiles: jsonArrayArg(args, "preload-files-json").filter((value): value is string => typeof value === "string"),
925-
bootstrapMode: argValue(args, "bootstrap-mode")?.trim() || "managed",
927+
bootstrapMode,
926928
projectBootstrap: argValue(args, "project-bootstrap")?.trim() || "",
927929
multisite: booleanArg(args, "multisite"),
928930
resultFile,

tests/phpunit-project-autoload.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { join } from "node:path"
66

77
import { buildWordPressPhpunitRecipe } from "../packages/runtime-core/src/recipe-builders.js"
88
import { corePhpunitRunCode, phpunitRunCode } from "../packages/runtime-playground/src/phpunit-command-handlers.js"
9+
import { runPhpunitCommand } from "../packages/runtime-playground/src/wordpress-command-runners.js"
910
import { recipePolicy } from "../packages/cli/src/recipe-validation.js"
1011
import { recipeExtraPluginSourceSubpath } from "../packages/cli/src/recipe-sources.js"
1112
import { recipeInputMountPathMap, rewriteInputMountPathArgs } from "../packages/cli/src/commands/recipe-runtime-setup.js"
@@ -156,6 +157,28 @@ assert.equal(projectModeCode.match(/return array\(\$directories, \$suffixes, \$p
156157
assert.equal(projectModeCode.match(/return \$return_values\(\);/g)?.length, 3)
157158
assertPhpunitParseConfigFallbacksReturnFiveTuple(projectModeCode, "wp_codebox_phpunit_parse_config", "pg_log")
158159

160+
let capturedDefaultProjectCode = ""
161+
await runPhpunitCommand({
162+
artifactRoot: mkdtempSync(join(tmpdir(), "wp-codebox-phpunit-artifacts-")),
163+
mounts: [],
164+
runPlaygroundCommand: async (_command, _server, input) => {
165+
capturedDefaultProjectCode = input.code
166+
return { text: "ok", exitCode: 0 }
167+
},
168+
server: { playground: {} } as never,
169+
spec: {
170+
command: "wordpress.phpunit",
171+
args: [
172+
"plugin-slug=ai-provider-for-openai",
173+
"bootstrap-mode=project",
174+
"phpunit-xml=phpunit.xml.dist",
175+
"test-file=tests/unit/Models/OpenAiEmbeddingGenerationModelTest.php",
176+
],
177+
},
178+
})
179+
assert.ok(capturedDefaultProjectCode.includes('$autoload_file = "";'))
180+
assert.ok(capturedDefaultProjectCode.includes("NOTICE:project bootstrap mode continuing without configured PHPUnit harness autoload"))
181+
159182
const coreModeCode = corePhpunitRunCode({
160183
coreRoot: "/wordpress",
161184
testsDir: "/wordpress/tests/phpunit",

0 commit comments

Comments
 (0)