Skip to content

feat: let a shard unit bundle several test classes - #1829

Open
maks-oleksyuk wants to merge 1 commit into
pestphp:5.xfrom
maks-oleksyuk:pr/shard-units
Open

feat: let a shard unit bundle several test classes#1829
maks-oleksyuk wants to merge 1 commit into
pestphp:5.xfrom
maks-oleksyuk:pr/shard-units

Conversation

@maks-oleksyuk

@maks-oleksyuk maks-oleksyuk commented Aug 7, 2026

Copy link
Copy Markdown

--shard splits test classes and weighs each one on its own. That holds while a test class is the whole unit of work, but not when the work a shard has to do spans several of them: splitting those classes across shards duplicates the work and leaves every shard with a partial result.

Mutation testing is the case that needs this. A mutation belongs to a source file, several test classes can cover that file, so the file is the unit and its covering test classes have to travel together. Related to #1691.

What changed

Shard::useTimings() accepts a richer value. Instead of a duration per test class, a unit may be ['time' => float, 'tests' => list<string>] under any key. A bare float still means a test class bundling only itself, so an existing shards.json and the behaviour of a plain --update-shards run are unchanged.

LPT partitioning now runs over units, and the --filter a shard receives is the union of the test classes its units bundle. Shard::selectedUnits() exposes the keys allocated to the current shard, so a plugin can narrow the work it generates to match.

Shard::useTimings() also takes optional metadata, stored next to the units and read back through Shard::metadata(). That lets a plugin carry a reference value from the unsharded run that produces the file into the sharded runs that consume it.

Three smaller fixes ride along. The timings file is written when a plugin supplied the units and the run exits non-zero, so a job whose only purpose is to record timings is not lost to an unrelated failure. The count reported by --update-shards now matches the number of entries actually written. The --list-tests subprocess no longer inherits --coverage arguments.

Testing

tests/Unit/Plugins/Shard.php covers unit normalisation, partitioning that keeps a bundle intact, both file shapes on read and write, precedence of plugin-supplied units, and the zero entries written for test classes that produced no work of their own.

Follow-ups

The plugin side that consumes this API lands in pestphp/pest-plugin-mutate#40, with the timeout it depends on in pestphp/pest-plugin-mutate#41. Together with #40 this closes the request in #1691.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.

1 participant