Repository navigation
Allow expectOutputString() and expectOutputRegex() to be combined and repeated - #6701
Closed
sebastianbergmann wants to merge 1 commit into
Closed
sebastianbergmann wants to merge 1 commit into
sebastianbergmann wants to merge 1 commit into
Conversation
sebastianbergmann
force-pushed
the
multiple-output-expectations
branch
from
June 4, 2026 06:06
b970e7f to
80d86d9
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6701 +/- ##
=========================================
Coverage 97.25% 97.25%
- Complexity 8694 8699 +5
=========================================
Files 868 868
Lines 26633 26641 +8
=========================================
+ Hits 25901 25909 +8
Misses 732 732 ☔ View full report in Codecov by Harness. |
sebastianbergmann
added a commit
to sebastianbergmann/phpunit-documentation-english
that referenced
this pull request
Jun 5, 2026
staabm
pushed a commit
to staabm/phpunit
that referenced
this pull request
Jul 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously, the two methods for configuring an expectation on output silently replaced one another:
expectOutputString()(orexpectOutputRegex()) more than once kept only the last valueThis meant a configured expectation on the output could be discarded without any indication, and a test could pass even though one of its output expectations was never checked.
Since bebab12, this discarding when
expectOutputString()andexpectOutputRegex()are combined or repeated in no longer silent.The changes proposed here make output expectations additive: every call to
expectOutputString()andexpectOutputRegex()contributes an expectation, and the output must satisfy all of them:The single case that cannot be satisfied, expecting the output to be identical to two different strings, is reported with a PHPUnit warning explaining the conflict, since no output can ever fulfil it.
This is a behavioural change: a test that previously passed only because an earlier output expectation was silently discarded may now fail, because that expectation is finally being verified. In practice such tests were already not testing what they appeared to.