pekral / test-redundancy
Finds PHPUnit and Pest tests whose covered lines other tests already cover, and shows what each candidate asserts beyond them.
Requires
- php: ^8.4
- ext-libxml: *
- ext-simplexml: *
- ext-zlib: *
- nikic/php-parser: ^5.9
- phpunit/php-code-coverage: ^10.1 || ^11.0 || ^12.0 || ^13.0 || ^14.5.1
- symfony/console: ^6.4 || ^7.0 || ^8.1.11
- symfony/filesystem: ^6.4.3 || ^7.0.3 || ^8.1.11
- symfony/finder: ^6.4 || ^7.0 || ^8.1.11
- symfony/process: ^6.4 || ^7.0 || ^8.1.10
Requires (Dev)
- ergebnis/composer-normalize: ^2.56.0
- laravel/pint: ^1.32.1
- pekral/ai-olympus: ^0.1.3
- pekral/phpcs-rules: ^0.4.8 || ^0.5
- pekral/phpstan-rules: ^0.4.5
- pekral/rector-rules: ^0.6 || ^0.7
- pestphp/pest: ^3.0 || ^4.0 || ^5.3.5
- phpstan/phpstan-deprecation-rules: >=2.0.5
- phpstan/phpstan-phpunit: ^2.1.1
- roave/security-advisories: dev-latest
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
test-redundancy
test-redundancy finds the tests in a PHPUnit or Pest suite whose covered lines other tests already cover, and shows
what each of them asserts beyond those tests. It runs the tests once with per-test coverage and gives every candidate an
action: delete it, merge it into a dataset, review it, or keep it as the only test of an error path. The JSON output is
built for AI agents; --format=text is built for people.
Requirements
| Version | |
|---|---|
| PHP | ^8.4 with ext-libxml, ext-simplexml and ext-zlib |
phpunit/php-code-coverage |
^10.1, ^11, ^12, ^13 or ^14.5.1 — the one your PHPUnit or Pest installs |
| Coverage driver | pcov (the tool limits pcov.directory to the source directories) or xdebug |
| Test runner | vendor/bin/pest or vendor/bin/phpunit |
Installation
composer require --dev pekral/test-redundancy
The tool keeps its local state (the coverage map, the baseline, the file durations and the runner cache) in
.test-redundancy/. Add it to .gitignore:
echo ".test-redundancy/" >> .gitignore
Configuration
Optional. Without a test-redundancy.json in the project root, the tool reads src/ and app/, runs 2 parallel
processes, and picks vendor/bin/pest when it exists, otherwise vendor/bin/phpunit. The keys source, ignore,
env, processes, map and runner are described in Configuration.
Quick start
-
Analyse a test folder and read the report:
vendor/bin/test-redundancy tests/Unit/Billing --format=text
[!WARNING] The tests always run in parallel, on the test tokens 1…
processes. Never start the tool next to another run of the same suite. -
Act on each candidate, from the top: the report puts the slowest candidates first. Follow its
steps, see How to read a candidate. -
Verify that every source line the analysed tests covered is still covered:
vendor/bin/test-redundancy verify
verifyexits with1and lists the lost lines when a change dropped coverage.
Without a path, analyse takes the test files the branch changes against origin/HEAD, or against --base.
vendor/bin/test-redundancy analyse --help lists every option.
What it does
- Finds candidates: test cases whose covered lines other test cases already cover, every dataset row separately.
- Compares contracts, not only lines:
differsBylists the literals, calls and keys a candidate has and its covering test lacks. - Says what to do: every candidate has an
actionand numberedsteps; a test of an error path that no covering test asserts is markedkeep. - Starts where it pays: files and candidates are ordered by the time each candidate took, so the slowest redundant tests come first.
- Proves nothing was lost:
verifyfails when a source line the last analysis covered is no longer covered. - Compares across files:
mapbuilds a per-test coverage map, andanalyse --acrosscompares with every mapped test.
Documentation
- Usage: commands, options, how the tool runs your tests, configuration,
verifyand--across. - Reading the report: the actions, the JSON fields, error paths, input combinations, failed tests and skipped files.
- Reference: the exact rules for
deleteandmerge-into-dataset, howdiffersBynames a difference, and how the analysis works. - Development: the Composer scripts and the CI matrix.
Testing
Contributing needs PHP 8.4+ with pcov.
composer install
composer test
composer check runs the full quality gate: Composer normalize, PHPCS, Pint, Rector, PHPStan, the security audit and
the tests with 100% coverage.
Changelog
See CHANGELOG.
Contributing
See CONTRIBUTING.
Security
See the security policy.
License
MIT. See LICENSE.