Skip to content

Fix CLI streams in Playground PHP runtimes - #1905

Merged
chubes4 merged 1 commit into
mainfrom
fix/1901-playground-cli-stdout
Jul 20, 2026
Merged

Fix CLI streams in Playground PHP runtimes#1905
chubes4 merged 1 commit into
mainfrom
fix/1901-playground-cli-stdout

Conversation

@chubes4

@chubes4 chubes4 commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • define PHP's standard CLI stream constants at the shared Playground command bootstrap before WordPress and test dependencies load
  • reuse the same stream primitive in the dedicated WP-CLI script instead of maintaining a second copy
  • cover the cli namespace fallback contract in the real Playground PHPUnit integration fixture

Root cause

PHP-WASM does not define the CLI-only global STDIN, STDOUT, or STDERR constants. WP Codebox already polyfilled them for the dedicated wordpress.wp-cli command, but wordpress.phpunit enters through the shared Playground PHP bootstrap instead. Tests that load WP-CLI formatter libraries therefore reached php-cli-tools without global STDOUT.

PHP reports the failed unqualified lookup from namespace cli as the exact fatal:

Error: Undefined constant "cli\\STDOUT"

A Playground probe confirmed both defined('STDOUT') and defined('cli\\STDOUT') were false before this change. The fix defines the global CLI primitive; PHP's normal namespace fallback then resolves unqualified STDOUT in cli code without defining a separate namespaced constant.

Layer ownership

This belongs to WP Codebox's Playground/PHP runtime bootstrap. It does not patch vendored WP-CLI code and does not add a consumer workaround in data-machine-events.

Verification

  • npm run build
  • npm run test:runtime-php-snippets
  • npm exec -- tsx tests/phpunit-project-autoload.test.ts
  • npm run test:playground-phpunit-readonly-cache-integration
  • npm run test:production-boundary-enforcement
  • git diff --check
  • live wordpress.run-php Playground probe: global STDOUT/STDERR are defined resources and unqualified STDOUT resolves inside namespace cli

The broader runtime smoke group also exposed an unrelated pre-existing 25 ms timing assertion failure, tracked separately in #1904.

Closes #1901

@chubes4
chubes4 merged commit c4cb30a into main Jul 20, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Playground PHPUnit runtime lacks STDOUT for WP-CLI formatter tests

1 participant