1

I have an integration test that fires a curl request to an API URL with the hostname from a docker container. The API has a different docker-compose.yml than the PHP's docker-compose.yml, so they are configured to be linked over a shared network (see Communication between multiple docker-compose projects).

When I run the test over the terminal of PHP's container (php vendor/phpunit/phpunit/phpunit tests), the API (that has the docker containers name as host name) from the other docker-compose environment, is reachable. So it is being resolved, and responds with content.

But when I run the test over PhpStorm, that uses the PHP interpreter from docker-compose, the API URL can't be resolved, as if would ignore the shared network. In the terminal I can see a long PHPUnit command is generated and fired from PhpStorm:

[docker://php_php:latest/]:php /opt/project/php/vendor/phpunit/phpunit/phpunit --no-configuration --filter MyNamespace\\Tests\\CurlTest --test-suffix CurlTest.php /opt/project/php/tests/Integration --teamcity --cache-result-file=/opt/project/.phpunit.result.cache

How can I fix the PhpStorm test runner to consider the shared network in Docker?

LazyOne
  • 158,824
  • 45
  • 388
  • 391
fabpico
  • 2,628
  • 4
  • 26
  • 43
  • 1
    According to the command you posted, you don't use a Docker Compose interpreter but a Docker interpreter. In this mode, PhpStorm just runs `docker run php_php:latest php ...` which doesn't re-use the existing container and spawns a new one instead that has its own network attached to it. Try switching to the Docker Compose interpreter in the `exec` mode. – Eugene Morozov Aug 26 '21 at 13:02
  • @EugeneMorozov Makes sense, I see that my Interpreter is configured with `Docker` instead of `Docker Compose`. But now I see why I used `Docker`, when I try to configure with `Docker Compose`, then at `General -> PHP Executable`, I receive error `Failed to parse valiation script output`. I tried with `php` and all other paths of `whereis php`, namely `/usr/local/bin/php`, `/usr/local/etc/php`, `/usr/local/lib/php`, `/usr/local/php`, without success. – fabpico Aug 27 '21 at 06:50
  • It's impossible to tell why that is without looking at the logs. Add `#com.jetbrains.php` to `Help | Diagnostic Tools | Debug Log Settings`, try to add a Docker Compose interpreter again, and then check the log - what error does it yield exactly? – Eugene Morozov Aug 27 '21 at 10:17
  • @EugeneMorozov In the log, before `com.intellij.execution.ExecutionException: Failed to parse validation script output`, there is a debug message `Error on executing 'php [-dxdebug.remote_enable=0, -dxdebug.mode=off, /opt/.phpstorm_helpers/phpinfo.php]': Version mismatch: file C:\Users\...\docker-compose.yml specifies version 3.9 but extension file C:\Users\...\AppData\Local\JetBrains\PhpStorm2021.1\tmp\docker-compose.override.9.yml uses version 1`. Does that mean that PHPStorm only understands docker-compose v1 specifications? – fabpico Aug 31 '21 at 09:55
  • Your docker-compose.yml doesn't have its `version` declared, right? Such files weren't supported in PhpStorm prior to 2021.2.1, it was fixed in the course of [PY-49305](https://youtrack.jetbrains.com/issue/PY-49305) – Eugene Morozov Aug 31 '21 at 13:58
  • @EugeneMorozov Right. After I declared the version explicitly, the PHP executable could be found. But I could not `Ok` the window, there was a new error `Specify PHP interpreter path` even if the PHP version and Xdebug Version were found now (maybe you should adress this as Bug). After deleting the CLI Interpreter Entry and adding a new one, it worked. – fabpico Sep 01 '21 at 05:43

1 Answers1

1

Solution was:

  1. Add docker-compose version explicitly in docker-compose.yml (eg. version: '3.9'), to fix the error when trying to set up a Docker Compose CLI interpreter.
  2. Create a new CLI Interpreter entry of type Docker Compose instead of Docker.
fabpico
  • 2,628
  • 4
  • 26
  • 43