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

后端 未结 9 1972
时光取名叫无心
时光取名叫无心 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:37

    Did you try to :

    1. Set your xdebug.idekey in your php.ini to wathever you want (eg: blacktie)
    2. restart your server

    3. Call you script by adding -d xdebug.idekey=blacktie

      phpunit -d xdebug.profiler_enable=on -d xdebug.idekey=blacktie XYZTestCase.php

    Hope that help.

    0 讨论(0)
  • 2020-12-23 11:38

    On Windows with phpStorm

    Enter this into the command line:

    set XDEBUG_CONFIG="idekey=PHPSTORM"
    

    This will add an environment variable that phpStorm will lookout for.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题