Skip to content

Commit 61e332b

Browse files
committed
Expose PHPUnit arguments during project bootstrap
1 parent f512929 commit 61e332b

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,18 @@ $bootstrap_mode = ${JSON.stringify(options.bootstrapMode || "managed")};
370370
$project_bootstrap = ${JSON.stringify(options.projectBootstrap)};
371371
$multisite = ${JSON.stringify(options.multisite)};
372372
373+
function pg_build_phpunit_argv($raw): array {
374+
$phpunit_argv = array('phpunit');
375+
if (is_array($raw)) {
376+
foreach ($raw as $arg) {
377+
if (is_scalar($arg)) {
378+
$phpunit_argv[] = (string) $arg;
379+
}
380+
}
381+
}
382+
return $phpunit_argv;
383+
}
384+
373385
@file_put_contents($result_file, '');
374386
375387
function pg_log($msg) {
@@ -1045,6 +1057,10 @@ try {
10451057
}
10461058
10471059
pg_apply_env($bench_env);
1060+
$phpunit_argv = pg_build_phpunit_argv($phpunit_args_raw);
1061+
$argv = $phpunit_argv;
1062+
$_SERVER['argv'] = $phpunit_argv;
1063+
$_SERVER['argc'] = count($phpunit_argv);
10481064
10491065
if (!is_array($wp_config_defines)) {
10501066
$wp_config_defines = array();
@@ -1291,14 +1307,6 @@ function wp_codebox_phpunit_print_test_list($test) {
12911307
pg_stage_begin('run_tests');
12921308
pg_log('RUNNING ' . count($test_files) . ' TEST FILES');
12931309
try {
1294-
$phpunit_argv = array('phpunit');
1295-
if (is_array($phpunit_args_raw)) {
1296-
foreach ($phpunit_args_raw as $arg) {
1297-
if (is_scalar($arg)) {
1298-
$phpunit_argv[] = (string) $arg;
1299-
}
1300-
}
1301-
}
13021310
$phpunit_args = wp_codebox_phpunit_args($phpunit_argv);
13031311
if (!empty($phpunit_args['listTests'])) {
13041312
wp_codebox_phpunit_print_test_list($suite);

tests/phpunit-project-autoload.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,9 @@ const projectModeCode = phpunitRunCode({
254254
const bootIndex = projectModeCode.indexOf("$config_path = pg_run_boot_stage")
255255
const projectBootstrapIndex = projectModeCode.indexOf("pg_run_project_bootstrap_stage", bootIndex)
256256
const projectAutoloadIndex = projectModeCode.indexOf("pg_run_project_autoload_stage", projectBootstrapIndex)
257+
const phpunitArgvIndex = projectModeCode.indexOf("$_SERVER['argv'] = $phpunit_argv;")
257258
assert.ok(bootIndex > 0)
259+
assert.ok(phpunitArgvIndex > 0 && phpunitArgvIndex < projectBootstrapIndex, "project bootstrap must receive forwarded PHPUnit arguments")
258260
assert.ok(projectBootstrapIndex > bootIndex)
259261
assert.ok(projectAutoloadIndex > projectBootstrapIndex)
260262
assert.ok(projectModeCode.includes("'autoload_required' => $bootstrap_mode !== 'project' || $harness_autoload_file !== ''"))

0 commit comments

Comments
 (0)