I've wrote a browser based test for the contributed module, code can be seen here, when I run test in terminal I get following error

./vendor/bin/phpunit   --configuration /home/sharique/Projects/drupal/d8/d8contrib/core/phpunit.xml --filter "/::testReadOnlyModeEnabled( .*)?$/" Drupal\Tests\readonlymode\Functional\ReadOnlyModeTest /home/sharique/Projects/drupal/d8/d8contrib/modules/porting/readonlymode/tests/src/Functional/ReadonlymodeTest.php -v
PHPUnit 4.8.36 by Sebastian Bergmann and contributors.

Runtime:        PHP 7.1.10 with Xdebug 2.5.5
Configuration:  /home/sharique/Projects/drupal/d8/d8contrib/core/phpunit.xml

Testing Drupal\Tests\readonlymode\Functional\ReadOnlyModeTest

Time: 2 minutes, Memory: 6.00MB

There was 1 error:

1) Drupal\Tests\readonlymode\Functional\ReadOnlyModeTest::testReadOnlyModeEnabled
Exception: User warning: mkdir(): Permission Denied
Drupal\Component\PhpStorage\FileStorage->createDirectory()() (Line: 173)


Tests: 1, Assertions: 1, Errors: 1.

Same error when running from PhpStorm

  • 1
    Have you confirmed the user executing that test has permissions to write to the folder it's complaining about?
    – Clive
    Jan 9, 2018 at 16:06
  • I get this a lot too, and I think I have a question on here about it but can’t find it at the moment.
    – Kevin
    Jan 9, 2018 at 16:42
  • yes, the user permissions are correct.
    – Sharique
    Jan 9, 2018 at 17:31
  • The operating system doesn't really seem to agree with you - what folder is it trying to create a folder in, who owns that folder, what mode does it and its content have, and what user executes the test script?
    – Clive
    Jan 9, 2018 at 20:01
  • I think it is trying to create folder in "sites/simpletest/", User is correct.
    – Sharique
    Jan 10, 2018 at 8:35

2 Answers 2


Maybe the Permission problems section of Running PHPUnit tests can help you:

Note: functional tests have to be invoked with a user in the same group as the web server user. You can either configure Apache (or nginx) to run as your own system user or run tests as a privileged user instead.

To develop locally, a straightforward - but also less secure - approach is to run tests as your own system user. To achieve that, change the default Apache user to run as your system user. Typically, you'd need to modify /etc/apache2/envvars on Linux or /etc/apache2/httpd.conf on Mac.

Example for Linux:

export APACHE_RUN_USER=<your-user>
export APACHE_RUN_GROUP=<your-group>

If the default user is e.g. www-data, the above functional tests will have to be invoked with sudo instead:

export SIMPLETEST_DB='mysql://root@localhost/dev_d8'
export SIMPLETEST_BASE_URL='http://d8.dev'
sudo -u www-data -E ./vendor/bin/phpunit -c core --testsuite functional
sudo -u www-data -E ./vendor/bin/phpunit -c core --testsuite functional-javascript

The other answer didn't help me. I had the simpletests folder with 777 permissions. I ran the tests as root, or as www-data. It didn't matter. The only fix that worked for me was found at the end of core/tests/README.md:

If you have permission problems accessing files after running tests, try putting

$settings['file_chmod_directory'] = 02775;

in your settings.php or local.settings.php file.

That fixed it for me, finally. Then, for example, I can run

/var/www/html$ ./vendor/bin/phpunit -c core/phpunit.xml core/path/to/test/some/file.php

Since it's for running tests in a local development environment set up inside a Docker image, the most important thing is getting it all to run successfully, and this is what got it to work for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.