Skip to content

Add PHP CLI working directory support - #4159

Draft
benitoalba wants to merge 1 commit into
WordPress:trunkfrom
benitoalba:fix/3803-php-command-cwd
Draft

Add PHP CLI working directory support#4159
benitoalba wants to merge 1 commit into
WordPress:trunkfrom
benitoalba:fix/3803-php-command-cwd

Conversation

@benitoalba

Copy link
Copy Markdown

Motivation for the change, related issues

The php command currently requires absolute VFS paths for scripts and related configuration, even when a plugin or theme has already been auto-mounted. This makes common commands such as PHPUnit unnecessarily verbose.

Fixes #3803.

Implementation details

  • Add a PHP-command-only --cwd=<vfs-path> option and expose it through RunCLIArgs.
  • Use an explicit CWD when provided; otherwise infer the sole auto-mounted VFS path only when no manual mounts are configured.
  • Pass the CWD together with the PHP CLI invocation so the selected pooled worker changes directory before execution.
  • Preserve the existing default working directory for zero, manual, and ambiguous multi-mount configurations.
  • Report invalid working directories with a descriptive filesystem error.
  • Document php, --cwd, and relative PHPUnit command/configuration paths.

Testing Instructions (or ideally a Blueprint)

npm exec nx -- run playground-cli:test-playground-cli --testFiles=packages/playground/cli/tests/run-cli.spec.ts
npm exec nx -- run playground-cli:test-playground-cli
npm exec nx -- run playground-cli:lint
npm exec nx -- run playground-cli:typecheck
npm exec nx -- run playground-cli:build
npm exec nx -- run php-wasm-universal:lint
npm exec nx -- run php-wasm-universal:typecheck
npm exec prettier -- --check packages/playground/cli/src/run-cli.ts packages/php-wasm/universal/src/lib/php-worker.ts packages/php-wasm/universal/src/lib/php.ts packages/playground/cli/tests/run-cli.spec.ts packages/playground/cli/README.md packages/docs/site/docs/developers/05-local-development/04-wp-playground-cli.md packages/docs/site/docs/main/guides/phpunit-testing.md
git diff --check

The full Playground CLI suite passes with 190 tests passed and 6 platform-specific tests skipped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CLI] Enable users to set the current working directory when using the PHP command

1 participant