-
Notifications
You must be signed in to change notification settings - Fork 11.7k
[12.x] Add disableConfigCache method to the WithCachedConfig trait
#57790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
SanderMuller
wants to merge
1
commit into
laravel:12.x
Choose a base branch
from
SanderMuller:add-disable-test-cache-config
base: 12.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+17
−2
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you want to remove the current cached config, since the next test which wants a cached config will have to build it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why, but without this my tests still fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you ever envision even one test in a class still wanting the original cached config?
While I know it's not pretty, I wonder if you could just override
setUpWithCachedConfig()andmarkConfigCached()for the entire test class, making them no-ops?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potentially, though it's possible to isolate these kind of tests.
But I can also imagine more Laravel devs having the need to have some kind of config testing, which conflicts with this caching, but still wanting to by-default cache the config, and having an option to disable it for a single test. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This technically works, but the devex feels a little unusual, and it's got some footguns in it.
We could add a property check like this, but it doesn't really offer the flexibility to set it on a per-test basis since it happens in TestCase@setUp():
You might be better off just adding a method like:
With that method, you could call it at the start of each test method, rather than in the test setUp.
Let me know your thoughts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree about the devex, and think the
->withFreshConfig()API feels much better.The proposed implementation worked for most of my use-cases, however not all. It seems that this doesn't refresh the config of packages (I guess it doesn't merge them in), at least I am getting an exception when running a test where
config('request-factories')returnsnullin the following snippet:If I call
$this->refreshApplication();after$this->withFreshConfig()then the test passes again (not sure if that info helps)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that makes sense. Config is merged when the Provider is booted, which would explain why it's not working that way.