PhpUnit with DockerCompose remote interpreter

First of all, thanks JetBrains for the neat feature in 2017.2 of being able to use docker-compose for php remote interpreter.  

Now I setup my phpUnit configuration using this interpreter, the problem though is before executing tests, PhpStorm decided to do a :

docker compose up

I had plenty of non-instanciated containers in my docker-compose file, so it started pulling the images and spawning containers one after the other.  The work-around I found is to remove all containers I won't use from docker-compose.yml file, so it doesn't have to do all that work before running tests, but ideally I'd like to keep my compose file intact. Suggestions or insight would be appreciated ! 

Thanks  and check out below for some screenshots'

PHP Interpreter


Test Frameworks


Run/Debug configurations


Result


 

 

 

1
8 comments

Phil, it may seem obvious, but what did you expect to happen?
If you only wanted to use a single image, you should have configured a Docker interpreter, not a Docker Compose one.

0
Avatar
Permanently deleted user

^ -- real helpful advice there /s

Thanks for the Docker Compose Support. I've been using a hack that pretends to be a local interpreter but actually passes all commands through to the docker-compose php container.

I have a similar issue to the OP where I have existing running services within the docker-compose.yml file. It seems that PHPStorm would like to be the program that initiates docker-compose up because it starts its own containers alongside the docker-compose environment. If PHPStorm is not the initiating user, it will force an already-running docker-compose environment to restart.

Is there a button somewhere to do this without having to run a test?

0
Avatar
Permanently deleted user

@Eugene Well I have multiple containers running, but there are some services I'm not using at the moment (for example databases and caching alternatives).  When I started phpUnit tests, I was expecting phpStorm to use php interpreter and run the tests, not to docker compose up every non-instanciated service.  To me it felt like an unintended side effect but maybe I'm wrong or that I misunderstand the feature.

Can you confirm using a docker compose php remote interpreter, you should have all services specified in the docker-compose.yml file instanciated else phpStorm will have them up for you when using phpUnit? That is it the intended behavior?  Thank you for your time helping me on this, appreciate it. 

0
Avatar
Permanently deleted user

It seems to me since we have the option to specify the service under the Docker Compose config, IntelliJ should call 

docker-compose up servicename

Thus booting the necessary dependencies for just that service. The work-around now is to split up large singular instances of docker-compose.yml files (for example docker-compose.servicea.ymldocker-compose.serviceb.yml) into one-off files in order to run only the necessary services but the end result is either a lot of copy paste, or a lot of chained .yml dependencies.

0

Guys, I am sorry for losing this thread out of sight, and thus making you wait, and also for my previous reply - I was totally wrong, this really is a problem.

Here's the bug: https://youtrack.jetbrains.com/issue/WI-37774

Please vote.

1
Avatar
Permanently deleted user

Thanks!

0
Avatar
Permanently deleted user

Hey guys, I checked the issue mentioned above and read your comments.  Right now I'm working around the issue by using a docker-compose.yml file that only has the services that I want running at the moment.  

 

There is still something bugging me though; It still brings up the docker-compose up window and seems to be evaluating if containers need to be instanciated.  None are being created since they are all up and running but it's annoying to have to watch that window for 2-3 seconds everytime I want to run my tests.  Is it the expected behavior ? Am I asking for something for too much ? I' m not too sure. Anyway, do you experience the same thing ? Feel free to link to similar issues if it's the case.

 

Thanks.

0
Avatar
Permanently deleted user

Ok so my recommandation guys is to use phpunit on command line I can't seem to work it around for now. 

I played around with my configurations (deleted and created new ones to try different things ...) and now PHPUnit can't seem to work with composer autoloader anymore ; I had version 6.3 detected before ( when I was trying to get around that docker-compose up issue) But now I get the  'Please select local PHP Interpreter to load PHPUnit version'

If you have an idea on how to configure it back the right way I' ll take it but as things stand it was just so much faster to use cli to run phpunit ; 4-5 secs vs 140 ms for a single test. I wish I could stay in the IDE and run the tests with hotkeys though but seems there are flaws to both approach in my situation.

Any feedback is welcome.

0

Please sign in to leave a comment.