What username does PHPStorm take in PHPUnit Testing

Hello,

I configured PHPStorm so that it can run PHPUnit tests for Drupal sites.
In PHPStorm I clicked a button to run a test, then I got the message that the test failed.
Of course, in a PHPStorm window I could see the detailed command line for running PHPUnit like following:

/usr/bin/php7.3 xxx/vendor/phpunit/phpunit/phpunit --bootstrap xxx/core/tests/bootstrap.php --configuration xxx/modules/phpunit.xml --teamcity

Then I copied the command line to a terminal in the OS (Ubuntu), and ran it, and guess what, it passed! So I am very confused with the fact, that the same command line will lead to different results in PHPStorm and in a terminal in Ubuntu.

As I know, for running certain Drupal tests it restricts the user who runs the tests (see following post):
https://www.drupal.org/docs/automated-testing/phpunit-in-drupal/running-phpunit-tests#s-permission-problems

When running the tests in a Ubuntu Terminal, the user is *dev*, with this user the tests are OK.
So I'm wondering if PHPStorm takes an other username when running PHPUnit Tests? If so, what is that?

Thank you very much for your support.

7 comments
Comment actions Permalink

It depends on your PHP Interpreter. Do you have the Drupal site running locally? Or it's a remote box in a Docker or a remote site accessible over SSH?

Are you sure it's related to a user at all? It might be something like this: https://youtrack.jetbrains.com/issue/WI-55428#focus=Comments-27-4390358.0-0

I would suggest checking the logs first. Please open Help > Diagnostic Tools > Debug Log Settings... and add #com.jetbrains.php lines.
Reproduce the issue and share your idea.log file (Help > Show log in ...).

0
Comment actions Permalink

Thank you for your quick response.

Firstly: Drupal site is running locally, not in any containers or remotelly.

I've read the post you mentioned above.
I'm sure the PHPUnit Settings in my PHPStorm were right.
I can run any tests based on PHPUnit\Framework\TestCase in PHPStorm correctly, without the problem I described above.
Problems are only with tests based on Drupal\Tests\BrowserTestBase.

So it's not a problem with the PHPUnit settings.

I've followed your instructions, changed the settings accordingly, and refresh the test.
I'd share the log details below, hopefully you can detect something helpful:

----
2020-09-30 13:22:07,852 [15962945] INFO - lij.diagnostic.DebugLogManager - Set DEBUG for the following categories: #com.jetbrains.php
2020-09-30 13:22:49,172 [16004265] DEBUG - t.PhpUnitLocalRunConfiguration - PHPUnit 7.5.20 was detected. Execute tests with /home/dev/test/drupal-microservices/drupal2/vendor/phpunit/phpunit/phpunit
2020-09-30 13:22:49,225 [16004318] DEBUG - .php.run.filters.PhpUnitFilter - Path mapper: com.jetbrains.php.util.pathmapper.PhpLocalPathMapper@b8d675e
2020-09-30 13:22:49,225 [16004318] DEBUG - ains.php.run.filters.PhpFilter - Path mapper: com.jetbrains.php.util.pathmapper.PhpLocalPathMapper@b8d675e
2020-09-30 13:22:49,226 [16004319] DEBUG - ains.php.run.filters.PhpFilter - Path mapper: com.jetbrains.php.util.pathmapper.PhpIdenticalPathMapper@483e34b0
2020-09-30 13:22:49,226 [16004319] DEBUG - ains.php.run.filters.PhpFilter - Path mapper: com.jetbrains.php.util.pathmapper.PhpIdenticalPathMapper@7ca11e9a
2020-09-30 13:22:49,237 [16004330] DEBUG - ains.php.run.filters.PhpFilter - Path mapper: com.jetbrains.php.util.pathmapper.PhpLocalPathMapper@b8d675e
2020-09-30 13:22:49,237 [16004330] DEBUG - .php.run.filters.PhpUnitFilter - Path mapper: com.jetbrains.php.util.pathmapper.PhpLocalPathMapper@b8d675e
2020-09-30 13:22:49,237 [16004330] DEBUG - ains.php.run.filters.PhpFilter - Path mapper: com.jetbrains.php.util.pathmapper.PhpLocalPathMapper@b8d675e
2020-09-30 13:22:49,266 [16004359] DEBUG - m.jetbrains.php.run.PhpRunUtil - Output: /usr/bin/php7.3 /home/dev/test/drupal-microservices/drupal2/vendor/phpunit/phpunit/phpunit --bootstrap /home/dev/test/drupal-microservices/drupal2/core/tests/bootstrap.php --configuration /home/dev/test/drupal-microservices/drupal2/modules/custom/loremipsum/tests/phpunit.xml --teamcity
2020-09-30 13:22:49,545 [16004638] DEBUG - ains.php.run.filters.PhpFilter - Path mapper: com.jetbrains.php.util.pathmapper.PhpIdenticalPathMapper@3baba4fb
2020-09-30 13:22:49,545 [16004638] DEBUG - ains.php.run.filters.PhpFilter - Path mapper: com.jetbrains.php.util.pathmapper.PhpIdenticalPathMapper@720eb08e
2020-09-30 13:22:49,546 [16004639] DEBUG - .pathmapper.PhpLocalPathMapper - Cache size: 0
2020-09-30 13:22:49,839 [16004932] DEBUG - m.jetbrains.php.run.PhpRunUtil - Output: PHPUnit 7.5.20 by Sebastian Bergmann and contributors.
2020-09-30 13:22:49,839 [16004932] DEBUG - m.jetbrains.php.run.PhpRunUtil - Output:
2020-09-30 13:22:49,839 [16004932] DEBUG - m.jetbrains.php.run.PhpRunUtil - Output:
2020-09-30 13:22:49,839 [16004932] DEBUG - m.jetbrains.php.run.PhpRunUtil - Output: ##teamcity[testCount count='2' flowId='33681']
2020-09-30 13:22:49,839 [16004932] DEBUG - m.jetbrains.php.run.PhpRunUtil - Output:
2020-09-30 13:22:49,839 [16004932] DEBUG - m.jetbrains.php.run.PhpRunUtil - Output: ##teamcity[testSuiteStarted name='functional' flowId='33681']
2020-09-30 13:22:49,840 [16004933] DEBUG - m.jetbrains.php.run.PhpRunUtil - Output:
2020-09-30 13:22:49,840 [16004933] DEBUG - m.jetbrains.php.run.PhpRunUtil - Output: ##teamcity[testSuiteStarted name='Drupal\Tests\loremipsum\Functional\LoremipsumTest' locationHint='php_qn:///home/dev/test/drupal-microservices/drupal2/modules/custom/loremipsum/tests/src/Functional/LoremipsumTest.php::\Drupal\Tests\loremipsum\Functional\LoremipsumTest' flowId='33681']
2020-09-30 13:22:49,841 [16004934] DEBUG - m.jetbrains.php.run.PhpRunUtil - Output:
2020-09-30 13:22:49,841 [16004934] DEBUG - m.jetbrains.php.run.PhpRunUtil - Output: ##teamcity[testStarted name='testLoremIpsumPageExists' locationHint='php_qn:///home/dev/test/drupal-microservices/drupal2/modules/custom/loremipsum/tests/src/Functional/LoremipsumTest.php::\Drupal\Tests\loremipsum\Functional\LoremipsumTest::testLoremIpsumPageExists' flowId='33681']
2020-09-30 13:23:09,083 [16024176] DEBUG - m.jetbrains.php.run.PhpRunUtil - Output:
2020-09-30 13:23:09,083 [16024176] DEBUG - m.jetbrains.php.run.PhpRunUtil - Output: ##teamcity[testFailed name='testLoremIpsumPageExists' message='Behat\Mink\Exception\ElementNotFoundException : Button with id||name||label||value "Log in" not found.'
2020-09-30 13:23:09,083 [16024176] DEBUG - m.jetbrains.php.run.PhpRunUtil - Output: details=' /home/dev/test/drupal-microservices/drupal2/core/tests/Drupal/Tests/WebAssert.php:77|n /home/dev/test/drupal-microservices/drupal2/core/tests/Drupal/Tests/UiHelperTrait.php:77|n /home/dev/test/drupal-microservices/drupal2/core/tests/Drupal/Tests/UiHelperTrait.php:250|n /home/dev/test/drupal-microservices/drupal2/modules/custom/loremipsum/tests/src/Functional/LoremipsumTest.php:40|n ' duration='19026' flowId='33681']
2020-09-30 13:23:09,084 [16024177] DEBUG - m.jetbrains.php.run.PhpRunUtil - Output:
2020-09-30 13:23:09,084 [16024177] DEBUG - m.jetbrains.php.run.PhpRunUtil - Output: ##teamcity[testFinished name='testLoremIpsumPageExists' duration='19026' flowId='33681']
2020-09-30 13:23:09,085 [16024178] DEBUG - m.jetbrains.php.run.PhpRunUtil - Output:
2020-09-30 13:23:09,085 [16024178] DEBUG - m.jetbrains.php.run.PhpRunUtil - Output: ##teamcity[testStarted name='testConfigForm' locationHint='php_qn:///home/dev/test/drupal-microservices/drupal2/modules/custom/loremipsum/tests/src/Functional/LoremipsumTest.php::\Drupal\Tests\loremipsum\Functional\LoremipsumTest::testConfigForm' flowId='33681']
2020-09-30 13:23:29,374 [16044467] DEBUG - m.jetbrains.php.run.PhpRunUtil - Output:
2020-09-30 13:23:29,374 [16044467] DEBUG - m.jetbrains.php.run.PhpRunUtil - Output: ##teamcity[testFailed name='testConfigForm' message='Behat\Mink\Exception\ElementNotFoundException : Button with id||name||label||value "Log in" not found.' details=' /home/dev/test/drupal-microservices/drupal2/core/tests/Drupal/Tests/WebAssert.php:77|n /home/dev/test/drupal-microservices/drupal2/core/tests/Drupal/Tests/UiHelperTrait.php:77|n /home/dev/test/drupal-microservices/drupal2/core/tests/Drupal/Tests/UiHelperTrait.php:250|n /home/dev/test/drupal-microservices/drupal2/modules/custom/loremipsum/tests/src/Functional/LoremipsumTest.php:52|n ' duration='20081'
2020-09-30 13:23:29,374 [16044467] DEBUG - m.jetbrains.php.run.PhpRunUtil - Output: flowId='33681']
2020-09-30 13:23:29,374 [16044467] DEBUG - m.jetbrains.php.run.PhpRunUtil - Output:
2020-09-30 13:23:29,374 [16044467] DEBUG - m.jetbrains.php.run.PhpRunUtil - Output: ##teamcity[testFinished name='testConfigForm' duration='20081' flowId='33681']
2020-09-30 13:23:29,375 [16044468] DEBUG - m.jetbrains.php.run.PhpRunUtil - Output:
2020-09-30 13:23:29,375 [16044468] DEBUG - m.jetbrains.php.run.PhpRunUtil - Output: ##teamcity[testSuiteFinished name='Drupal\Tests\loremipsum\Functional\LoremipsumTest' flowId='33681']
2020-09-30 13:23:29,375 [16044468] DEBUG - m.jetbrains.php.run.PhpRunUtil - Output:
2020-09-30 13:23:29,375 [16044468] DEBUG - m.jetbrains.php.run.PhpRunUtil - Output: ##teamcity[testSuiteFinished name='functional' flowId='33681']
2020-09-30 13:23:29,375 [16044468] DEBUG - m.jetbrains.php.run.PhpRunUtil - Output:
2020-09-30 13:23:29,375 [16044468] DEBUG - m.jetbrains.php.run.PhpRunUtil - Output:
2020-09-30 13:23:29,375 [16044468] DEBUG - m.jetbrains.php.run.PhpRunUtil - Output: Time: 39.71 seconds, Memory: 8.00 MB
2020-09-30 13:23:29,375 [16044468] DEBUG - m.jetbrains.php.run.PhpRunUtil - Output:
2020-09-30 13:23:29,375 [16044468] DEBUG - m.jetbrains.php.run.PhpRunUtil - Output:
2020-09-30 13:23:29,375 [16044468] DEBUG - m.jetbrains.php.run.PhpRunUtil - Output: ERRORS!
2020-09-30 13:23:29,375 [16044468] DEBUG - m.jetbrains.php.run.PhpRunUtil - Output: Tests: 2, Assertions: 12, Errors: 2
2020-09-30 13:23:29,375 [16044468] DEBUG - m.jetbrains.php.run.PhpRunUtil - Output: .
2020-09-30 13:23:29,379 [16044472] DEBUG - m.jetbrains.php.run.PhpRunUtil - Output: Process finished with exit code 2
2020-09-30 13:23:29,662 [16044755] DEBUG - ains.php.run.filters.PhpFilter - Path mapper: com.jetbrains.php.util.pathmapper.PhpIdenticalPathMapper@cb8ed15
2020-09-30 13:23:29,662 [16044755] DEBUG - ains.php.run.filters.PhpFilter - Path mapper: com.jetbrains.php.util.pathmapper.PhpIdenticalPathMapper@12592344
2020-09-30 13:23:29,662 [16044755] DEBUG - .pathmapper.PhpLocalPathMapper - Cache size: 1
2020-09-30 13:23:29,662 [16044755] DEBUG - .pathmapper.PhpLocalPathMapper - Cache size: 1
2020-09-30 13:23:29,663 [16044756] DEBUG - .pathmapper.PhpLocalPathMapper - Cache size: 2
2020-09-30 13:23:29,663 [16044756] DEBUG - .pathmapper.PhpLocalPathMapper - Cache size: 3
2020-09-30 13:23:29,663 [16044756] DEBUG - .pathmapper.PhpLocalPathMapper - Cache size: 3
2020-09-30 13:23:29,663 [16044756] DEBUG - .pathmapper.PhpLocalPathMapper - Cache size: 4
2020-09-30 13:23:29,663 [16044756] DEBUG - .pathmapper.PhpLocalPathMapper - Cache size: 4
2020-09-30 13:23:29,663 [16044756] DEBUG - .pathmapper.PhpLocalPathMapper - Cache size: 4
2020-09-30 13:23:29,663 [16044756] DEBUG - .pathmapper.PhpLocalPathMapper - Cache size: 4

0
Comment actions Permalink

Thanks! The log shows that PHPUnit run successfully: Output: Time: 39.71 seconds, Memory: 8.00 MB, Output: Tests: 2, Assertions: 12, Errors: 2.

What does it show in IDE?

0
Comment actions Permalink

in IDE: the test failed due to the 2 errors (in Ubuntu terminal or PHPStorm terminal: the test passed!)


---
/usr/bin/php7.3 /home/dev/test/drupal-microservices/drupal2/vendor/phpunit/phpunit/phpunit --bootstrap /home/dev/test/drupal-microservices/drupal2/core/tests/bootstrap.php --configuration /home/dev/test/drupal-microservices/drupal2/modules/custom/loremipsum/tests/phpunit.xml --teamcity
PHPUnit 7.5.20 by Sebastian Bergmann and contributors.


Behat\Mink\Exception\ElementNotFoundException : Button with id|name|label|value "Log in" not found.
/home/dev/test/drupal-microservices/drupal2/core/tests/Drupal/Tests/WebAssert.php:77
/home/dev/test/drupal-microservices/drupal2/core/tests/Drupal/Tests/UiHelperTrait.php:77
/home/dev/test/drupal-microservices/drupal2/core/tests/Drupal/Tests/UiHelperTrait.php:250
/home/dev/test/drupal-microservices/drupal2/modules/custom/loremipsum/tests/src/Functional/LoremipsumTest.php:40

Behat\Mink\Exception\ElementNotFoundException : Button with id|name|label|value "Log in" not found.
/home/dev/test/drupal-microservices/drupal2/core/tests/Drupal/Tests/WebAssert.php:77
/home/dev/test/drupal-microservices/drupal2/core/tests/Drupal/Tests/UiHelperTrait.php:77
/home/dev/test/drupal-microservices/drupal2/core/tests/Drupal/Tests/UiHelperTrait.php:250
/home/dev/test/drupal-microservices/drupal2/modules/custom/loremipsum/tests/src/Functional/LoremipsumTest.php:52


Time: 44.64 seconds, Memory: 8.00 MB


ERRORS!
Tests: 2, Assertions: 12, Errors: 2.

Process finished with exit code 2

0
Comment actions Permalink

Just to clarify: if you run exactly the same command (/usr/bin/php7.3 /home/dev/test/drupal-microservices/drupal2/vendor/phpunit/phpunit/phpunit --bootstrap /home/dev/test/drupal-microservices/drupal2/core/tests/bootstrap.php --configuration /home/dev/test/drupal-microservices/drupal2/modules/custom/loremipsum/tests/phpunit.xml --teamcity) in terminal - it would finish those tests without any errors?

0
Comment actions Permalink

Thanks.Generally, in your scenario tests will be run under your current user unless configured in Apache. Did you try a solution with export APACHE_RUN_USER?

Also, looking at Drupal PHPUnit permission issue, you would get explicit "Permission denied" errors if there's a problem with a user. It looks to me there's something different that causes the issue.

Unfortunately I can't see similar reports on our tracker & don't have ideas what's causing this. We can assist you with this if you could share this project with us.

 

0

Please sign in to leave a comment.