You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Exit with non-zero exit code when explicit test selection (--filter, --group, --testsuite) yields no tests #6276
thanks for the examples. that indeed proves that my initial problem is actually not the same as the feature --fail-on-empty-test-suite seems to provide.
I think its a DX problem that PHPUnit reports a "success" result when its instructed to run with a certain filter but no tests match such filter. it would be useful for any tool (KI Agent, CI Job, batch file,..) invoking phpunit that no tests were run (by default, without an additional required config flag)
changed the title [-]`--filter FilterWhichDoesNotMatchAnything` should exit with non-zero exit code[/-][+]Exit with non-zero exit code when explicit test selection (--filter, --group, --testsuite) yields no tests[/+]on Apr 12, 2026
changed the title [-]Exit with non-zero exit code when explicit test selection (--filter, --group, --testsuite) yields no tests[/-][+]Exit with non-zero exit code when explicit test selection (`--filter`, `--group`, `--testsuite`) yields no tests[/+]on Apr 12, 2026
When --filter, --exclude-filter, --group, --exclude-group, --testsuite, or --exclude-testsuite is used and no tests match, PHPUnit now exits with exit code 1 instead of 0.
The change is a one-line modification in ShellExitCodeCalculator: the default value of $failOnEmptyTestSuite is set to true when any of those options are active, instead of unconditionally false. This means the existing failOnEmptyTestSuite logic kicks in automatically when explicit test selection yields no results.
--do-not-fail-on-empty-test-suite (and doNotFailOnEmptyTestSuite="true" in XML) still overrides this and restores exit code 0, so there is an escape hatch for anyone who needs the old behavior.
Without any filter/group/testsuite selection, empty test suites continue to exit with 0, no change in behavior there.
Activity
staabm commentedon Jul 15, 2025
I think the same should be true for
--testsuiteand--groupbased filters:kubawerlos commentedon Jul 15, 2025
What about running without any parameters and still getting "No tests executed!" (because of no tests)?
What about a simple relation, "No tests executed!" -> "a non-zero exit code"?
staabm commentedon Jul 15, 2025
this might work, too.
I tried to talk about my actual use-cases. but it might work for a more general case.
not sure about possible BC impact though.
joteejotee commentedon Jul 16, 2025
I'd like to work on this issue if nobody else is working on it.
staabm commentedon Jul 16, 2025
We have no signal from Sebastian yet whether a fix would be accepted (he is on vacation atm).
But if you want to work on it - go ahead.
joteejotee commentedon Jul 16, 2025
That makes sense—since we haven’t heard Sebastian’s opinion yet, I’ll hold off for now. Thanks for letting me know!
stof commentedon Jul 18, 2025
There is already a
--fail-on-empty-test-suiteconfig setting (the XML config file also supports it). Isn't it solving that need already ?staabm commentedon Jul 18, 2025
thanks, wasn't aware of
--fail-on-empty-test-suite.I think the behaviour of
--fail-on-empty-test-suiteshould be the default for--filter(or maybe even in general).stof commentedon Jul 18, 2025
@staabm just set
failOnEmptyTestSuite="true"in your XML config file (orfailOnAllIssues="true").Right now, none of the
failOn*setting defaults to true, so this is consistent.staabm commentedon Jul 25, 2025
thanks for the examples. that indeed proves that my initial problem is actually not the same as the feature
--fail-on-empty-test-suiteseems to provide.I think its a DX problem that PHPUnit reports a "success" result when its instructed to run with a certain filter but no tests match such filter. it would be useful for any tool (KI Agent, CI Job, batch file,..) invoking phpunit that no tests were run (by default, without an additional required config flag)
[-]`--filter FilterWhichDoesNotMatchAnything` should exit with non-zero exit code[/-][+]Exit with non-zero exit code when explicit test selection (--filter, --group, --testsuite) yields no tests[/+][-]Exit with non-zero exit code when explicit test selection (--filter, --group, --testsuite) yields no tests[/-][+]Exit with non-zero exit code when explicit test selection (`--filter`, `--group`, `--testsuite`) yields no tests[/+]Closes #6276
sebastianbergmann commentedon Apr 12, 2026
When
--filter,--exclude-filter,--group,--exclude-group,--testsuite, or--exclude-testsuiteis used and no tests match, PHPUnit now exits with exit code1instead of0.The change is a one-line modification in
ShellExitCodeCalculator: the default value of$failOnEmptyTestSuiteis set totruewhen any of those options are active, instead of unconditionallyfalse. This means the existingfailOnEmptyTestSuitelogic kicks in automatically when explicit test selection yields no results.--do-not-fail-on-empty-test-suite(anddoNotFailOnEmptyTestSuite="true"in XML) still overrides this and restores exit code0, so there is an escape hatch for anyone who needs the old behavior.Without any filter/group/testsuite selection, empty test suites continue to exit with
0, no change in behavior there.Merge branch '12.5' into 13.1
Merge branch '13.1'
Closes #6276
Merge branch '12.5' into 13.1
Merge branch '13.1'
Fix tests that may trigger failures for empty test suites
fix: tolerate empty Functional test suite (PHPUnit 12.5.18+)