How can I get XDebug to run with PHPUnit on the CLI?

后端 未结 9 1979
时光取名叫无心
时光取名叫无心 2020-12-23 11:01

I\'ve tried running the following CLI command:

phpunit -d xdebug.profiler_enable=on XYZTestCase.php

but it just runs as normal. Can anyone

9条回答
  •  轮回少年
    2020-12-23 11:42

    The only thing I need to do in the terminal, while using VS code debugger (with WSL), is execute this command:

    export XDEBUG_CONFIG="idekey=VSCODE"
    

    after that I simply run my phpunit command as usual. i.e. phpunit ./tests/ and the debugger will stop on the first breakpoint I have set.

    If the debugger pauses on unreachable code, you might want to toggle of "Everything" in the debugger pane under Breakpoints.

    I got this info from https://tighten.co/blog/configure-vscode-to-debug-phpunit-tests-with-xdebug

    :: EDIT ::

    While the above worked on my local webserver. I got bit by this today as I tried to port my project to docker.

    It turned out it will not work with this setting:

    xdebug.remote_connect_back=1
    

    But you need to set this instead:

    xdebug.remote_host=172.17.0.1
    xdebug.remote_connect_back=0
    

    Note: I use 172.17.0.1 to refer to my host machine from inside the docker container because I am on linux, but if you are on a mac it's probably better to use:

    xdebug.remote_host=docker.for.mac.host.internal
    xdebug.remote_connect_back=0
    

    or on windows:

    xdebug.remote_host=host.docker.internal
    xdebug.remote_connect_back=0
    

    With docker it seems like I did not need to do export XDEBUG_CONFIG="idekey=VSCODE" anymore either.

提交回复
热议问题