[Dotenv] Start using virtual filesystem in tests #47538
Closed
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.
During the work on Dotenv I was always running into an issue that when I cause test to fail, file/directory cleanup mechanism does not run. Since in such cases file persists between test runs, this causes tests to be permanently broken even after fixing the bug, until file/folder is removed manually. Situation is complicating also a fact that temporary directory is used, which is pretty much non-accessible and completely random on my dev machine (macos).
So I was thinking, why not using VFS? This is precisely what it's designed for, see https://github.com/bovigo/vfsStream/wiki/Example and https://github.com/bovigo/vfs-stream-examples/tree/master/src/part01. Nothing is persisted between tests no matter what, since all the files are in memory. And it might also be faster, since it eliminates I/O.
As for library used, it is pretty mature as I remember it was used back in the days when I was using CodeIgniter 2 and it's still used by them. It has no dependencies, in latest version it supports PHP versions from 7.2 up to 8.2 and is used by projects such as:
and more
I'm targetting 5.4 because there are 0 changes between 5.4 and 6.2 in DotenvTest class, unlike when comparing with 4.4.
As this library wasn't used and I wasn't sure this change is welcome, I've added it to one component only (DotEnv). However, lot of tests in lot of other Symfony components would benefit from this as well.