-
-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lando + PHPStorm + PHPUnit #6
Comments
I found this in the Lando slack search: |
Yeah I've tried this several times, from my research I don't believe it's possible until PHPstorm adds the ability to use an already running container as the test runner. Phpstorm can also connect over SSH, but I haven't been able to work out how to get it to connect into the lando appserver. If we can get that working, it will probably be the easiest path forward. |
I have a working example. Writing up a Lando guide. |
Guide write up delayed because of the effort involved. Here's the step by step that works for me on a Mac but doesn't work on Ubuntu 20.04. Before you begin
Step 1: Configure PHPStorm Docker
Step 2: Configure PHPStorm PHP CLINext, we need to tell PHPStorm about Lando's PHP Image. This is where a lot of the settings are used from the "Before you begin" section.
Step 3: Configure PHPStorm PHPUnitFinally, we need to tell PHPStorm about PHPUnit and where to find it's executable command file.
Step 4: Create a PHPUnit ConfigurationNow that you have your PHPStorm Project Settings all correctly configured (steps 1-3), the next step is to create a "Run/Debug Configuration" that will give you a push-button ability to run PHPUnit tests using Lando's Docker PHP Docker. Note: This is not the last step, so this will not likely work if you click play once you're done.
Step 5: PHPUnit.xml SettingsThe recommended approach is to keep a PHPStorm-version of phpunit.xml file called "phpunit.phpstorm.xml" at the root of your repository so you can set specific options up just for PHPStorm. Below there is a complete copy of the xml file, but here for good measure are the items that you will want to consider: <php>
<env name="SIMPLETEST_BASE_URL" value="http://appserver_nginx"/>
<env name="SIMPLETEST_DB" value="mysql://drupal8:drupal8@database/drupal8#phpunit"/>
</php>
<testsuites>
<testsuite name="unit">
<file>./web/core/tests/TestSuites/UnitTestSuite.php</file>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./web/modules</directory>
</whitelist>
</filter> Specifically, do the following:
|
I've used your guide on Windows, here are the differences:
I hope this helps! |
Thanks for the guide! I got my tests up and running, but I ran into issues on step 3
... where if I touched the little refresh icon next to Path to phpunit.phar I would get a popup from PhpStorm saying Updating PhpUnit Version... and I was unable to close it, or cancel, force quitting PhpStorm was the only option. Well, after force quitting, and double checking all of my settings compared to yours, I was able to get my tests running. However, even when all the settings are good, touching that refresh icon brings the dreaded unclosable Updating PhpUnit Version.. popup |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions and please check out this if you are wondering why we auto close issues. |
Here's an updated version of this issue's steps, relying on Docker Compose and without relying on I hope this helps! |
Did you enable XDebug on your Lando project? |
Thanks @quentint , I have it setup like that |
Looks OK to me. Did you |
@sebastienserre You probably need to tell PHPStorm where Xdebug is located within the Lando environment. To find out where this is, from your terminal, SSH into the Lando app with the following command:
and then from within the Lando app environment, enter the command:
This command should spit out something like this, I've highlighted in yellow the portion you want to copy: Back in PHPStorm Run/Debug configurations screen, choose the lando CLI interpreter from the dropdown, and then click the options button as shown here: Paste the extensions directory path you copied from the Lando environment, into the "Additional: Debugger Extension" field, and dont forget to add the xdebug extension "xdebug.so" as shown here: That should resolve the issue of "'Xdebug' extension is not installed" |
Thank you @sheanhoxie, it works. |
I followed these instructions for linux and one difference I encountered is using "Connect to docker daemon with" = Unix socket. |
@joshmiller83 - Thank you so much for you write up, I have followed it and I now have PHPUnit running within Lando. My final hurdle, is that I seem to be unable to run browser tests. I have configured my phpunit.xml file with the internal hostname provided when running
Any help would be greatly appreciated! |
This stopped working for me on PHPStorm 2022-2. When I try to run a test the IDE hangs on test initialization. When I downgrade back to 2022-1.4 then it works again flawlessly. |
I got this to work in IntelliJ but my teammates running PhpStorm couldn't get it to work. Eventually, it turned out that it worked by chance for me because I had the Python plugin for IntelliJ installed, and a side effect of the Python plugin is that it remaps Windows paths into WSL paths when launching commands. PhpStorm doesn't have a Python plugin so this isn't an acceptable workaround there. |
Re: Xdebug not being detected, I did not have to tell the IDE where the extension was located for it to work. However, on one of my systems, it was not being detected no matter what I did; this turned out to be because one of the build steps was failing when Lando was bringing the containers up, and that seemed to prevent Lando from setting up Xdebug in the container. So, if you are not getting Xdebug to work, ensure that you do not see any errors from Lando when starting the containers. |
I want to be able to run Drupal tests within PHPStorm, but have not been able to configure it correctly. Unit and Kernel tests will run, but Functional tests are running into issues like file permissions or accessing urls. I configured a CLI interpreter to use docker compose and included all configuration files in ~/.lando/compose/SITE, selecting appserver as the service. When run is selected, it's giving file permission errors: Exception : User warning: mkdir(): Permission Denied When exec is selected: If I create a CLI interpreter using the docker image, I get: Is there another way to get PHPUnit working in PHPStorm? |
Set the docker compose command on the run configuration to Now functional tests are running in PHPStorm! You have to re-add the exec command per test, but you can fix that by editing run/debug configurations, and clicking Edit configuration templates in the lower left corner. Edit the PHPUnit test template and put the docker compose exec command there. |
Hi there,
Has anyone successfully set up Lando + PHPStorm + PHPUnit to run all together, such that you can run the tests right from the IDE (Not the terminal/running as
lando phpunit
)? If so, can you post documentation on getting them set up? I've tried a few times and every time I believe it boils down to PHPStorm running some sort of containers of their own. But it IS possible through docker-compose (non lando setup), so am wondering if there are any tips/tricks to maybe getting it to work with Lando.Much appreciated!
The text was updated successfully, but these errors were encountered: