Did you find any solution for this ?
Has anyone gotten PhpStorm + phpunit + Docker PHP working?
I am attempting to get phpunit working in Docker PHP container with the configuration options available in PhpStorm.
Under Settings > Languages & Frameworks > PHP > PHP language level I have defined the language level to be 7.1 (the version running in Docker.)
Under Settings > Languages and Frameworks > PHP > CLI Interpreter it says app:latest I got that by clicking on the [...] button clicking + defining a new Docker server (local) picked the image name of my PHP container in the dropdown (app:latest)
The PHP version is detected here as 7.1.13 The configuration file is auto-generated to /usr/local/etc/php/php.ini which is the one from inside the Docker container.
Under Settings > Languages & Frameworks > PHP > Test Frameworks
I have the CLI Interpreter from above - it says app:latest (7.1.13) I have the Path mappings: ->/Projects/myproject I have Docker container: -v /Users/myuser/Documents/Projects/myproject:/Project/myproject
This was auto-detected, and appears to be correct.
Under Run -> Edit Configurations I defined a Phpunit Run Configuration to run my unit tests.
Ok, so when I go to run the tests...
At the top of the Run output window it says Testing started at 11:47 am... docker://app:latest//usr/local/bin/php /Projects/trinity/vendor/phpunit/phpunit/phpunit --no-configuration /Projects/trinity/tests --teamcity
This looks right, but now my test hangs for awhile, and complains
Illuminate\Database\QueryException : SQLSTATE[08006] [7] could not connect to server:
Connection refused
Is the server running on host "db" (127.0.0.1) and accepting TCP/IP
connections on port 5432?
Now here's the weird thing that I don't understand.
"db" is defined in the Mac OS X host as being 127.0.0.1 so I can access it with SQLPro for Postgres. Inside the docker container, it gets the NAT IP from the docker compose environment.
$ docker exec -it app /bin/bash
root@226fa45f05f3:/var/www/html# ping db
PING db (172.18.0.4): 56 data bytes
What makes no sense is that, with all of this Docker configuration defined for my CLI test, and seemingly correct, how is PhpStorm getting my Mac OS PHP configuration and DNS?
My tests do not and will not work on Mac OS X host (I have not installed the same version of PHP, nor any of the extensions) - These are all in Docker.
I can continue entering the docker container and running my tests on the command line inside the container, but I'd love to get the key commands and helpers from PhpStorm working instead, if possible.
Please or to participate in this conversation.