Skip to content

Commit 9681379

Browse files
committed
Pass PHPUnit paths through recipe builder CLI
1 parent d146341 commit 9681379

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

packages/cli/src/commands/recipe-build.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ interface WordPressPhpunitBuilderOptions {
2323
autoloadFile?: string
2424
projectAutoloadFile?: string
2525
testsDir?: string
26+
testRoot?: string
27+
phpunitXml?: string
2628
dependencyMounts?: string[]
2729
bootstrapFiles?: string[]
2830
preloadFiles?: string[]
@@ -87,6 +89,8 @@ function buildRecipe(recipeType: RecipeBuildOptions["recipeType"], options: Word
8789
autoloadFile: stringOrUndefined(phpunitOptions.autoloadFile),
8890
projectAutoloadFile: stringOrUndefined(phpunitOptions.projectAutoloadFile),
8991
testsDir: stringOrUndefined(phpunitOptions.testsDir),
92+
testRoot: stringOrUndefined(phpunitOptions.testRoot),
93+
phpunitXml: stringOrUndefined(phpunitOptions.phpunitXml),
9094
dependencyMounts: Array.isArray(phpunitOptions.dependencyMounts) ? phpunitOptions.dependencyMounts : [],
9195
bootstrapFiles: Array.isArray(phpunitOptions.bootstrapFiles) ? phpunitOptions.bootstrapFiles : [],
9296
preloadFiles: Array.isArray(phpunitOptions.preloadFiles) ? phpunitOptions.preloadFiles : [],

tests/runtime-services.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import assert from "node:assert/strict"
2+
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises"
23
import { createServer } from "node:net"
4+
import { tmpdir } from "node:os"
5+
import { join } from "node:path"
6+
import { runRecipeBuildCommand } from "../packages/cli/src/commands/recipe-build.ts"
37
import { parseLoopbackPort, provisionRuntimeServices, provisionRuntimeServicesForRecipe, RuntimeServiceProvisionError, runtimeServiceEvidenceFromError, runtimeServicePlan, waitForMysqlProtocol, type RuntimeServiceDependencies } from "../packages/cli/src/runtime-services.ts"
48
import { planWorkspaceRecipe } from "../packages/cli/src/recipe-dry-run.ts"
59
import { validateWorkspaceRecipeSemantics } from "../packages/cli/src/recipe-validation.ts"
@@ -19,6 +23,22 @@ assert.equal(unsafe.valid, false)
1923
const emptyRootService = { ...service, configuration: { rootAuthentication: "empty-password" as const } }
2024
assert.equal(validateWorkspaceRecipeJsonSchema({ schema: "wp-codebox/workspace-recipe/v1", inputs: { services: [emptyRootService] }, workflow: { steps: [{ command: "wordpress.run-php" }] } }).valid, true)
2125
assert.deepEqual(buildWordPressPhpunitRecipe({ pluginSlug: "example", services: [emptyRootService] }).inputs?.services, [emptyRootService])
26+
const builderDirectory = await mkdtemp(join(tmpdir(), "wp-codebox-phpunit-builder-"))
27+
try {
28+
const optionsPath = join(builderDirectory, "options.json")
29+
const recipePath = join(builderDirectory, "recipe.json")
30+
await writeFile(optionsPath, JSON.stringify({
31+
pluginSlug: "example",
32+
testRoot: "/home/example/bin/tests/core",
33+
phpunitXml: "/home/example/bin/tests/core/phpunit.xml",
34+
}))
35+
assert.equal(await runRecipeBuildCommand(["phpunit", "--options", optionsPath, "--output", recipePath]), 0)
36+
const builtRecipe = JSON.parse(await readFile(recipePath, "utf8")) as WorkspaceRecipe
37+
assert.ok(builtRecipe.workflow.steps[0].args?.includes("test-root=/home/example/bin/tests/core"))
38+
assert.ok(builtRecipe.workflow.steps[0].args?.includes("phpunit-xml=/home/example/bin/tests/core/phpunit.xml"))
39+
} finally {
40+
await rm(builderDirectory, { recursive: true, force: true })
41+
}
2242
const recipe: WorkspaceRecipe = { schema: "wp-codebox/workspace-recipe/v1", inputs: { services: [service] }, workflow: { steps: [{ command: "wordpress.run-php", args: ["code=echo 'ok';"] }] } }
2343
assert.deepEqual(await validateWorkspaceRecipeSemantics(recipe, "recipe.json"), [])
2444
const dryRun = await planWorkspaceRecipe(recipe, process.cwd(), { recipePath: "recipe.json" }, {

0 commit comments

Comments
 (0)