vscode-phpunit
vscode-phpunit copied to clipboard
Is it possible to specify the `cwd`?
I need to run tests from within a specific directory otherwise they will fail. I know, these tests are badly designed, but is there any way I could achieve this?
same here, my tests are not even showing, because they are inside source dir
Same here - you can make tests appear by adding in settings.json
:
"phpunit.args": ["--configuration=my-subfolder/phpunit.xml.dist"],
"phpunit.files": "./my-subfolder/test/**/*Test.php"
But it won't work if your workdir should be my-subfolder
because all dependencies are missing then.
what i did was :
"phpunit.files": "source/{test,tests}/**/*Test.php",
"phpunit.phpunit": "/home/rilex/docker/enode5/sanity/test.sh"
and inside test.sh just docker-compose exec -T php-fpm vendor/bin/phpunit
. which probably could just be replaced with path to phpunit for non docker environment, and everything works great
If anyone comes across this like I did and does not use docker for the phpunit. (and perhaps wants to be able to change the cwd on the fly / or based on workspace).
The script will take the first parameter of phpunit.args
as the cwd and the rest will be passed through to PHPUnit.
In my example I have my phpunit within the same dir under phpunit-9.5.phar
settings.json
{
"phpunit.phpunit": "home/.../.../tools/phpunit.sh",
"phpunit.args": [
"/home/.../.../myapp/api/site",
"--cache-result-file=/home/.../.../.phpunit.result.cache"
]
}
phpunit.sh
#!/bin/bash
SCRIPT=$(realpath "$0");
SCRIPTPATH=$(dirname "$SCRIPT");
(cd "$1" && "$SCRIPTPATH"/phpunit-9.5.phar "${@:2}");