What Happened
The --shard option silently ignores test classes whose fully-qualified name does not start with Tests\. This affects any project with test files outside the standard tests/ directory — such as modular Laravel applications with test directories like app-modules/*/tests/.
Root Cause
In src/Plugins/Shard.php, the allTests() method parses --list-tests output with this regex:
preg_match_all('/ - (?:P\\\\)?(Tests\\\\[^:]+)::/', $output, $matches);
This hardcodes that the class identifier after the P\ prefix must start with Tests\. However, when tests live outside the tests/ directory, Pest generates path-based identifiers like:
- P\Appmodules\ai\tests\Tenant\Actions\SomeTest::__pest_evaluable_...
After stripping P\, the remaining identifier starts with Appmodules\, not Tests\, so the regex never matches.
Impact
In my project:
- 2540 total test cases in the Tenant suite
- 189 matched by the regex (tests in
tests/Tenant/)
- 2351 silently dropped (tests in
app-modules/*/tests/Tenant/)
The shard reports "16 files ran, out of 16" because it only sees 16 test files total. The remaining ~90% of the test suite is invisible to sharding — they either all run unsharded in every shard (wasting CI time) or are filtered out entirely by the --filter argument.
There is no warning or error indicating that tests were missed.
Expected Behavior
The regex should match any test class identifier from --list-tests output, not just those namespaced under Tests\. A fix would be:
preg_match_all('/ - (?:P\\\\)?([^:]+)::/', $output, $matches);
How to Reproduce
- Create a project with tests outside
tests/ (e.g. in app-modules/module-name/tests/)
- Configure
phpunit.xml testsuite to include those directories
- Run
pest --testsuite=YourSuite --shard=1/2
- Observe the shard only reports tests from
tests/ — app-module tests are missing
Sample Repository
canyongbs/advisingapp#2549
Pest Version
v4.7.0
PHP Version
8.4
Operation System
macOS
Notes
- Pest v4.7.0
- PHP 8.4
- Laravel modular application with ~40 modules in
app-modules/
What Happened
The
--shardoption silently ignores test classes whose fully-qualified name does not start withTests\. This affects any project with test files outside the standardtests/directory — such as modular Laravel applications with test directories likeapp-modules/*/tests/.Root Cause
In
src/Plugins/Shard.php, theallTests()method parses--list-testsoutput with this regex:This hardcodes that the class identifier after the
P\prefix must start withTests\. However, when tests live outside thetests/directory, Pest generates path-based identifiers like:After stripping
P\, the remaining identifier starts withAppmodules\, notTests\, so the regex never matches.Impact
In my project:
tests/Tenant/)app-modules/*/tests/Tenant/)The shard reports "16 files ran, out of 16" because it only sees 16 test files total. The remaining ~90% of the test suite is invisible to sharding — they either all run unsharded in every shard (wasting CI time) or are filtered out entirely by the
--filterargument.There is no warning or error indicating that tests were missed.
Expected Behavior
The regex should match any test class identifier from
--list-testsoutput, not just those namespaced underTests\. A fix would be:How to Reproduce
tests/(e.g. inapp-modules/module-name/tests/)phpunit.xmltestsuite to include those directoriespest --testsuite=YourSuite --shard=1/2tests/— app-module tests are missingSample Repository
canyongbs/advisingapp#2549
Pest Version
v4.7.0
PHP Version
8.4
Operation System
macOS
Notes
app-modules/