简体   繁体   中英

PhpStorm with PHPUnit in PHP docker container on vagrant

I have the Vagrant box with several containers and one container is for PHP engine.

Usually, I run my tests inside Vagrant box like:

docker run <my_specific_parameteres> remote.docker.container.php7.2 bin/phpunit --coverage-clover -c phpunit.xml.dist

But, I want to run this with PhpStorm. It is possible? If yes, any help, because I do not know how to properly configure my PhpStorm to run PHPUnit as I want.

It's a bit complicated because there is one extra virtualization layer (host => Vagrant VM => Docker), but it's possible.

Let's agree on these:

  • /home/PhpstormProjects/theProject is the path of your sources on the host.
  • /var/www/html/theProject is the Vagrant VM path your sources are mapped into.
  • /opt/theProject is the container path the Vagrant path is bound to with volume mappings.

First, you need to configure your Docker daemon to listen on TCP port: https://success.docker.com/article/how-do-i-enable-the-remote-api-for-dockerd

Then, you need to add these Docker server at PhpStorm Settings | Build, Execution, Deployment | Docker Settings | Build, Execution, Deployment | Docker Settings | Build, Execution, Deployment | Docker .

After that, add a Docker remote interpreter using the desired image at PhpStorm Settings | Languages & Frameworks | PHP Settings | Languages & Frameworks | PHP Settings | Languages & Frameworks | PHP .

You need to set the following mappings later:

  • Docker container | Volume bindings:
    • Container path: /opt/theProject
    • Host path: /var/www/html/theProject
  • Path mappings: Add a new mapping (as the default one is incorrect):
    • Local path: /home/PhpstormProjects/theProject
    • Remote path: /opt/theProject

After that, configure PHPUnit for this Docker interpreter at Settings | Languages & Frameworks | PHP | Test Frameworks Settings | Languages & Frameworks | PHP | Test Frameworks Settings | Languages & Frameworks | PHP | Test Frameworks , it should be able to parse paths OK.

That's basically it, you should be good to go. Unfortunately, there's no option to pass custom arguments to Docker: https://youtrack.jetbrains.com/issue/IDEA-181088

If there are any issues, please submit a support request: https://intellij-support.jetbrains.com/hc/en-us

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM