2

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?

1
  • 1
    That's an antipattern. One container, one task. You shouldn't run either your tests and your database server in the same container. Commented Mar 24, 2018 at 3:55

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @Bounce, do you know if there is a mirror for that article?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.