[12.x] Add attributes for marking setUp and tearDown lifecycle hooks in traits #56862
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.
Inspired by #56518, this PR aims to introduce
SetUp
andTearDown
attributes for (trait) methods, that allow executing them during the respective hook calls in a test lifecycle. This allows for more flexibility on these kind of methods, e.g. no longer requiring exact name matching.To illustrate the usage, it has also been added to the
WithConsoleEvents
trait.Implementation choices:
Before
andAfter
PHPUnit attributes (see also https://docs.phpunit.de/en/12.3/attributes.html#before) already introduce very similar possibilities, so it's also an option to prefer thosePotential follow-ups:
setUpTraits
; this would likely require some additional mechanism to enforce correct order of executing hooksWithRedis
trait, although its setUp and tearDown hooks are seemingly called in two different ways (right away vs. hooked to test application lifetime)