LoadTest fail due to "chmod(): Operation not permitted" I downloaded and installed a new Drupal 8 site via Composer.
I generated a new module using Drupal Console.
I tried running a phpUnit functional test of the newly generated module, and it keeps failing due to some folder permission:


  Exception: Warning: chmod(): Operation not permitted
  Drupal\Component\PhpStorage\FileStorage->createDirectory()() (Line: 168)


What grind my gears is that it was working OK a few days ago. Something is clearly wrong with my system, I just don't know what that is, or what changed since then.

I'm running a WSL with Apache 2.4.37 (PHP Version 7.2.12-1+ubuntu18.04.1+deb.sury.org+1).

I have all the detailed steps to reproduce the case, my full phpinfo, and some more relevant information in this gist I created.

I spent the last few days browsing for a known solution, and some cases appear to be similar, but none of them seems to hit the spot.

I am using Windows 10.0.17134.407; the tests from the browser are passing. All the files and folders on the project are owned by 'zoio' (user and group); the file permissions for folders and files in modules, sites/default/files, and sites/simpletest are set to 0777.

I tried to follow the tips on this WSL issue, but I just ended up with a different failure, still related to permission and ownership.


  Drupal\Tests\sandbox\Functional\LoadTest::testLoad()
  Exception: User warning: mkdir(): Permission Denied
  Drupal\Component\PhpStorage\FileStorage->createDirectory()() (Line: 174)
   /mnt/c/www/temp/d8_temp/web/core/lib/Drupal/Core/Test/HttpClientMiddleware/TestHttpClientMiddleware.php:51 (...) /mnt/c/www/temp/d8_temp/web/modules/custom/sandbox/tests/src/Functional/LoadTest.php:33
  ERRORS!
  Tests: 1, Assertions: 1, Errors: 1.
The thing is, the chmod wasn't really working.

It was an issue with the mounted drivers in the WSL Ubuntu installation. Based on Stefanos Petrakis' comment, simply trying to unmount and mount the driver with the proper options enabled wouldn't solve the issue by itself. What solved was a bit more drastic:


Factory reset the ubuntu (how-to);
re-mount the driver, with the metadata option included (source):

sudo umount /mnt/c
sudo mount -t drvfs C: /mnt/c -o metadata,uid=1000,gid=1000
Install php, Apache, and everything.


Only then, the phpunit tests did work properly.