Running any tests which extended from BrowserTestBase getting permission denied

Created on 5 April 2017, over 7 years ago
Updated 19 November 2023, about 1 year ago

Problem/Motivation

Running any tests which extended from BrowserTestBase getting permission denied .

Steps to reproduce

  • Run the testNewWorkflow from Drupal\Tests\content_moderation\Functional [Infact any tests that extends the BrowserTestBase] which will throw the following error
  • /usr/local/bin/php /private/var/folders/r_/g2c755t93dq757w_51kbbhx00000gn/T/ide-phpunit.php --configuration /Users/rakeshjames/Sites/drupal/core/phpunit.xml --filter "/::testNewWorkflow( .*)?$/" Drupal\Tests\content_moderation\Functional\ContentModerationWorkflowTypeTest /Users/rakeshjames/Sites/drupal/core/modules/content_moderation/tests/src/Functional/ContentModerationWorkflowTypeTest.php
    Testing started at 5:41 PM ...
    PHPUnit 4.8.35 by Sebastian Bergmann and contributors.
    
    
    Warning: mkdir(): Permission denied
    Drupal\Component\PhpStorage\FileStorage->createDirectory()() (Line: 157)
    
     /Users/rakeshjames/Sites/drupal/core/lib/Drupal/Core/Test/HttpClientMiddleware/TestHttpClientMiddleware.php:44
     /Users/rakeshjames/Sites/drupal/vendor/guzzlehttp/promises/src/Promise.php:203
     /Users/rakeshjames/Sites/drupal/vendor/guzzlehttp/promises/src/Promise.php:156
     /Users/rakeshjames/Sites/drupal/vendor/guzzlehttp/promises/src/TaskQueue.php:47
     /Users/rakeshjames/Sites/drupal/vendor/guzzlehttp/promises/src/Promise.php:246
     /Users/rakeshjames/Sites/drupal/vendor/guzzlehttp/promises/src/Promise.php:223
     /Users/rakeshjames/Sites/drupal/vendor/guzzlehttp/promises/src/Promise.php:267
     /Users/rakeshjames/Sites/drupal/vendor/guzzlehttp/promises/src/Promise.php:225
     /Users/rakeshjames/Sites/drupal/vendor/guzzlehttp/promises/src/Promise.php:62
     /Users/rakeshjames/Sites/drupal/vendor/guzzlehttp/guzzle/src/Client.php:129
     /Users/rakeshjames/Sites/drupal/vendor/fabpot/goutte/Goutte/Client.php:155
     /Users/rakeshjames/Sites/drupal/vendor/symfony/browser-kit/Client.php:315
     /Users/rakeshjames/Sites/drupal/vendor/behat/mink-browserkit-driver/src/BrowserKitDriver.php:144
     /Users/rakeshjames/Sites/drupal/vendor/behat/mink/src/Session.php:148
     /Users/rakeshjames/Sites/drupal/core/tests/Drupal/Tests/BrowserTestBase.php:291
     /Users/rakeshjames/Sites/drupal/core/tests/Drupal/Tests/BrowserTestBase.php:431
     /Users/rakeshjames/Sites/drupal/core/modules/content_moderation/tests/src/Functional/ContentModerationWorkflowTypeTest.php:28
     
    
    
    Time: 7.71 seconds, Memory: 6.00MB
    
    
    FAILURES!
    Tests: 1, Assertions: 1, Errors: 1.
    
    Process finished with exit code 2

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Fixed

Version

8.7 ⚰️

Component
PHPUnit 

Last updated 1 day ago

Created by

🇬🇧United Kingdom rakesh.gectcr Manchester

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇷🇺Russia niklan Russia, Perm

    Finally, found reliable solution for Drupal4Drupal environment.

    Add new environment variables for php container in docker-compose.yml:

      php:
        image: wodby/php:$PHP_TAG
        container_name: "${PROJECT_NAME}_php"
        environment:
          …
          PHP_FPM_USER: wodby
          PHP_FPM_GROUP: wodby
    

    Then rebuild container by docker-compose up -d --no-deps --build php and that's it/ All tests, including Functional, will be run without needing using sudo or anything else. They just run as expected, even from PHPStorm.

  • 🇷🇸Serbia super_romeo Belgrade

    #68 works.
    Thank you @Niklan!

  • 🇺🇦Ukraine quadrexdev Lutsk

    Thanks @Niklan!

    I was struggling with this issue but your solution works like a charm.

  • 🇷🇺Russia Chi

    One possible solution is setting directory permissions manually.

    The attached patch assumes you have the following configuration in settings.php file.

    if ($_SERVER['DRUPAL_FUNCTIONAL_TEST'] ?? FALSE) {
      $settings['file_chmod_directory'] = 0777;
    }
    

    Note, you will still need to set permissions for sites/simpletest/browser_output directory. Also ensure access to SQLite database.

  • 🇷🇺Russia Chi

    Actually, it's better to follow #53 🐛 Running any tests which extended from BrowserTestBase getting permission denied Fixed but use testing.settings.php file instead.

    
    $settings['file_chmod_directory'] = 02777;
    
  • 🇳🇱Netherlands Martijn Houtman

    For me, it was the permission hardening that was setting the simpletest directory to 0555. Simply adding this to default.settings.php worked:

    ```
    $settings['skip_permissions_hardening'] = TRUE;
    ```

Production build 0.71.5 2024