Set event subscriber priority for failure events #6586
Merged
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.
Problem
In a module I want to handle failures and see whether fail-fast is enabled or not. For example, extending the
Doctrine2
module to not cleanup when fail-fast is enabled so the state of the Doctrine data store can be introspected after a failure has occurred.As it stands, modules catch
Events::TEST_FAIL
andEvents::TEST_ERROR
before theFailFast
subscriber because modules are configured first.A simple dump of the EventDispatcher's set of listeners for
test.fail
shows:Solution
As event subscribers have been configured without a priority the order is determined by the order in which they are added to the event dispatcher's subscriber. As per the Symfony docs a priority can be set for event subscribers.
By setting a higher positive number we ensure
FailFast
is called first when theEvents::TEST_FAIL
andEvents::TEST_ERROR
events are triggered.With my change I can ensure that the
ResultAggregator
has been configured to stop in the event that fail-fast has been enabled, and in turn I can see that in my own Codeception modules and handle it appropriately.