Skip to content

[Dotenv] Start using virtual filesystem in tests #47538

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

Closed
wants to merge 1 commit into from

Conversation

ostrolucky
Copy link
Contributor

@ostrolucky ostrolucky commented Sep 10, 2022

Q A
Branch? 6.2
Bug fix? no
New feature? no
Deprecations? no
Tickets
License MIT
Doc PR

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:

  • php-cs-fixer
  • Zend/Laminas
  • CodeIgniter
  • Magento
  • CakePHP
  • JMS
  • phpmd
  • Gaufrette
  • Phing
  • Yasumi

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.

@nicolas-grekas
Copy link
Member

Works for me, I just wouldn't do the change preemptively.
Instead, we should wait for the need on a case by case basis.
I suppose this means we should merge this together with a fix on Dotenv.

@ostrolucky
Copy link
Contributor Author

That fix is probably not coming. But I've at least extracted this out of it. I think that also works, usually people don't like unrelated (refactorings) changes in feature PRs unless necessary, as it's making PR harder to review.

@fabpot
Copy link
Member

fabpot commented Sep 13, 2022

This should be done for 6.2 then.

@nicolas-grekas nicolas-grekas modified the milestones: 5.4, 6.2 Sep 13, 2022
@carsonbot carsonbot changed the title Start using virtual filesystem in tests [Dotenv] Start using virtual filesystem in tests Sep 13, 2022
@ostrolucky ostrolucky changed the base branch from 5.4 to 6.2 September 13, 2022 09:57
@ostrolucky
Copy link
Contributor Author

as you want. rebased

@nicolas-grekas nicolas-grekas modified the milestones: 6.2, 6.3 Nov 5, 2022
@nicolas-grekas nicolas-grekas modified the milestones: 6.3, 6.4 May 23, 2023
@nicolas-grekas
Copy link
Member

Closing as this staled without much traction. We could improve the cleanup mechanism instead I guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants