You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all, I went for this package because the gillion other vfs composer packages seem to be unmaintained or not very mature.
I got the feeling that this library mixes up global/static scope with instances a bit.
For example, looking at the provided sample, I thought vfsStream::setup() would return a vfsStream object, not a vfsDirectory.
After looking at the code, it became obvious: in reality there is only one stream wrapper being registered.
Also, storing the created vfsDirectory instance in a (private) property causes an IDE warning that it seems to not be used (only written once). While it's not a problem, the warning does kinda make sense - there are many ways in PHP to avoid an early deconstruction/dereferencing of objects.
While static classes might be handier to work with, they do encourage the habit of writing bad code - so I'd recommend a singleton approach is a bit better than static. This approach might also open up the possibility of multiple isolated vfs wrappers.
Here's what I imagine it to look like:
class MyClassTest extends TestCase
{
publicfunctiontestThatSomethingWorks(): void
{
$vfs = VfsStream::setUp();
$sut = newMyClass($vfs()); // $vfs() is just a shortcut for url() - since I find that url is an implementation// detail of vfs. There are probably more idiomatic alternatives, like ->get() or so,// whereas the __invoke approach is just a handy shortcut.$sut->doSomething();
$this->assertFileExists($vfs('file-created-by-myclass.txt'));
}
publicfunctiontestThatMultipleVfsWorks(): void
{
$vfs1 = VfsStream::setUp();
$vfs2 = VfsStream::setUp();
file_put_contents($vfs1('test.txt'), 'hello world');
rename($vfs1('test.txt'), $vfs2('test2.txt'));
$this->assertFileDoesNotExist($vfs1('test.txt'));
$this->assertFileExists($vfs2('test2.txt'));
}
This is just my two cents, library is already totally usable as it is.
The text was updated successfully, but these errors were encountered:
First of all, I went for this package because the gillion other vfs composer packages seem to be unmaintained or not very mature.
I got the feeling that this library mixes up global/static scope with instances a bit.
For example, looking at the provided sample, I thought
vfsStream::setup()
would return avfsStream
object, not avfsDirectory
.After looking at the code, it became obvious: in reality there is only one stream wrapper being registered.
Also, storing the created
vfsDirectory
instance in a (private) property causes an IDE warning that it seems to not be used (only written once). While it's not a problem, the warning does kinda make sense - there are many ways in PHP to avoid an early deconstruction/dereferencing of objects.While static classes might be handier to work with, they do encourage the habit of writing bad code - so I'd recommend a singleton approach is a bit better than static. This approach might also open up the possibility of multiple isolated vfs wrappers.
Here's what I imagine it to look like:
This is just my two cents, library is already totally usable as it is.
The text was updated successfully, but these errors were encountered: