skip to Main Content

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.

2

Answers


  1. Chosen as BEST ANSWER

    For anyone who has similar issues I was able to fix this AFTER installing XDebug locally on my Windows computer.

    Specifically, in the composer.json file:

    I changed:

    // a Linux variable setting
    "scripts": {
        "test": ["XDEBUG_MODE=coverage vendor/bin/phpunit -c phpunit.dist.xml"]
    },
    

    To:

    "scripts": {
        "test": ["vendor/bin/phpunit -c phpunit.dist.xml"]
    },
    

    And in my Windows php.ini file I had to set: xdebug.mode=coverage

    And then for notes purposes, I also added the following so others developers will know how the test works in each environment:

    "scripts-descriptions": {
        "test" : "Set PHP.ini xdebug.mode=coverage (windows) OR set 'test':['XMODE_DEBUG=coverage vendor/bin/phpunit ...'] (linux)"
    }
    

    Credit to both @AlvaroGonzalez and @NicoHase for pointing me in the right direction.


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

    {
        "scripts": {
            "test": [
                "@putenv XDEBUG_MODE=coverage",
                "vendor/bin/phpunit -c phpunit.dist.xml"
             ]
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search