vscode-phpunit icon indicating copy to clipboard operation
vscode-phpunit copied to clipboard

Using docker-compose in phpunit.php does not seem to work.

Open Xachman opened this issue 5 years ago • 12 comments

if I add:

{
    "phpunit.php": "/usr/bin/docker-compose run --rm app php",
    "phpunit.phpunit": "/var/www/html/vendor/bin/phpunit
}

Config options and try to run the tests I get back.

spawn /usr/bin/docker-compose run --rm app php ENOENT

Xachman avatar Oct 10 '20 16:10 Xachman

This issue is because on my system it needs to be a file. I made a docker-phpunit.sh file:

#!/bin/bash

docker-compose run --rm app /var/www/html/vendor/bin/phpunit $@

and made changes to the settings.json

{
    "phpunit.phpunit": "/path/to/file/docker-phpunit.sh",
    "phpunit.args": ["--configuration", "/var/www/html/phpunit.xml"],
    "phpunit.relativeFilePath": true
}

This works in general but now I get the error every once and a while.

(node:6089) UnhandledPromiseRejectionWarning: Error: Unhandled method TestRetryEvent-0e1f51777fd53e8d4de77095197d3029
    at /home/user/.vscode/extensions/recca0120.vscode-phpunit-2.0.76/server/out/server.js:1:9133
    at /home/user/.vscode/extensions/recca0120.vscode-phpunit-2.0.76/server/out/server.js:1:9427
    at Immediate.<anonymous> (/home/user/.vscode/extensions/recca0120.vscode-phpunit-2.0.76/server/out/server.js:1:9788)
    at processImmediate (internal/timers.js:439:21)
(node:6089) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 25)

Xachman avatar Oct 12 '20 19:10 Xachman

https://github.com/recca0120/vscode-phpunit/issues/33 may be related

Xachman avatar Oct 12 '20 19:10 Xachman

It's happening for me too, I get this error after running all the tests succesfully, then trying to run the tests again returns the error above.

perebusquets avatar Oct 15 '20 09:10 perebusquets

Just started using this tool. I'm running against a docker-compose container sitting on a Debian box, which I'm connecting to using the inbuilt vscode SSH bridge (Remote-SSH). I'm experiencing the same issues as described.

I've set up my fields a little differently.

"phpunit.relativeFilePath": true,
"phpunit.php": "/usr/bin/docker exec my_container php",
"phpunit.phpunit": "/var/www/html/vendor/bin/phpunit",
"phpunit.shell": "/bin/bash",

The tests run fine as long as there's no failures, but as soon as there are the module crashes out and can't be recovered without a restart of the SSH connection.

I get the same error message as @Xachman.

(node:5145) UnhandledPromiseRejectionWarning: Error: Unhandled method TestRunStartedEvent-0199eba5e9da448952078e8954b366f9
    at /home/me/.vscode-server/extensions/recca0120.vscode-phpunit-2.0.76/server/out/server.js:1:9133
    at /home/me/.vscode-server/extensions/recca0120.vscode-phpunit-2.0.76/server/out/server.js:1:9427
    at Immediate.<anonymous> (/home/me/.vscode-server/extensions/recca0120.vscode-phpunit-2.0.76/server/out/server.js:1:9788)
    at processImmediate (internal/timers.js:439:21)
(node:5145) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 12)

dsclee1 avatar Nov 13 '20 16:11 dsclee1

Same problem here. I get a UnhandledPromiseRejectionWarning if a test fails and then I need to restart vscode.

enricodias avatar May 21 '21 20:05 enricodias

@perebusquets, @enricodias Please don't (ever) just comment "same here" — +1 the issue instead. Only post if you have valuable information to add to the discussion.

Also, you don't need to restart vscode, restarting the extension host (Ctrl+Shift+P, "Developer: Restart Extension Host") is enough.

antichris avatar Jun 18 '21 11:06 antichris

@antichris It was intentional to show that this issue is still relevant almost a year after the last reply. Having to restart the extension host is pretty much the same hassle as having to restart vscode itself, at least for me.

enricodias avatar Jun 18 '21 15:06 enricodias

It was intentional to show that this issue is still relevant almost a year after the last reply

Successful deflection is successful.

Although I'd speculate, had you thought about it that way at that particular moment, you'd probably written it like "hey, this is still happening, it's very annoying/frustrating, is there a fix coming?" (or something along the lines).

Also I was surprised at first how you managed to get "almost a year" from November 13 to May 21 (6 months 8 days), but that, although appears to shed light on your tendency to stick to the facts, is not very pertinent to the discussion.

What matters is that I do agree — having to restart anything every single flipping time a test fails is extremely frustrating and renders this extension practically useless, considering how tests have to be written to fail first, before enough code has been written (or changed) for them to start passing. We need a fix for this.

antichris avatar Jun 18 '21 16:06 antichris

It appears that problem that happens when a test fails seems to be caused by the file paths reported by phpunit, they differ between the container and the host machine. It works when no tests fail because the extension doesn't need to open any file in that case.

As a workaround, I'm using sed to replace the paths reported by phpunit with the path used in the host machine:

#!/bin/bash

docker-compose exec -T DOCKER_IMAGE bin/phpunit ${@:2} | sed "s|\./|HOST_PATH|g"

Replace DOCKER_IMAGE and HOST_PATH with your own.

enricodias avatar Aug 12 '21 17:08 enricodias

@enricodias I can confirm that this will in fact fix the issue. I had to make some adjustments to your script in my case this worked.

#!/bin/bash

docker-compose exec -T DOCKER_IMAGE bin/phpunit $@ | sed "s|/path/in/container|/path/on/host|g"

I can finally use this extension again! I appreciate all the time you put into figuring out this issue!

Xachman avatar Aug 13 '21 01:08 Xachman

Thanks @Xachman. Your comments helped me to make this extension finally work 👍

I used your settings.json

{
    "phpunit.phpunit": "/path/to/file/docker-phpunit.sh",
    "phpunit.args": ["--configuration", "/var/www/html/phpunit.xml"],
    "phpunit.relativeFilePath": true
}

Here is my bash script - I used docker exec where app is container name

#!/bin/bash
docker exec                       \
    --workdir="/var/www/api/"     \
    app                           \
    php ./vendor/bin/phpunit "$@" \
    | sed "s|/var/www/api|$HOME/Projects/api|g" 

For anyone having issues setting this up make sure to restart vscode if extension throws any error while you tweak bash script and re-try running tests. I had weird issue where tests would pass but it would never mark them as passed. At the same time extension worked for failed tests and it showed the error in the code. Only restart helped

I was debugging issues with following settings.json

{
    "phpunit.showAfterExecution": "always",
    "phpunit.logpanel": true,
    "phpunit.trace.server": "verbose",
}

ljubadr avatar Mar 11 '22 15:03 ljubadr

I wanted to post a quick update

Even though I have this extension working with the setup above I decided to use remote containers approach

I already have php docker container running as part of my docker-compose so I used Open an existing folder in a container

I've added list of extensions that will be automatically installed in any new remote container in my global settings.json

"remote.containers.defaultExtensions": [
    ....
]

After setting and installing extensions everything works out of the box without any hacks. I also don't have to do similar hacks/updates for other vscode extensions

Since I use some terminal CLI apps I also found how to start host terminal:

Terminal: Create New Integrated Terminal will open a terminal window within a container. Terminal: Create New Integrated Terminal (Local) will open a terminal on your host machine.

Thanks for all the help!

ljubadr avatar Mar 14 '22 16:03 ljubadr

try version 3.0

recca0120 avatar Dec 06 '22 19:12 recca0120