Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non functional when running phpunit on the CLI #154

Closed
johnbillion opened this issue Mar 30, 2017 · 11 comments
Closed

Non functional when running phpunit on the CLI #154

johnbillion opened this issue Mar 30, 2017 · 11 comments

Comments

@johnbillion
Copy link

PHP version: 7.1.0
XDebug version: 2.5.0
Adapter version: 1.10.0

Your launch.json:

{
	"version": "0.2.0",
	"configurations": [
		{
			"name": "Listen for XDebug",
			"type": "php",
			"request": "launch",
			"port": 8999,
			"log": true
		}
	]
}

XDebug php.ini config:

[xdebug]
zend_extension=/Users/john/.phpbrew/php/7.1/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so
xdebug.idekey = john-xdebug
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_handler = dbgp
xdebug.remote_host = 127.0.0.1
xdebug.remote_port = 8999q
xdebug.remote_log = "/sites/x/php/xdebug.log"

XDebug logfile (from setting xdebug.remote_log in php.ini):
https://gist.github.com/johnbillion/5ade700e7a0db209d63ee95e6d60827a

Adapter logfile (from setting "log": true in launch.json):
https://gist.github.com/johnbillion/2476befecc0b5734ae830ec8fb4584c7

Code snippet to reproduce:
N/A


The PHP Debug Adapter for Visual Studio Code works well for me over HTTP (eg. via a web page in the browser) and via the CLI with php -f <file>. However, when running phpunit on the CLI, the adaptor exhibits strange behaviour and doesn't function as expected.

As soon as the command starts, two entries appear in the Call Stack panel:

These entries aren't expandable/collapsable like a normal stack trace, and the adaptor is otherwise non-functional (the only thing that works is the Stop button). The Pause button remains in place of the Continue button, breakpoints don't trigger, and the command hangs indefinitely until you exit with ctrl+c on the CLI or abort the execution with the Stop button in VS Code.

Whilst trying to narrow down the problem, I ran the Xdebug client for Atom while running phpunit and it worked as expected. I was able to step through code etc as normal with no problems.

Any ideas where the problem might lie? Any other debugging info I can provide?

@akoskm
Copy link

akoskm commented Apr 9, 2017

I'm working on a project which uses laravel and I found two ways to run phpunit tests:

  • phpunit --stderr
  • phpunit --process-isolation

Running with phpunit --process-isolation I'm also getting two processes in the call stack, while phpunit --stderr works fine and the debug points are triggered.

@felixfbecker
Copy link
Contributor

I use this launch config which is working fine for me:

{
            "name": "PHPUnit",
            "type": "php",
            "request": "launch",
            "program": "${workspaceRoot}/vendor/phpunit/phpunit/phpunit",
            "cwd": "${workspaceRoot}",
            "args": [
                // "--filter", "whatever"
            ]
        }

@akoskm
Copy link

akoskm commented Apr 9, 2017

thanks @felixfbecker for the great plugin! 🎉

I just tried your config and got the same error when I was running phpunit without any of those flags I mentioned:

1) Tests\Feature\LoginTest::testLogin
Cannot modify header information - headers already sent by (output started at /home/akoskm/momentum/momentum-back/vendor/phpunit/phpunit/src/Util/Printer.php:134)

I have no idea why I'm getting this btw ^^

However, adding "--stderr" in "args" into your config works just fine. 👍

@pedrosalpr
Copy link

Hello @felixfbecker .

How do I debug a test method in phpunit? I added this script yours on launch.json.

Because when I run the PHPUnit script it appears in the debug console: No tests executed!

@felixfbecker
Copy link
Contributor

This is impossible to say without knowing your project

@pedrosalpr
Copy link

For example if I run phpunit --filter Unit\\Classes\\Graphics\\HeatmapTest::heatmap_com_animacao in cli, I can usually check if it gave error or not. But this method is failing, and I wanted to debug it step by step. So I added breakpoint in this method but it does not debug.

In the script in launch.json, I commented out the arguments, but it is not working, and I tried to put in --filter Unit\\Classes\\Graphics\\HeatmapTest::heatmap_com_animacao arguments, however it gives PHPUnit_Framework_Exception: unrecognized Option --filter Unit\\Classes\\Graphics\\HeatmapTest::heatmap_com_animacao

@felixfbecker
Copy link
Contributor

did you put it in as

            "args": [
                "--filter", "Unit\\Classes\\Graphics\\HeatmapTest::heatmap_com_animacao"
            ]

(correct)
or

            "args": [
                "--filter Unit\\Classes\\Graphics\\HeatmapTest::heatmap_com_animacao"
            ]

(wrong)
?

@pedrosalpr
Copy link

Now I put the correct argument, but when I run the PHPUnit script it appears in the debug console: No tests executed !.

@jshafe
Copy link

jshafe commented Jan 7, 2018

I've tried everything I can think of. Debugging works fine from the browser but completely ignores breakpoints on unit tests initiated directly from within VSCode. Any additional information I can provide and any idea why it's working from the browser but not working on unit tests?

Thanks a lot,
Jeff

Windows 7
PHP 7.1
XDebug 2.5.5 (shows perfectly in phpinfo)
VSCode 1.19.1
Launch.json

{
"version": "0.2.0",
"configurations": [

    {
        "name": "Listen for XDebug",
        "type": "php",
        "request": "launch",
        "port": 9000,
        "log": true,
        "env": {
            "XDEBUG_CONFIG": "idekey=VSCODE"
        }
    },
    {
        "name": "Launch currently open script",
        "type": "php",
        "request": "launch",
        "program": "${file}",
        "cwd": "${fileDirname}",
        "port": 9000
    }
]

}

@serchuz
Copy link

serchuz commented Jun 4, 2018

This is the only solution that work for me (use another port to run and listen phpunit)
https://stackoverflow.com/questions/49148551/how-can-i-get-xdebug-to-run-with-phpunit-on-the-cli-in-windows-using-vscode/49207236#49207236

@jonathanjfshaw
Copy link

Same as @serchuz, add a second configuration listening on 8000 and then:
'php -d xdebug.remote_port=8000 "vendor/bin/phpunit" "anyphpunitargument"'
You can run both configurations more easily if you use a compound configuration:
https://code.visualstudio.com/docs/editor/debugging#_multitarget-debugging

I use Lando as my development environment, which makes this solution a bit easier to implement, and I added it to their docs:
lando/lando#1107

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants