-1

Background

A php application in running in a Docker container. With docker-compose, this container is ran in a configuration together with a postgres database container and a lot of other containers.

Attempting to run my phpunit tests in phpstorm, I have created a Docker Remote Interpreter test configuration which runs the PHP application container.

Problem

The container complains that it can not connect to the database, which of course is not started because it's configured in the docker-compose.yml and not started up along with the single container used by PhpStorm.

Attempts to solve

  • A PHP Remote Debug can use a deployment, so I tried to create a Docker Deployment configuration which uses the docker-compose.yml (therefore starting all containers) and is launched before the PHPUnit launch, but I cannot select this deployment.
  • Starting the Docker Compose containers except the one from the PHP app and have it connect to it. This proves difficult, because they are on different networks, so the php app container still complains about not finding the database. I cannot configure which network the container uses in PhpStorm.

tl;dr

My PhpStorm project is a PHP application. This application can run in a Docker container which serves through nginx. I can run my PHPUnit tests in the container with a run configuration, but it also needs other containers which are not started up automatically.

Question

How can I use PHPStorm to run PHPUnit tests in a PHP application container together with the containers it depends on (already described in a docker-compose.yml)?

user3942918
  • 25,539
  • 11
  • 55
  • 67
Bas Peeters
  • 3,269
  • 4
  • 33
  • 49
  • Can you make a script that will launch compose instead of your container ? You could also start your database when you start working and your container will be able to link to it. – Wassim Dhif Jul 25 '17 at 09:25
  • Take a look at [wait-for](https://github.com/Eficode/wait-for/blob/master/wait-for) script which will wait for a particular container before starting another container. – Ayushya Jul 25 '17 at 09:48
  • @WassimDhif I've created such a script, but then I'm not sure how to adapt a _PHPUnit_ run configuration in PhpStorm to that specific container running my app. – Bas Peeters Jul 25 '17 at 10:02
  • @Ayushya The containers my app is depending on are up when I need them, but they're just not in the same docker network, and I can't seem to change the network membership using PhpStorm run configuration settings for running PHPUnit on an app in a docker container. – Bas Peeters Jul 25 '17 at 10:04
  • [This](https://stackoverflow.com/a/45197727/6207775) answer describes how you can run individual containers and connect them using networks. You can define network in `docker-compose.yml`, and access that network in the other container. – Ayushya Jul 25 '17 at 10:17
  • Anyone care to comment on the downvotes? Comments and answers seem to solve my problem, so I wonder what's bad about the question. – Bas Peeters Aug 09 '19 at 06:57

1 Answers1

1

The answer is too long. I hope this 5 minutes video by Jetbrains TV helps you.

https://www.youtube.com/watch?v=I7aGWO6K3Ho

In short you need:

  1. Configure Docker instance in PHPStorm
  2. Configure new PHP Interpreter from Docker container
  3. Configure PHPUnit to use your new interpreter
Pavel Shorokhov
  • 4,485
  • 1
  • 35
  • 44