Skip to content

Commit 40aec34

Browse files
committed
Fix PHPUnit cache writes through readonly mounts
1 parent 57eb74e commit 40aec34

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,18 @@ function phpunitArgsPhp(functionName: string, logFunction: string): string {
300300
$arguments['verbose'] = true;
301301
continue;
302302
}
303+
if ($arg === '--cache-result-file' && isset($args[$i + 1]) && $args[$i + 1] !== '') {
304+
$arguments['cacheResult'] = true;
305+
$arguments['cacheResultFile'] = $args[++$i];
306+
${logFunction}('NOTICE:phpunit result cache redirected to: ' . $arguments['cacheResultFile']);
307+
continue;
308+
}
309+
if (strpos($arg, '--cache-result-file=') === 0 && substr($arg, strlen('--cache-result-file=')) !== '') {
310+
$arguments['cacheResult'] = true;
311+
$arguments['cacheResultFile'] = substr($arg, strlen('--cache-result-file='));
312+
${logFunction}('NOTICE:phpunit result cache redirected to: ' . $arguments['cacheResultFile']);
313+
continue;
314+
}
303315
}
304316
return $arguments;
305317
}`

tests/phpunit-project-autoload.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,4 +322,22 @@ const managedModeCode = phpunitRunCode({
322322
assert.ok(managedModeCode.includes("configured PHPUnit harness autoload file is not readable"))
323323
assert.ok(managedModeCode.includes("'cacheResult' => false"))
324324

325+
const phpunitArgsFunction = extractPhpFunction(managedModeCode, "wp_codebox_phpunit_args")
326+
const phpunitArgsProbe = join(mkdtempSync(join(tmpdir(), "wp-codebox-phpunit-cache-args-")), "probe.php")
327+
writeFileSync(phpunitArgsProbe, `<?php
328+
function pg_log($message) {}
329+
${phpunitArgsFunction}
330+
echo json_encode(array(
331+
'default' => wp_codebox_phpunit_args(array('phpunit')),
332+
'redirected' => wp_codebox_phpunit_args(array('phpunit', '--cache-result-file=/tmp/wp-codebox-phpunit.result.cache')),
333+
));
334+
`)
335+
const phpunitArgs = JSON.parse(execFileSync("php", [phpunitArgsProbe], { encoding: "utf8" })) as {
336+
default: Record<string, unknown>
337+
redirected: Record<string, unknown>
338+
}
339+
assert.equal(phpunitArgs.default.cacheResult, false, "PHPUnit result caching must be disabled when no sandbox cache path is requested")
340+
assert.equal(phpunitArgs.redirected.cacheResult, true)
341+
assert.equal(phpunitArgs.redirected.cacheResultFile, "/tmp/wp-codebox-phpunit.result.cache")
342+
325343
console.log("phpunit project autoload ok")

0 commit comments

Comments
 (0)