wodby / drupal-php

PHP docker container image for Drupal
https://wodby.com/stacks/drupal
MIT License
60 stars 81 forks source link

Unable to run PHPUnit tests inside the containers #52

Closed mxr576 closed 6 years ago

mxr576 commented 6 years ago

After the latest changes introduced in the PHP 7.1-4.1.0 I am unable to run Drupal 8's PHPunit tests inside the container because all Functional/Kernel tests fails with the following error.

Exception: User warning: mkdir(): Permission Denied
Drupal\Component\PhpStorage\FileStorage->createDirectory()() (Line: 173)

Checked the path, it complains about the sites/simpletest/45573929/files/php and sites/simpletest/45573929/files owned by wodby:wodby.

mxr576 commented 6 years ago

Little more context...

/var/www/html $ php vendor/bin/phpunit -c core --group failing -v --debug --printer '\Drupal\Tests\Listeners\HtmlOutputPrinter'
PHPUnit 6.5.7 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.1.14
Configuration: /var/www/html/core/phpunit.xml.dist

Testing 
.......

Time: 26.89 seconds, Memory: 572.00MB

There was 1 error:

1) Drupal\Tests\......
Exception: User warning: mkdir(): Permission Denied sites/simpletest/13063360/files/php www-data
Drupal\Component\PhpStorage\FileStorage->createDirectory()() (Line: 173)

/var/www/html/core/lib/Drupal/Core/Test/HttpClientMiddleware/TestHttpClientMiddleware.php:51
/var/www/html/vendor/guzzlehttp/promises/src/Promise.php:203
/var/www/html/vendor/guzzlehttp/promises/src/Promise.php:156
/var/www/html/vendor/guzzlehttp/promises/src/TaskQueue.php:47
/var/www/html/vendor/guzzlehttp/promises/src/Promise.php:246
/var/www/html/vendor/guzzlehttp/promises/src/Promise.php:223
/var/www/html/vendor/guzzlehttp/promises/src/Promise.php:267
/var/www/html/vendor/guzzlehttp/promises/src/Promise.php:225
/var/www/html/vendor/guzzlehttp/promises/src/Promise.php:62
/var/www/html/vendor/guzzlehttp/guzzle/src/Client.php:131
/var/www/html/vendor/fabpot/goutte/Goutte/Client.php:155
/var/www/html/vendor/symfony/browser-kit/Client.php:312
/var/www/html/vendor/behat/mink-browserkit-driver/src/BrowserKitDriver.php:144
/var/www/html/vendor/behat/mink/src/Session.php:148
/var/www/html/core/tests/Drupal/Tests/BrowserTestBase.php:333
/var/www/html/core/tests/Drupal/Tests/BrowserTestBase.php:484
/opt/drupal-module/tests.........

ERRORS!
Tests: 1, Assertions: 1, Errors: 1.
/var/www/html $ ls -lah sites/simpletest/13063360/files
total 20
drwxrwxrwx    4 wodby    wodby       4.0K Feb 28 20:09 .
drwxrwxrwx    5 wodby    www-data    4.0K Feb 28 20:09 ..
-rwxrwxrwx    1 wodby    wodby        487 Feb 28 20:09 .htaccess
drwxrwxrwx    3 wodby    wodby       4.0K Feb 28 20:09 config_JG3Qir--iQ-_BxpGOd3lM2aO8Naty742uC6vQHG-KLvBJ2az30yCQcpqQILf_jDInR--CQ56oA
drwxrwxrwx    2 wodby    wodby       4.0K Feb 28 20:09 styles
mxr576 commented 6 years ago

As a temporary "solution" I could solve this problem by restoring www-data's wodby group membership.

Related documentation page on Drupal.org: https://www.drupal.org/node/244924

csandanov commented 6 years ago

Have you tried to run it via sudo as mentioned in https://www.drupal.org/docs/8/phpunit/running-phpunit-tests? In -dev images sudo allowed for all commands for wodby user

mxr576 commented 6 years ago

I think for that a similar rule like this is missing from sudoers, if I would like to execute tests as www-data in a shell script.

wodby ALL=(www-data:ALL) NOPASSWD:SETENV:ALL

or should I use the sudo -u root -E sudo -u www-data -E whoami syntax?

jessegrunert commented 6 years ago

Take a look at this: https://www.drupal.org/project/drupal/issues/2867042 I think that may be what you're running up against.

mxr576 commented 6 years ago

Solved by using "dev" images and running test with sudo -u root -E sudo -u www-data -E vendor/bin/phpunit ...