Search code examples
dockerphpunitphpstorm

PhpStorm: running PHPUnit database tests from Docker container


I configured PhpStorm to run PHPUnit tests from Docker container. Unfortunately if test tries to connect to MySQL server I get an error:

SQLSTATE[HY000] [2002] Connection refused

MySQL server runs in the same container. If I try to connect to MySQL server from container via some standalone script - it works fine. Also the app itself works fine too.

Other tests (without database usage) work fine.

Any ideas what is wrong with my PhpStorm configuration? I followed official step by step configuration video tutorial, but it does not cover database part.

PhpStorm runs command that is being executed every time I hit run tests button:

docker://mycontainer/myapp:v1.0/php /opt/.phpstorm_helpers/phpunit.php --configuration /var/www/myapp/tests/phpunit.xml /var/www/myapp/tests/unit

Maybe problem is with phpstorm_helpers? Because it stands as separate container. Maybe my app container and helper container should be linked somehow?


Solution

  • What I need is to run tests in existing container which I start only once. Depending on this thread PhpStorm does not have such functionality yet.

    So I switched to remote interpreter instead. Now PhpStorm connects to container via SSH. I know, it's a bit gruesome, but for this moment it's what I need.

    Still if somebody wants to run integration tests with PhpStorm and Docker in proper way there is a good thread about it.