[8.x] Added a method to the Macroable trait that removes all configured macros. #39633
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.
This pull request adds a static
flushMacros
method to theMacroable
trait that removes all the configured macros.The primary use of this method is in a unit testing environment. When running multiple test cases that add static macros in the same process, there can be side-effects between test cases caused by the use of
static
members.When combined with either the
--random-order
flag to PHPUnit or parallelized testing, these side effects can cause intermittent failures, as tests may or may not pass depending on the order / process they are ran in and the result of the side effects.Ideally each unit test case is ran in a sanitized environment to ensure the developer is testing exactly what they intended to test, and aren't relying on any aspects setup outside of the current test case.
I was unsure as to whether the framework should enforce the running of
flushMacros
on contained Macroable classes, or whether the developer should handle this manually so i haven't done that.Also enforcing that macros are always flushed is a not fully backwards-compatible change, whereas adding a method to allow developers to handle it themselves is.
Thanks for your time.