Skip to content

Commit a962fe1

Browse files
committed
Forward PHPUnit runtime package options
1 parent 95ab723 commit a962fe1

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { readFile, writeFile } from "node:fs/promises"
2-
import { buildGenericAbilityRuntimeRunRecipe, buildRuntimePackageRunRecipe, buildWordPressBenchRecipe, buildWordPressPhpunitRecipe, compileRecipeTemplate, type GenericAbilityRuntimeRunOptions, type RecipeTemplateInput, type RuntimePackageRunRecipeOptions, type WorkspaceRecipe, type WorkspaceRecipeExtraPlugin, type WorkspaceRecipeMount, type WorkspaceRecipeRuntimeService, type WorkspaceRecipeStep } from "@automattic/wp-codebox-core"
2+
import { buildGenericAbilityRuntimeRunRecipe, buildRuntimePackageRunRecipe, buildWordPressBenchRecipe, buildWordPressPhpunitRecipe, compileRecipeTemplate, type GenericAbilityRuntimeRunOptions, type RecipeTemplateInput, type RuntimePackageRunRecipeOptions, type WorkspaceRecipe, type WorkspaceRecipeExtraPlugin, type WorkspaceRecipeMount, type WorkspaceRecipePHPWasmExtensionManifest, type WorkspaceRecipeRuntimeBackendPackage, type WorkspaceRecipeRuntimeService, type WorkspaceRecipeStep } from "@automattic/wp-codebox-core"
33

44
interface RecipeBuildOptions {
55
recipeType: "phpunit" | "bench" | "template" | "generic-ability-runtime-run" | "runtime-package-run"
@@ -10,6 +10,9 @@ interface RecipeBuildOptions {
1010
interface WordPressPhpunitBuilderOptions {
1111
blueprint?: unknown
1212
wordpressVersion?: string
13+
phpVersion?: string
14+
extensions?: WorkspaceRecipePHPWasmExtensionManifest[]
15+
backendPackage?: WorkspaceRecipeRuntimeBackendPackage
1316
mounts?: WorkspaceRecipeMount[]
1417
services?: WorkspaceRecipeRuntimeService[]
1518
extra_plugins?: WorkspaceRecipeExtraPlugin[]
@@ -76,6 +79,9 @@ function buildRecipe(recipeType: RecipeBuildOptions["recipeType"], options: Word
7679
return buildWordPressPhpunitRecipe({
7780
blueprint: phpunitOptions.blueprint,
7881
wordpressVersion: stringOrUndefined(phpunitOptions.wordpressVersion),
82+
phpVersion: stringOrUndefined(phpunitOptions.phpVersion),
83+
extensions: Array.isArray(phpunitOptions.extensions) ? phpunitOptions.extensions : [],
84+
backendPackage: phpunitOptions.backendPackage,
7985
mounts: Array.isArray(phpunitOptions.mounts) ? phpunitOptions.mounts : [],
8086
services: Array.isArray(phpunitOptions.services) ? phpunitOptions.services : [],
8187
extra_plugins: Array.isArray(phpunitOptions.extra_plugins) ? phpunitOptions.extra_plugins : [],

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { WorkspaceRecipe, WorkspaceRecipeExtraPlugin, WorkspaceRecipeMount, WorkspaceRecipeRuntimeService, WorkspaceRecipeStep } from "./runtime-contracts.js"
1+
import type { WorkspaceRecipe, WorkspaceRecipeExtraPlugin, WorkspaceRecipeMount, WorkspaceRecipePHPWasmExtensionManifest, WorkspaceRecipeRuntimeBackendPackage, WorkspaceRecipeRuntimeService, WorkspaceRecipeStep } from "./runtime-contracts.js"
22
import { commandArg, commandJsonArg, commandStringListArg } from "./command-codecs.js"
33
export { buildRuntimePackageRunRecipe, CODEBOX_RUN_RUNTIME_PACKAGE_ABILITY, RUNTIME_PACKAGE_ARTIFACT_DECLARATION_SCHEMA, RUNTIME_PACKAGE_EXECUTION_INPUT_SCHEMA, RUNTIME_PACKAGE_EXECUTION_RESULT_SCHEMA, RUNTIME_PACKAGE_OUTPUT_PROJECTION_SCHEMA, runtimePackageExecutionInput, type RuntimePackageArtifactDeclaration, type RuntimePackageExecutionInput, type RuntimePackageOutputProjection, type RuntimePackageRunRecipeOptions } from "./runtime-package-execution.js"
44
export { RUNTIME_PACKAGE_DIAGNOSTIC_SCHEMA, RUNTIME_PACKAGE_RESULT_SCHEMA, RUNTIME_PACKAGE_TASK_SCHEMA, normalizeRuntimePackageResult, normalizeRuntimePackageTask, validateRuntimePackageTask, type RuntimePackageDiagnostic, type RuntimePackageResult, type RuntimePackageTask } from "./runtime-package-contracts.js"
@@ -13,7 +13,10 @@ export interface NormalizeRecipeMountsOptions {
1313

1414
export interface WordPressPhpunitRecipeOptions {
1515
wordpressVersion?: string
16+
phpVersion?: string
1617
blueprint?: unknown
18+
extensions?: WorkspaceRecipePHPWasmExtensionManifest[]
19+
backendPackage?: WorkspaceRecipeRuntimeBackendPackage
1720
mounts?: WorkspaceRecipeMount[]
1821
services?: WorkspaceRecipeRuntimeService[]
1922
extra_plugins?: WorkspaceRecipeExtraPlugin[]
@@ -73,7 +76,10 @@ export function buildWordPressPhpunitRecipe(options: WordPressPhpunitRecipeOptio
7376
schema: "wp-codebox/workspace-recipe/v1",
7477
runtime: {
7578
wp: options.wordpressVersion ?? DEFAULT_WORDPRESS_VERSION,
79+
...(options.phpVersion ? { phpVersion: options.phpVersion } : {}),
7680
blueprint: options.blueprint ?? { steps: [] },
81+
...(options.extensions?.length ? { extensions: options.extensions } : {}),
82+
...(options.backendPackage ? { backendPackage: options.backendPackage } : {}),
7783
},
7884
inputs: {
7985
extra_plugins: normalizeExtraPlugins(options.extra_plugins),

tests/runtime-services.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,19 @@ try {
2929
const recipePath = join(builderDirectory, "recipe.json")
3030
await writeFile(optionsPath, JSON.stringify({
3131
pluginSlug: "example",
32+
phpVersion: "8.3",
33+
extensions: [{ manifest: "./sodium/manifest.json" }],
34+
backendPackage: { kind: "playground", source: "./playground-cli", package: "@wp-playground/cli" },
3235
testRoot: "/home/example/bin/tests/core",
3336
phpunitXml: "/home/example/bin/tests/core/phpunit.xml",
3437
}))
3538
assert.equal(await runRecipeBuildCommand(["phpunit", "--options", optionsPath, "--output", recipePath]), 0)
3639
const builtRecipe = JSON.parse(await readFile(recipePath, "utf8")) as WorkspaceRecipe
3740
assert.ok(builtRecipe.workflow.steps[0].args?.includes("test-root=/home/example/bin/tests/core"))
3841
assert.ok(builtRecipe.workflow.steps[0].args?.includes("phpunit-xml=/home/example/bin/tests/core/phpunit.xml"))
42+
assert.equal(builtRecipe.runtime?.phpVersion, "8.3")
43+
assert.deepEqual(builtRecipe.runtime?.extensions, [{ manifest: "./sodium/manifest.json" }])
44+
assert.deepEqual(builtRecipe.runtime?.backendPackage, { kind: "playground", source: "./playground-cli", package: "@wp-playground/cli" })
3945

4046
await writeFile(optionsPath, JSON.stringify({ pluginSlug: "example" }))
4147
assert.equal(await runRecipeBuildCommand(["phpunit", "--options", optionsPath, "--output", recipePath]), 0)

0 commit comments

Comments
 (0)