Cannot debug tests when using 'docker-compose exec' (PHP)

I have created a PHP CLI Interpreter using Docker Compose (Preferences -> Languages & Frameworks -> PHP -> CLI Interpreter).

The interpreter has 2 lifecycle options:

  1. Always start a new container ('docker-compose run')
  2. Connect to existing container ('docker-compose exec')

I would like to use the second option (exec) because it allows phpunit tests to run much more quickly (see https://youtrack.jetbrains.com/issue/WI-37986). However, when that option is selected, I lose the ability to debug my unit tests.

Specifically, when the "exec" option is selected and I try debug, I get the error:

Connection was not established.
Probably 'xdebug.remote_host=docker.for.mac.localhost' is incorrect.

However, when the "run" option is selected, debugging works (breakpoints trigger as expected). 

Is it possible to debug unit tests when the "exec" option is selected?


---

Additional info

  • Operating System: macOS Big Sur, Version 11.3.1
  • IDE: IntelliJ IDEA Ultimate 2021.1
  • Downloaded Plugins: PHP, PHP Docker, PHP Remote Interpreter  (all by JetBrains)
0
3 comments

Yes, that should be possible.

Please try to bring your docker-compose config down, then try debugging PHPUnit tests again.

When the service is down IDE would launch it for the first time with docker-compose run. All consequent sessions will be run using exec.

 

1

That worked!

0

Please sign in to leave a comment.