PHPUnit with Xdebug not working on DDEV+WSL
Yeah I know the title is pretty wordy.
Recently I've got tasks that I have to work with the Windows stack. It has been so long since I used a Windows computer and at first, I thought I wouldn't like it.
But it's quite the opposite - I'm getting to like it. Although I won't be switching to it any time soon (of course in my mind Mac is still the best), Windows has grown exceptionally in the past decade and now I wouldn't be surprised to see professionals work with it.
There does have issues here and there. And in this point I'll talk about the one that took me almost 3 hours to debug, which is Xdebug doesn't stop at the breakpoints in VSCode when I run the tests in PHPUnit Test Explorer.
That being said, breakpoints are working if I'm browsing the website, but they were all skipped when I run PHPUnit (in the UI or just use CLI commands). So I know that Xdebug doesn't work properly but I really couldn't tell why.
I've tried several combinations of debugging approaches but none of them really worked. ChatGPT suggested to create a Task to run the tests separately with requried environment variables being added. While that approach was working, I couldn't accept it is the ultimate solution.
Eventually, maybe because I finally chose the right keywords, I was led to the document on DDEV: https://ddev.readthedocs.io/en/stable/users/debugging-profiling/step-debugging/#troubleshooting-xdebug And the soluton is a one liner: ddev config global --xdebug-ide-location=wsl2
.
Again writing this so hope it will gain the right amount of exposure to save other developers' time in the future.