This gist is a follow-up to this Lando issue, updated for Docker Composer and Windows (but might also help macOS and Linux users).
- Open File | Settings | Build, Execution, Deployment | Docker
- Click on the top-left "+"
- Case a: If you have (and want to use) Docker for Windows: choose "Docker for Windows"
- Case b (theorical, because unfortunately I could not get it to work): If your Lando instance is in WSL:
- Choose "WSL" and your Linux distribution
- Add one or more path mappings (in my case mapping
/home/quentint
to\\wsl$\Ubuntu\home\quentint
was enough because my projects are stored in WSL's home directory)
- Open File | Settings | Languages & Frameworks | PHP
- Click on the three dots on the "CLI Interpreter" line
- Click on the top-left "+" and create CLI Interpreter "From Docker, Vagrant, VM, WSL, Remote..."
- Choose "Docker Compose"
- Click on the "Configuration files" folder icon
- Click on the top-right "+"
- Select all YAML files in
C:\Users\[user]\.lando\compose\[project]
- Select "appserver" in the Service dropdown
- Click OK to close the "Configure Remote PHP Interpreter" window
- Choose "Connect to an existing container" in the "Lifecycle" section
- Click OK to close the "CLI Interpreters" window
- Click on the directory icon of the "Path mappings" section
- Add a local path mapping your project root to
/app
and click OK to confirm
- Open File | Settings | Languages & Frameworks | PHP | Test Frameworks
- Click the top-left "+" to add a test framework
- Choose "PHPUnit by Remote Interpreter"
- Choose your newly created interpreter and click OK to close the window
- Choose "Use Composer autoloader"
- Set "Path to script" to
/app/vendor/autoload.php
- If not already there, create
phpunit.xml.dist
at the root of your project
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.readthedocs.io/en/latest/configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" colors="true"
bootstrap="tests/bootstrap.php">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<php>
<ini name="error_reporting" value="-1"/>
<server name="APP_ENV" value="test" force="true"/>
<server name="SHELL_VERBOSITY" value="-1"/>
</php>
<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<!-- Run `composer require symfony/phpunit-bridge` before enabling this extension -->
<!--
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
</listeners>
-->
<!-- Run `composer require symfony/panther` before enabling this extension -->
<!--
<extensions>
<extension class="Symfony\Component\Panther\ServerExtension" />
</extensions>
-->
</phpunit>
- If not present, add
KERNEL_CLASS='App\Kernel'
to your.env.test
file - Open previous settings (File | Settings | Languages & Frameworks | PHP | Test Frameworks)
- Check "Default configuration file"
- Set path to
/app/phpunit.xml.dist
See this comment for detailed steps.
Great success! ๐
It works for me now. I wish I could tell you what the problem was, but I don't know. In the meantime, my Linux kernel, Docker, PhpStorm etc. were updated. Maybe one of those was the problem. Anyway, the above approach works now and I am able to select appserver in the Service dropdown.
Also thanks to @mortona42 , the file permission problem is gone. To my surprise, it was not enough that the test ran through
docker compose
. The file created was still owned by root.To recap: if you set up your test runner like this...
... any file created during testing will be owned by your (host) user and not root. The same way it works if you run
lando phpunit
.The last problem is that PhpStorm tries to create the Clover XML in a dir that does not exist.
As you can see in the above screenshot, I tried setting a path for the XML report, but it's just ignored and PhpStorm appends another one with the problematic path.
I can't find any option how to properly set this path. ๐