elonmallin/vscode-phpunit

phpunit.phpunit setting seems to have no effect

Closed this issue · 3 comments

I tried setting a custom PHPUnit path like this in my workspace settings (.vscode/settings.json file in the root of my project):

"phpunit.phpunit": "docker exec -it MY_CONTAINER_NAME php vendor/bin/phpunit"

However, the PHPUnit extension doesn’t seem to be using this path, as the tests fail instantly with this header output:

Running phpunit with driver: Composer
./vendor/bin/phpunit ./tests/unit/Domain/Report/Model/CategoryTest.php --filter testCanCreateTopLevelCategory --no-logging
PHPUnit 7.5.2 by Sebastian Bergmann and contributors.

The second line looks like the extension is still trying to run PHPUnit locally from my machine, using the path ./vendor/bin/phpunit.

Is there anything else I need to configure to get this working with my Docker container? As it also says driver: Composer, so not sure if that needs configuring somewhere?

The docker support is rather lackluster at the moment. You can't set a container that it will run. It will just start a new php:latest container and run there. So this is more as a fallback if you don't have php installed on your local dev machine.

If it works for you to run your tests with the official image php:latest you could try clearing the phpunit.phpunit config and instead move the priority of the Docker driver to the top. You do this in the config as well like so:

"phpunit.driverPriority": [
            "Docker",
            "Path",
            "Composer",
            "Phar",
            "Ssh",
            "GlobalPhpUnit"
          ],

This should run the unit test in a docker container with the image php:latest and find your phpunit in the vendor folder which is mounted in the automatically created container.

Hope that works for now. I want to add better options to actually set the container to attach to and run the test in.

Another option if you're on Mac or Linux would be to move your whole project on the host computer to the same folder that you have mounted your project to inside the container. The absolute paths have to match on both systems.
Then you could try something like:

"phpunit.php": "docker exec -it MY_CONTAINER_NAME php",
"phpunit.phpunit": "/absolute_workdir_path_for_both_host_and_container/vendor/bin/phpunit"

Hope one of those workarounds works for now. I'll try and improve the support for containers, however I'm currently looking at colored output and getting failed tests in the PROBLEMS pane.

Cheers

@elonmallin Thanks for taking the time to get back to me 🙂

I'll close this for now since what you want is actually not supported yet. But hope one of the workarounds worked for now.

Please let me know of they did in case someone else has the same issue.