Problem/Motivation
After I ran all the unit tests in 9.3.x on my local machine, I noticed that there is ./vfs: empty directory in the project root, next to the ./index.php.
I knew that one of the test must be guilty of that which uses \org\bovigo\vfs\vfsStream, but it took me a while to figure it out which one it is exactly.
That ./vfs: directory also means that, that test does something else that it is intended to do.
\Drupal\Tests\Component\PhpStorage\FileStorageTest::testCreateDirectoryFailWarning
There are several problem with this test, all of them are closely related to each other, so hard to separate them.
1. always passes
To change the permission 0200 to anything else in the following line does nothing.
$directory = new vfsStreamDirectory('permissionDenied', 0200);. The test always passes green.
2. $directory hasn't added to the root vfs structure
$directory hasn't added to the root VFS structure. I am not 100% sure about this, but I think this means that this directory is not exists (and it behaves like that). In other words, the root vfs structure does not know about this directory.
3. \dirname() and vfs://foo aren't best friends
When the FileStorage::save() is called to store a file, it tries to create all the missing/necessary parent directories. But not in one go with \mkdir('/a/b/c', 0755, TRUE); recursively. It does it one by one in a recursive manner.
If the input is vfs://permissionDenied/test/subdirectory/foo.php then all the parent directories are missing (check point 2. not added to the vfs:// structure).
By using \dirname() the parents are the follows:
vfs://permissionDenied/test/subdirectory/foo.phpvfs://permissionDenied/test/subdirectoryvfs://permissionDenied/testvfs://permissionDeniedvfs:.this one is the first one which exists (obviously).
So first it creates a ./vfs: directory. (success)
Next it tries to create vfs://permissionDenied (fail), because it is outside of the root vfs:// structure. Not because there is some kind of chmod permission problem.
4. With proper vfs:// usage
When I change the test to properly use the vfs:// then the test always fails, because it is always able to create all the parent directories and save the file content, so trigger_error('mkdir(): Permission Denied', E_USER_WARNING); never called.
Maybe I doing something wrong or there is some kind of limitation in the chmod handling of vfs that I don't know of.
In some cases the \dirname() behaves very strangely, this is why \Webmozart\PathUtil\Path::getDirectory() has a solution for those problems.
Very likely the FileStorage works very well in the real life, but this test definitely doesn't simulate a real life situation.
Steps to reproduce
phpunit --filter='testCreateDirectoryFailWarning' './core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php'
The expected result of this issue is not have a dangling ./vfs: directory in the project root (or anywhere else).
Comments
Comment #2
cilefen commentedA test that can't fail? I love it!