Skip to content

feat(php): add PHPUnit support with compact output (65%+ token savings)#874

Open
Beninho wants to merge 1 commit intortk-ai:masterfrom
Beninho:feat/phpunit-support
Open

feat(php): add PHPUnit support with compact output (65%+ token savings)#874
Beninho wants to merge 1 commit intortk-ai:masterfrom
Beninho:feat/phpunit-support

Conversation

@Beninho
Copy link

@Beninho Beninho commented Mar 26, 2026

Summary

  • New rtk phpunit command with a state-machine output filter (65%+ token savings)
  • Supports all PHPUnit invocation variants: phpunit, vendor/bin/phpunit, bin/phpunit (Symfony), php vendor/bin/phpunit, php bin/phpunit

Changes

File Change
src/phpunit_cmd.rs New module — state-machine filter, binary detection, tee integration
src/main.rs Routing, doc comment, is_operational_command registration
src/discover/rules.rs PATTERNS regex + RtkRule with 5 rewrite prefixes
src/discover/registry.rs 10 classify/rewrite tests for all variants
tests/fixtures/phpunit_raw.txt Realistic fixture (PHPUnit 10, 110 tests, 1 failure)
scripts/test-all.sh PHP section (conditional on phpunit/vendor/bin presence)
README.md Quick-ref line + hook mapping table entry
CHANGELOG.md [Unreleased] feature entry

Filter design

State machine: Header → Failures → Done

PHPUnit 10.5.0 ...          ← stripped (Header state)
Runtime: PHP 8.2.0          ← stripped
.F.......  100/100 (100%)   ← stripped
Time: 00:01:23, Memory: ... ← stripped
There was 1 failure:        ← triggers Failures state
1) UserTest::testEmail      ← captured
Failed asserting ...        ← captured (up to 2 detail lines)
/path/to/test:42            ← captured
FAILURES!                   ← triggers Done state
Tests: 110, Assertions: 340, Failures: 1.  ← parsed for summary

Output:

PHPUnit: 110 tests, 340 assertions, 1 failures
═══════════════════════════════════════
Failures:
1. 1) UserTest::testEmail
   Failed asserting that false is true.
   /path/to/test:42

Test plan

  • cargo test --all — 1134 passed, 0 failed
  • cargo fmt --all && cargo clippy --all-targets — clean for updated files. See src/rake_cmd.rs:18:31
  • Token savings test asserts ≥65% on realistic fixture
  • All 5 invocation variants tested for classify + rewrite
  • Manual: rtk phpunit --help shows description
  • Manual: hook rewrites phpunit tests/rtk phpunit tests/

- New `rtk phpunit` command: state-machine filter that captures test
  names, assertion messages, and file locations from PHPUnit output,
  stripping version banner, progress dots, timing, and memory noise
- Supports all invocation variants: `phpunit`, `vendor/bin/phpunit`,
  `bin/phpunit` (Symfony), `php vendor/bin/phpunit`, `php bin/phpunit`
- Binary detection priority: global phpunit → bin/phpunit → vendor/bin/phpunit
- Registers in discover/rules.rs for `rtk discover` and hook rewriting
- 17 tests: 7 filter tests (including token savings ≥60%), 10 registry
  tests for classify/rewrite across all variants; real fixture in
  tests/fixtures/phpunit_raw.txt
- "OK (X tests, Y assertions)" → already worked, now also shows
  counts for the generic fallback path
- "OK, but incomplete, skipped, or risky tests!" → new handler
  shows skipped count (e.g. "PHPUnit: 9 tests, 15 assertions, 2 skipped")
- Generic fallback now calls parse_counts to show test/assertion
  counts instead of bare "PHPUnit: OK"
- parse_counts returns 4-tuple (tests, assertions, failures, skipped)
  to support Skipped: field with trailing-period stripping
- 3 new tests covering each success variant
- catch segfault + Fatal error
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Benjamin LETELLIER seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

2 participants