Set event subscriber priority for failure events#6586
Merged
Naktibalda merged 2 commits intoCodeception:5.0from Oct 21, 2022
Merged
Set event subscriber priority for failure events#6586Naktibalda merged 2 commits intoCodeception:5.0from
Naktibalda merged 2 commits intoCodeception:5.0from
Conversation
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Doctrine2module 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_FAILandEvents::TEST_ERRORbefore theFailFastsubscriber because modules are configured first.A simple dump of the EventDispatcher's set of listeners for
test.failshows: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
FailFastis called first when theEvents::TEST_FAILandEvents::TEST_ERRORevents are triggered.With my change I can ensure that the
ResultAggregatorhas 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.