Search code examples
phpvisual-studio-codecomposer-phpxdebug

PHP Composer errors with XDEBUG_MODE not recognized in VS Code


I am running VS Code. I have PHP installed locally, Composer installed locally and the VS Code Composer plugin installed in VS Code. From VS Code terminal, I pulled the GitHub master project and the pr/#XX that I am trying to clean up and merge

I made all my changes to my project repo branch and am now trying to test it, from the VS Code Terminal I ran the following:

composer install - downloads/installs all the required php files and packages

composer update - updates most of all the installed packages

composer test - on the project and it fails with:

XDEBUG_MODE=coverage vendor/bin/phpunit -c phpunit.dist.xml
'XDEBUG_MODE' is not recognized as an internal or external command, operable program or batch file.

Through much reading, I added both to my php.ini file:

xdebug.mode=coverage
XDEBUG_MODE=coverage

What is happening and how can I fix this?


I found some docs on Xdebug here and cloned the xdebug.git (https://xdebug.org/docs/install#windows), then supplied my phpinfo() output to get the right downloaded php_xdebug.dll file to my php/ext folder and then added zend_extension = xdebug.

I verified Xdebug is enabled from CLI with: php -v

PHP 8.3.11 (cli) (built: Aug 27 2024 21:28:59) (ZTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.3.11, Copyright (c) Zend Technologies
    with Xdebug v3.3.2, Copyright (c) 2002-2024, by Derick Rethans

I closed and restarted VS Code, but the composer test problem still persists.

I also removed the two xdebug_mode lines (above) from my php.ini file, to no effect.


Solution

  • Composer scripts cross-platform compatible environment variable setting (ref):

    {
        "scripts": {
            "test": [
                "@putenv XDEBUG_MODE=coverage",
                "vendor/bin/phpunit -c phpunit.dist.xml"
             ]
        }
    }