Skip to content

Compact output - #6597

Closed
sebastianbergmann wants to merge 2 commits into
mainfrom
feature/compact-output
Closed

sebastianbergmann wants to merge 2 commits into
mainfrom
feature/compact-output

Conversation

@sebastianbergmann

Copy link
Copy Markdown
Owner

PHPUnit's default output is designed for interactive use in a terminal: it shows progress as each test completes, reports timing and memory usage, and uses color to highlight the outcome. This is useful when you are watching tests run. But it is not always what you want.

When you run tests in a tight feedback loop, when you review test output in a CI log, or when you simply know what you are looking for, the ceremony gets in the way. The progress dots, the percentage counter, the timing line, the colour codes add nothing when all you need is "did it pass, and if not, what broke?"

You can already use --no-progress to suppress the progress output. But that still leaves the timing and memory line, the colour codes, and the verbose result formatting with its numbered lists and prose headers. There is no combination of existing flags that gets you all the way to a clean, minimal output.

--compact is a new output mode that strips PHPUnit's output down to what is actionable:

$ phpunit --compact tests
PHPUnit 13.2.0 by Sebastian Bergmann and contributors.

Runtime: PHP 8.5.5

OK (4699 tests, 13576 assertions)

No progress dots. No timing. No colour codes. When all tests pass, that is all you see.

When something fails, the output focuses on what you need to fix:

$ phpunit --compact tests
PHPUnit 13.2.0 by Sebastian Bergmann and contributors.

Runtime: PHP 8.5.5

FAILURES (23 tests, 42 assertions, 1 failure)

--- FAILURE: ExampleTest::testSomething
Failed asserting that false is true.

/path/to/tests/ExampleTest.php:47

Each defect is a clearly delimited block with the test name, the assertion message, and the file location. Errors are listed before failures, followed by any other issues and in the order that typically matters when you are fixing things.

Like the default output, --compact respects the --display-* flags. By default, only errors, failures, and risky tests are shown. Use --display-deprecations, --display-warnings, --display-incomplete, --display-skipped, or --display-all-issues to see more.

AI-based coding assistants frequently run test suites as part of their workflow. Every token of test output that these tools consume costs context window budget. Progress dots and ANSI colour codes are particularly wasteful because they carry no information an AI agent can act on.

With --compact, a passing test suite with 4699 tests produces 55 tokens instead of 1255: a 96% reduction. For failing suites, the savings are smaller (15-25%) because the failure details themselves are what matters, and both modes include them.

Compact output can be activated with the --compact CLI option or by setting the PHPUNIT_COMPACT_OUTPUT=1 environment variable. The environment variable makes it easy to enable compact output globally for an AI assistant without changing how PHPUnit is invoked.

@sebastianbergmann sebastianbergmann added type/enhancement A new idea that should be implemented feature/test-runner CLI test runner labels Apr 23, 2026
@codecov

codecov Bot commented Apr 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.27%. Comparing base (48c8285) to head (2ceb15b).
⚠️ Report is 3 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #6597      +/-   ##
============================================
- Coverage     96.67%   96.27%   -0.40%     
- Complexity     8074     8161      +87     
============================================
  Files           839      840       +1     
  Lines         24928    25229     +301     
============================================
+ Hits          24098    24289     +191     
- Misses          830      940     +110     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sebastianbergmann
sebastianbergmann deleted the feature/compact-output branch April 26, 2026 07:11
sebastianbergmann added a commit that referenced this pull request Apr 26, 2026
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators May 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

feature/test-runner CLI test runner type/enhancement A new idea that should be implemented

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant